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

Wait for connection to close before reopening it

This commit is contained in:
Javan Makhmali 2015-06-27 13:13:44 -04:00
parent 16849a7e68
commit d2c613cd8f

View file

@ -12,20 +12,23 @@ class Cable.Connection
else else
false false
open: -> open: =>
@websocket = new WebSocket(@consumer.url) @websocket = new WebSocket(@consumer.url)
@websocket.onmessage = @onMessage @websocket.onmessage = @onMessage
@websocket.onopen = @onOpen @websocket.onopen = @onOpen
@websocket.onclose = @onClose @websocket.onclose = @onClose
@websocket.onerror = @onError @websocket.onerror = @onError
@websocket
close: -> close: ->
@websocket.close() unless @isClosed() @websocket.close() unless @isClosed()
reopen: -> reopen: ->
@close() if @isClosed()
@open() @open()
else
@websocket.onclose = @open
@websocket.onerror = @open
@websocket.close()
isOpen: -> isOpen: ->
@websocket.readyState is WebSocket.OPEN @websocket.readyState is WebSocket.OPEN