Improved websocket reconnection after wakeup.
This commit is contained in:
parent
8c6d46bc3c
commit
778cddda37
1 changed files with 11 additions and 2 deletions
|
@ -91,6 +91,15 @@ class _webSocketSingleton extends App.Controller
|
||||||
# initial connect
|
# initial connect
|
||||||
@connect()
|
@connect()
|
||||||
|
|
||||||
|
# send ping after visibilitychange to check if connection is open again after wakeup
|
||||||
|
$(document).bind('visibilitychange', =>
|
||||||
|
console.log('visibilitychange')
|
||||||
|
return if document.hidden
|
||||||
|
return if !@connectionEstablished
|
||||||
|
console.log('ping')
|
||||||
|
@ping()
|
||||||
|
)
|
||||||
|
|
||||||
channel: ->
|
channel: ->
|
||||||
@backend
|
@backend
|
||||||
|
|
||||||
|
@ -153,7 +162,7 @@ class _webSocketSingleton extends App.Controller
|
||||||
@log 'debug', 'send websocket ping'
|
@log 'debug', 'send websocket ping'
|
||||||
@send(event: 'ping')
|
@send(event: 'ping')
|
||||||
|
|
||||||
# check if ping is back within 2 min
|
# check if ping is back within 90 sec
|
||||||
App.Delay.clear 'websocket-ping-check', 'ws'
|
App.Delay.clear 'websocket-ping-check', 'ws'
|
||||||
check = =>
|
check = =>
|
||||||
@log 'debug', 'no websocket ping response, reconnect...'
|
@log 'debug', 'no websocket ping response, reconnect...'
|
||||||
|
@ -165,7 +174,7 @@ class _webSocketSingleton extends App.Controller
|
||||||
|
|
||||||
@log 'debug', 'received websocket pong'
|
@log 'debug', 'received websocket pong'
|
||||||
|
|
||||||
# test again after 1 min
|
# test again after 60 sec
|
||||||
App.Delay.set(@ping, 60000, 'websocket-pong', 'ws')
|
App.Delay.set(@ping, 60000, 'websocket-pong', 'ws')
|
||||||
|
|
||||||
connect: =>
|
connect: =>
|
||||||
|
|
Loading…
Reference in a new issue