Class: Ruflet::WebSocketConnection
- Inherits:
-
Object
- Object
- Ruflet::WebSocketConnection
- Defined in:
- lib/ruflet/server/web_socket_connection.rb
Constant Summary collapse
- MAX_FRAME_PAYLOAD_BYTES =
Ruflet control messages are small; anything much larger is invalid or hostile.
16 * 1024 * 1024
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize(socket) ⇒ WebSocketConnection
constructor
A new instance of WebSocketConnection.
- #read_message ⇒ Object
- #send_binary(payload) ⇒ Object
- #send_text(payload) ⇒ Object
- #session_key ⇒ Object
Constructor Details
#initialize(socket) ⇒ WebSocketConnection
Returns a new instance of WebSocketConnection.
8 9 10 11 |
# File 'lib/ruflet/server/web_socket_connection.rb', line 8 def initialize(socket) @socket = socket @write_mutex = Mutex.new end |
Instance Method Details
#close ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/ruflet/server/web_socket_connection.rb', line 54 def close return if closed? begin @socket.close rescue IOError nil end end |
#closed? ⇒ Boolean
17 18 19 20 21 |
# File 'lib/ruflet/server/web_socket_connection.rb', line 17 def closed? @socket.closed? rescue IOError true end |
#read_message ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ruflet/server/web_socket_connection.rb', line 31 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
23 24 25 |
# File 'lib/ruflet/server/web_socket_connection.rb', line 23 def send_binary(payload) send_frame(0x2, payload.to_s.b) end |
#send_text(payload) ⇒ Object
27 28 29 |
# File 'lib/ruflet/server/web_socket_connection.rb', line 27 def send_text(payload) send_frame(0x1, payload.to_s.b) end |
#session_key ⇒ Object
13 14 15 |
# File 'lib/ruflet/server/web_socket_connection.rb', line 13 def session_key @socket.object_id end |