aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2015-02-26 16:33:17 -0600
committerPratik Naik <pratiknaik@gmail.com>2015-02-26 16:33:17 -0600
commit89f3fb71c739aee76be619806ab9fe6e513d5a36 (patch)
treee7f2ea05d3d3a27449c116b7cef5075f9a1e8412 /lib
parentd96ea7c5e4481b5d6b08a98a2c2c9fc7a2a5078a (diff)
downloadrails-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
Diffstat (limited to 'lib')
-rw-r--r--lib/assets/javascripts/cable.js.coffee9
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