Class: Ruflet::Rails::Protocol::WebSocketConnection
- Inherits:
-
Object
- Object
- Ruflet::Rails::Protocol::WebSocketConnection
- Defined in:
- lib/ruflet/rails/protocol/web_socket_connection.rb
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize(socket) ⇒ WebSocketConnection
constructor
A new instance of WebSocketConnection.
- #read_message ⇒ Object
- #send_binary(payload) ⇒ Object
- #session_key ⇒ Object
Constructor Details
#initialize(socket) ⇒ WebSocketConnection
Returns a new instance of WebSocketConnection.
7 8 9 10 |
# File 'lib/ruflet/rails/protocol/web_socket_connection.rb', line 7 def initialize(socket) @socket = socket @write_mutex = Mutex.new end |
Instance Method Details
#close ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/ruflet/rails/protocol/web_socket_connection.rb', line 49 def close return if closed? @socket.close rescue IOError nil end |
#closed? ⇒ Boolean
16 17 18 19 20 |
# File 'lib/ruflet/rails/protocol/web_socket_connection.rb', line 16 def closed? @socket.closed? rescue IOError true end |
#read_message ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ruflet/rails/protocol/web_socket_connection.rb', line 26 def frame = read_frame return nil if frame.nil? opcode = frame[:opcode] payload = frame[:payload] case opcode when 0x8 close nil when 0x9 send_frame(0xA, payload) when 0xA when 0x1, 0x2 payload else end end |
#send_binary(payload) ⇒ Object
22 23 24 |
# File 'lib/ruflet/rails/protocol/web_socket_connection.rb', line 22 def send_binary(payload) send_frame(0x2, payload.to_s.b) end |
#session_key ⇒ Object
12 13 14 |
# File 'lib/ruflet/rails/protocol/web_socket_connection.rb', line 12 def session_key @socket.object_id end |