提交 1a90ff9a 编写于 作者: J Javan Makhmali 提交者: Pratik Naik

Uninstall event handlers when replacing WebSocket instance

Ensures we don't get "onclose" events from a previous WebSocket that was in the "closing" state
上级 ab282767
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册