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:
parent
ab28276713
commit
1a90ff9a4d
1 changed files with 6 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue