From 89f3fb71c739aee76be619806ab9fe6e513d5a36 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Thu, 26 Feb 2015 16:33:17 -0600 Subject: Remove existing connection when trying to reconnect to ensure we dont end up with multiple connections --- lib/assets/javascripts/cable.js.coffee | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib') 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 -- cgit v1.2.3