Class: Weso::Base::Client
- Inherits:
-
Object
- Object
- Weso::Base::Client
- Includes:
- EventEmitter
- Defined in:
- lib/weso/client.rb
Overview
- ::nodoc
Instance Method Summary collapse
- #close(error = nil) ⇒ Object
- #closed? ⇒ Boolean
- #connect(url, options = {}) ⇒ Object
- #handshake ⇒ Object
- #handshaked? ⇒ Boolean
- #open? ⇒ Boolean
- #send_data(data, type: :text) ⇒ Object
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
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, = {}) return if @socket @socket = socket_creator(url, ).call @closed = false @handshake = handshake_client(url, [:headers]) @handshaked = false handshake call_runner self end |
#handshake ⇒ Object
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
57 58 59 |
# File 'lib/weso/client.rb', line 57 def handshaked? @handshaked end |
#open? ⇒ 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 |