diff options
author | Matthew Draper <matthew@trebex.net> | 2016-03-02 19:16:28 +1030 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2016-03-02 19:17:57 +1030 |
commit | fc1b32f8d1d26e41fa79d7a38c852acae24c77a0 (patch) | |
tree | d414a29907719bea99b1f10783820fa136bda209 /actioncable/app | |
parent | 1fdc83947be8b7e8838419a72f6f7b71ee63ac35 (diff) | |
parent | 53e163dc3fd2c77c7967534665e81e0ef40df580 (diff) | |
download | rails-fc1b32f8d1d26e41fa79d7a38c852acae24c77a0.tar.gz rails-fc1b32f8d1d26e41fa79d7a38c852acae24c77a0.tar.bz2 rails-fc1b32f8d1d26e41fa79d7a38c852acae24c77a0.zip |
Merge pull request #23976 from danielrhodes/enhancement/ac-ping-to-message-type
ActionCable: Add a "welcome" and "ping" message type
Diffstat (limited to 'actioncable/app')
3 files changed, 8 insertions, 9 deletions
diff --git a/actioncable/app/assets/javascripts/action_cable/connection.coffee b/actioncable/app/assets/javascripts/action_cable/connection.coffee index 4244322a1e..e8c9ae6bd0 100644 --- a/actioncable/app/assets/javascripts/action_cable/connection.coffee +++ b/actioncable/app/assets/javascripts/action_cable/connection.coffee @@ -73,8 +73,11 @@ class ActionCable.Connection events: message: (event) -> {identifier, message, type} = JSON.parse(event.data) - switch type + when message_types.welcome + @consumer.connectionMonitor.connected() + when message_types.ping + @consumer.connectionMonitor.ping() when message_types.confirmation @consumer.subscriptions.notify(identifier, "connected") when message_types.rejection diff --git a/actioncable/app/assets/javascripts/action_cable/connection_monitor.coffee b/actioncable/app/assets/javascripts/action_cable/connection_monitor.coffee index 75a6f1fb07..740e86643e 100644 --- a/actioncable/app/assets/javascripts/action_cable/connection_monitor.coffee +++ b/actioncable/app/assets/javascripts/action_cable/connection_monitor.coffee @@ -7,10 +7,7 @@ class ActionCable.ConnectionMonitor @staleThreshold: 6 # Server::Connections::BEAT_INTERVAL * 2 (missed two pings) - identifier: ActionCable.INTERNAL.identifiers.ping - constructor: (@consumer) -> - @consumer.subscriptions.add(this) @start() connected: -> @@ -22,11 +19,12 @@ class ActionCable.ConnectionMonitor disconnected: -> @disconnectedAt = now() - received: -> + ping: -> @pingedAt = now() reset: -> @reconnectAttempts = 0 + @consumer.connection.isOpen() start: -> @reset() diff --git a/actioncable/app/assets/javascripts/action_cable/subscriptions.coffee b/actioncable/app/assets/javascripts/action_cable/subscriptions.coffee index ae041ffa2b..2443bca14a 100644 --- a/actioncable/app/assets/javascripts/action_cable/subscriptions.coffee +++ b/actioncable/app/assets/javascripts/action_cable/subscriptions.coffee @@ -58,7 +58,5 @@ class ActionCable.Subscriptions sendCommand: (subscription, command) -> {identifier} = subscription - if identifier is ActionCable.INTERNAL.identifiers.ping - @consumer.connection.isOpen() - else - @consumer.send({command, identifier}) + @consumer.send({command, identifier}) + |