123456789_123456789_123456789_123456789_123456789_

Module: ActionCable::Server::Connections

Do not use. This module is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
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 ::ActionCable::RemoteConnections for that.

Constant Summary

Instance Method Summary

Instance Method Details

#add_connection(connection)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/server/connections.rb', line 20

def add_connection(connection)
  connections << connection
end

#connections

[ GitHub ]

  
# File 'actioncable/lib/action_cable/server/connections.rb', line 16

def connections
  @connections ||= []
end

#open_connections_statistics

[ GitHub ]

  
# File 'actioncable/lib/action_cable/server/connections.rb', line 39

def open_connections_statistics
  connections.map(&:statistics)
end

#remove_connection(connection)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/server/connections.rb', line 24

def remove_connection(connection)
  connections.delete connection
end

#setup_heartbeat_timer

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.

[ GitHub ]

  
# File 'actioncable/lib/action_cable/server/connections.rb', line 33

def setup_heartbeat_timer
  @heartbeat_timer ||= event_loop.timer(BEAT_INTERVAL) do
    event_loop.post { connections.each(&:beat) }
  end
end