diff options
author | Jeremy Daer <jeremydaer@gmail.com> | 2016-03-03 18:32:12 -0700 |
---|---|---|
committer | Jeremy Daer <jeremydaer@gmail.com> | 2016-03-03 18:32:12 -0700 |
commit | f8ec3a142fbfc9c6d6ddeb9ae75fd571343dcb40 (patch) | |
tree | 921a414c7f18f0092ac243266c78881d70142c6c /actioncable/app/assets/javascripts/action_cable/connection.coffee | |
parent | 8e9a1a62d35f6597aa344c9c747d5adf0ed4fe5f (diff) | |
parent | 96e6de955217a284a44f2c8171bd83bba5a4877b (diff) | |
download | rails-f8ec3a142fbfc9c6d6ddeb9ae75fd571343dcb40.tar.gz rails-f8ec3a142fbfc9c6d6ddeb9ae75fd571343dcb40.tar.bz2 rails-f8ec3a142fbfc9c6d6ddeb9ae75fd571343dcb40.zip |
Merge pull request #24038 from javan/actioncable-lazy-connection-monitor
Action Cable: Defer starting connection monitor until a connection is opened
Diffstat (limited to 'actioncable/app/assets/javascripts/action_cable/connection.coffee')
-rw-r--r-- | actioncable/app/assets/javascripts/action_cable/connection.coffee | 10 |
1 files changed, 7 insertions, 3 deletions
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() |