diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2015-02-26 16:33:17 -0600 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2015-02-26 16:33:17 -0600 |
commit | 89f3fb71c739aee76be619806ab9fe6e513d5a36 (patch) | |
tree | e7f2ea05d3d3a27449c116b7cef5075f9a1e8412 | |
parent | d96ea7c5e4481b5d6b08a98a2c2c9fc7a2a5078a (diff) | |
download | rails-89f3fb71c739aee76be619806ab9fe6e513d5a36.tar.gz rails-89f3fb71c739aee76be619806ab9fe6e513d5a36.tar.bz2 rails-89f3fb71c739aee76be619806ab9fe6e513d5a36.zip |
Remove existing connection when trying to reconnect to ensure we dont end up with multiple connections
-rw-r--r-- | lib/assets/javascripts/cable.js.coffee | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/assets/javascripts/cable.js.coffee b/lib/assets/javascripts/cable.js.coffee index 07f6ba2284..eb80fd7cbf 100644 --- a/lib/assets/javascripts/cable.js.coffee +++ b/lib/assets/javascripts/cable.js.coffee @@ -47,6 +47,8 @@ class @Cable callbacks['onConnect']?() reconnect: => + @removeExistingConnection() + @clearPingWaitTimeout() @resetPingTime() @disconnected() @@ -56,6 +58,13 @@ class @Cable @connect() , @generateReconnectInterval() + removeExistingConnection: => + if @connection? + @connection.onclose = -> # no-op + @connection.onerror = -> # no-op + @connection.close() + @connection = null + resetConnectionAttemptsCount: => @connectionAttempts = 1 |