From 1a90ff9a4d43b118448fcad72d547074c1efb2fb Mon Sep 17 00:00:00 2001 From: Javan Makhmali Date: Fri, 19 Feb 2016 10:26:41 -0500 Subject: Uninstall event handlers when replacing WebSocket instance Ensures we don't get "onclose" events from a previous WebSocket that was in the "closing" state --- actioncable/app/assets/javascripts/action_cable/connection.coffee | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'actioncable/app') diff --git a/actioncable/app/assets/javascripts/action_cable/connection.coffee b/actioncable/app/assets/javascripts/action_cable/connection.coffee index 78028bda3c..a67ad6e915 100644 --- a/actioncable/app/assets/javascripts/action_cable/connection.coffee +++ b/actioncable/app/assets/javascripts/action_cable/connection.coffee @@ -21,6 +21,7 @@ class ActionCable.Connection throw new Error("Existing connection must be closed before opening") else console.log("[cable] Opening WebSocket, current state is #{@getState()}", Date.now()) + @uninstallEventHandlers() if @webSocket? @webSocket = new WebSocket(@consumer.url) @installEventHandlers() true @@ -60,6 +61,11 @@ class ActionCable.Connection @webSocket["on#{eventName}"] = handler return + uninstallEventHandlers: -> + for eventName of @events + @webSocket["on#{eventName}"] = -> + return + events: message: (event) -> {identifier, message, type} = JSON.parse(event.data) -- cgit v1.2.3