Class: Weso::Base::Client

Inherits:
Object
  • Object
show all
Includes:
EventEmitter
Defined in:
lib/weso/client.rb

Overview

::nodoc

Instance Method Summary collapse

Instance Method Details

#close(error = nil) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/weso/client.rb', line 40

def close(error = nil)
  return if closed?

  emit :close, error
ensure
  close_socket
  close_runner
end

#closed?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/weso/client.rb', line 53

def closed?
  @closed
end

#connect(url, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/weso/client.rb', line 11

def connect(url, options = {})
  return if @socket

  @socket = socket_creator(url, options).call
  @closed = false

  @handshake = handshake_client(url, options[:headers])
  @handshaked = false

  handshake
  call_runner
  self
end

#handshakeObject



32
33
34
35
36
37
38
# File 'lib/weso/client.rb', line 32

def handshake
  @socket.write(@handshake.to_s)
  process_socket(@socket, method(:handshaked?)) do |socket|
    @handshake = read_socket(socket, @handshake)
    @handshaked = @handshake.finished?
  end
end

#handshaked?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/weso/client.rb', line 57

def handshaked?
  @handshaked
end

#open?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/weso/client.rb', line 49

def open?
  !closed? && handshaked?
end

#send_data(data, type: :text) ⇒ Object



25
26
27
28
29
30
# File 'lib/weso/client.rb', line 25

def send_data(data, type: :text)
  return unless open?

  @socket.write_nonblock output_frame(data, type)
  data
end