Class: AnyCable::RackServer::Connection
- Inherits:
-
Object
- Object
- AnyCable::RackServer::Connection
- Includes:
- Logging
- Defined in:
- lib/anycable/rack-server/connection.rb
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
-
#coder ⇒ Object
readonly
Returns the value of attribute coder.
-
#header_names ⇒ Object
readonly
Returns the value of attribute header_names.
-
#hub ⇒ Object
readonly
Returns the value of attribute hub.
-
#rpc_client ⇒ Object
readonly
Returns the value of attribute rpc_client.
-
#server_id ⇒ Object
readonly
Returns the value of attribute server_id.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Instance Method Summary collapse
- #handle_close ⇒ Object
- #handle_command(websocket_message) ⇒ Object
- #handle_open ⇒ Object
-
#initialize(socket, hub, coder, host, header_names, server_id) ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize(socket, hub, coder, host, header_names, server_id) ⇒ Connection
Returns a new instance of Connection.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/anycable/rack-server/connection.rb', line 21 def initialize(socket, hub, coder, host, header_names, server_id) @socket = socket @coder = coder @hub = hub @header_names = header_names @server_id = server_id @rpc_client = RPC::Client.new(host) @_identifiers = '{}' @_subscriptions = Set.new end |
Instance Attribute Details
#coder ⇒ Object (readonly)
Returns the value of attribute coder.
14 15 16 |
# File 'lib/anycable/rack-server/connection.rb', line 14 def coder @coder end |
#header_names ⇒ Object (readonly)
Returns the value of attribute header_names.
14 15 16 |
# File 'lib/anycable/rack-server/connection.rb', line 14 def header_names @header_names end |
#hub ⇒ Object (readonly)
Returns the value of attribute hub.
14 15 16 |
# File 'lib/anycable/rack-server/connection.rb', line 14 def hub @hub end |
#rpc_client ⇒ Object (readonly)
Returns the value of attribute rpc_client.
14 15 16 |
# File 'lib/anycable/rack-server/connection.rb', line 14 def rpc_client @rpc_client end |
#server_id ⇒ Object (readonly)
Returns the value of attribute server_id.
14 15 16 |
# File 'lib/anycable/rack-server/connection.rb', line 14 def server_id @server_id end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
14 15 16 |
# File 'lib/anycable/rack-server/connection.rb', line 14 def socket @socket end |
Instance Method Details
#handle_close ⇒ Object
39 40 41 42 43 |
# File 'lib/anycable/rack-server/connection.rb', line 39 def handle_close response = rpc_disconnect process_close(response) reset_connection end |
#handle_command(websocket_message) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/anycable/rack-server/connection.rb', line 45 def handle_command() decoded = decode() command = decoded.delete('command') channel_identifier = decoded['identifier'] case command when 'subscribe' then subscribe(channel_identifier) when 'unsubscribe' then unsubscribe(channel_identifier) when 'message' then (channel_identifier, decoded['data']) else raise Errors::UnknownCommand, "Command not found #{command}" end end |
#handle_open ⇒ Object
34 35 36 37 |
# File 'lib/anycable/rack-server/connection.rb', line 34 def handle_open response = rpc_connect process_open(response) end |