From 033de15758bfb57a43e5e903fc4a1f6fa9fac118 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Thu, 9 Apr 2015 18:50:22 -0500 Subject: Collect information about all the open connections and a method to fetch that --- lib/action_cable/connection/base.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'lib/action_cable/connection') 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) -- cgit v1.2.3