Skip to content

Commit

Permalink
Uninstall event handlers when replacing WebSocket instance
Browse files Browse the repository at this point in the history
Ensures we don't get "onclose" events from a previous WebSocket that was in the "closing" state
  • Loading branch information
javan authored and lifo committed Feb 23, 2016
1 parent ab28276 commit 1a90ff9
Showing 1 changed file with 6 additions and 0 deletions.
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1a90ff9

Please sign in to comment.