Module: ActionCable::Server::Connections
- Included in:
- Base
- Defined in:
- actioncable/lib/action_cable/server/connections.rb
Overview
Collection class for all the connections that have been established on this specific server. Remember, usually you’ll run many Action Cable servers, so you can’t use this collection as a full list of all of the connections established against your application. Instead, use RemoteConnections for that.
Constant Summary collapse
- BEAT_INTERVAL =
3
Instance Method Summary collapse
- #add_connection(connection) ⇒ Object
- #connections ⇒ Object
- #open_connections_statistics ⇒ Object
- #remove_connection(connection) ⇒ Object
-
#setup_heartbeat_timer ⇒ Object
WebSocket connection implementations differ on when they’ll mark a connection as stale.
Instance Method Details
#add_connection(connection) ⇒ Object
14 15 16 |
# File 'actioncable/lib/action_cable/server/connections.rb', line 14 def add_connection(connection) connections << connection end |
#connections ⇒ Object
10 11 12 |
# File 'actioncable/lib/action_cable/server/connections.rb', line 10 def connections @connections ||= [] end |
#open_connections_statistics ⇒ Object
31 32 33 |
# File 'actioncable/lib/action_cable/server/connections.rb', line 31 def open_connections_statistics connections.map(&:statistics) end |
#remove_connection(connection) ⇒ Object
18 19 20 |
# File 'actioncable/lib/action_cable/server/connections.rb', line 18 def remove_connection(connection) connections.delete connection end |
#setup_heartbeat_timer ⇒ Object
WebSocket connection implementations differ on when they’ll mark a connection as stale. We basically never want a connection to go stale, as you then can’t rely on being able to communicate with the connection. To solve this, a 3 second heartbeat runs on all connections. If the beat fails, we automatically disconnect.
25 26 27 28 29 |
# File 'actioncable/lib/action_cable/server/connections.rb', line 25 def setup_heartbeat_timer @heartbeat_timer ||= event_loop.timer(BEAT_INTERVAL) do event_loop.post { connections.map(&:beat) } end end |