From 96e6de955217a284a44f2c8171bd83bba5a4877b Mon Sep 17 00:00:00 2001 From: Javan Makhmali Date: Thu, 3 Mar 2016 20:21:50 -0500 Subject: Defer starting connection monitor until a connection is opened --- .../app/assets/javascripts/action_cable/connection.coffee | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'actioncable/app/assets/javascripts/action_cable/connection.coffee') diff --git a/actioncable/app/assets/javascripts/action_cable/connection.coffee b/actioncable/app/assets/javascripts/action_cable/connection.coffee index 9be5cdf5fb..bd63f5bb57 100644 --- a/actioncable/app/assets/javascripts/action_cable/connection.coffee +++ b/actioncable/app/assets/javascripts/action_cable/connection.coffee @@ -1,3 +1,5 @@ +#= require ./connection_monitor + # Encapsulate the cable connection held by the consumer. This is an internal class not intended for direct user manipulation. {message_types} = ActionCable.INTERNAL @@ -6,6 +8,7 @@ class ActionCable.Connection @reopenDelay: 500 constructor: (@consumer) -> + @monitor = new ActionCable.ConnectionMonitor this send: (data) -> if @isOpen() @@ -23,6 +26,7 @@ class ActionCable.Connection @uninstallEventHandlers() if @webSocket? @webSocket = new WebSocket(@consumer.url) @installEventHandlers() + @monitor.start() true close: -> @@ -72,9 +76,9 @@ class ActionCable.Connection {identifier, message, type} = JSON.parse(event.data) switch type when message_types.welcome - @consumer.connectionMonitor.connected() + @monitor.recordConnect() when message_types.ping - @consumer.connectionMonitor.ping() + @monitor.recordPing() when message_types.confirmation @consumer.subscriptions.notify(identifier, "connected") when message_types.rejection @@ -98,5 +102,5 @@ class ActionCable.Connection disconnect: -> return if @disconnected @disconnected = true - @consumer.connectionMonitor.disconnected() @consumer.subscriptions.notifyAll("disconnected") + @monitor.recordDisconnect() -- cgit v1.2.3