aboutsummaryrefslogtreecommitdiffstats
path: root/lib/action_cable
diff options
context:
space:
mode:
Diffstat (limited to 'lib/action_cable')
-rw-r--r--lib/action_cable/connection/base.rb17
-rw-r--r--lib/action_cable/server.rb14
2 files changed, 29 insertions, 2 deletions
diff --git a/lib/action_cable/connection/base.rb b/lib/action_cable/connection/base.rb
index 0c20f11502..655e74ee01 100644
--- a/lib/action_cable/connection/base.rb
+++ b/lib/action_cable/connection/base.rb
@@ -16,18 +16,19 @@ module ActionCable
delegate :worker_pool, :pubsub, :logger, to: :server
def initialize(server, env)
+ @started_at = Time.now
+
@server = server
@env = env
@accept_messages = false
@pending_messages = []
+ @subscriptions = {}
end
def process
logger.info "[ActionCable] #{started_request_message}"
if websocket?
- @subscriptions = {}
-
@websocket = Faye::WebSocket.new(@env)
@websocket.on(:open) do |event|
@@ -93,8 +94,18 @@ module ActionCable
@websocket.close
end
+ def statistics
+ {
+ identifier: connection_identifier,
+ started_at: @started_at,
+ subscriptions: @subscriptions.keys
+ }
+ end
+
private
def initialize_connection
+ server.add_connection(self)
+
connect if respond_to?(:connect)
subscribe_to_internal_channel
@@ -103,6 +114,8 @@ module ActionCable
end
def on_connection_closed
+ server.remove_connection(self)
+
cleanup_subscriptions
unsubscribe_from_internal_channel
disconnect if respond_to?(:disconnect)
diff --git a/lib/action_cable/server.rb b/lib/action_cable/server.rb
index 507b154e0d..a867d8578f 100644
--- a/lib/action_cable/server.rb
+++ b/lib/action_cable/server.rb
@@ -10,6 +10,8 @@ module ActionCable
@worker_pool_size = worker_pool_size
@connection_class = connection
+ @connections = []
+
logger.info "[ActionCable] Initialized server (redis_config: #{@redis_config.inspect}, worker_pool_size: #{@worker_pool_size})"
end
@@ -33,5 +35,17 @@ module ActionCable
@connection_class.identifiers
end
+ def add_connection(connection)
+ @connections << connection
+ end
+
+ def remove_connection(connection)
+ @connections.delete connection
+ end
+
+ def open_connections_statistics
+ @connections.map(&:statistics)
+ end
+
end
end