Class: AnyCable::Rack::Connection
- Inherits:
-
Object
- Object
- AnyCable::Rack::Connection
- Includes:
- Logging
- Defined in:
- lib/anycable/rack/connection.rb
Overview
:nodoc:
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
-
#coder ⇒ Object
readonly
Returns the value of attribute coder.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#hub ⇒ Object
readonly
Returns the value of attribute hub.
-
#rpc_client ⇒ Object
readonly
Returns the value of attribute rpc_client.
-
#sid ⇒ Object
readonly
Returns the value of attribute sid.
-
#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:, rpc_client:, headers:) ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize(socket, hub:, coder:, rpc_client:, headers:) ⇒ Connection
Returns a new instance of Connection.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/anycable/rack/connection.rb', line 23 def initialize(socket, hub:, coder:, rpc_client:, headers:) @socket = socket @coder = coder @headers = headers @hub = hub @sid = SecureRandom.hex(6) @rpc_client = rpc_client @_identifiers = "{}" @_subscriptions = Set.new @_istate = {} end |
Instance Attribute Details
#coder ⇒ Object (readonly)
Returns the value of attribute coder.
16 17 18 |
# File 'lib/anycable/rack/connection.rb', line 16 def coder @coder end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
16 17 18 |
# File 'lib/anycable/rack/connection.rb', line 16 def headers @headers end |
#hub ⇒ Object (readonly)
Returns the value of attribute hub.
16 17 18 |
# File 'lib/anycable/rack/connection.rb', line 16 def hub @hub end |
#rpc_client ⇒ Object (readonly)
Returns the value of attribute rpc_client.
16 17 18 |
# File 'lib/anycable/rack/connection.rb', line 16 def rpc_client @rpc_client end |
#sid ⇒ Object (readonly)
Returns the value of attribute sid.
16 17 18 |
# File 'lib/anycable/rack/connection.rb', line 16 def sid @sid end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
16 17 18 |
# File 'lib/anycable/rack/connection.rb', line 16 def socket @socket end |
Instance Method Details
#handle_close ⇒ Object
42 43 44 45 46 |
# File 'lib/anycable/rack/connection.rb', line 42 def handle_close response = rpc_disconnect process_close(response) reset_connection end |
#handle_command(websocket_message) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/anycable/rack/connection.rb', line 48 def handle_command() decoded = decode() command = decoded.delete("command") channel_identifier = decoded["identifier"] log(:debug) { "Command: #{decoded}" } case command when "subscribe" then subscribe(channel_identifier) when "unsubscribe" then unsubscribe(channel_identifier) when "message" then (channel_identifier, decoded["data"]) else log(:error, "Command not found #{command}") end rescue Exception => e # rubocop:disable Lint/RescueException log(:error, "Failed to execute command #{command}: #{e.}") end |
#handle_open ⇒ Object
37 38 39 40 |
# File 'lib/anycable/rack/connection.rb', line 37 def handle_open response = rpc_connect process_open(response) end |