diff options
author | Javan Makhmali <javan@javan.us> | 2016-02-19 10:26:41 -0500 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2016-02-23 09:37:49 -0600 |
commit | 1a90ff9a4d43b118448fcad72d547074c1efb2fb (patch) | |
tree | 0cee1ed46123abc6f9f9071f2aca6bccb5eb98f6 /actioncable/app/assets | |
parent | ab28276713af8503b667ecbc8c1672c187e944d7 (diff) | |
download | rails-1a90ff9a4d43b118448fcad72d547074c1efb2fb.tar.gz rails-1a90ff9a4d43b118448fcad72d547074c1efb2fb.tar.bz2 rails-1a90ff9a4d43b118448fcad72d547074c1efb2fb.zip |
Uninstall event handlers when replacing WebSocket instance
Ensures we don't get "onclose" events from a previous WebSocket that was in the "closing" state
Diffstat (limited to 'actioncable/app/assets')
-rw-r--r-- | actioncable/app/assets/javascripts/action_cable/connection.coffee | 6 |
1 files changed, 6 insertions, 0 deletions
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) |