1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Uninstall event handlers when replacing WebSocket instance

Ensures we don't get "onclose" events from a previous WebSocket that was in the "closing" state
This commit is contained in:
Javan Makhmali 2016-02-19 10:26:41 -05:00 committed by Pratik Naik
parent ab28276713
commit 1a90ff9a4d

View file

@ -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)