Added connection ping feature.

This commit is contained in:
Martin Edenhofer 2012-08-06 06:36:57 +02:00
parent 3e71b4e484
commit f884ad12f4

View file

@ -56,19 +56,19 @@ class _Singleton extends Spine.Controller
console.log 'send websockend ping' console.log 'send websockend ping'
@send( { action: 'ping' } ) @send( { action: 'ping' } )
# check if ping is back within 30 sec. # check if ping is back within 2 min
if @check_id if @check_id
clearTimeout(@check_id) clearTimeout(@check_id)
check = => check = =>
console.log 'no websockend ping response, reconnect...' console.log 'no websockend ping response, reconnect...'
@close() @close()
@check_id = @delay check, 60000 @check_id = @delay check, 120000
pong: -> pong: ->
console.log 'received websockend ping' console.log 'received websockend ping'
# test again after 10 sec. # test again after 1 min
@delay @ping, 30000 @delay @ping, 60000
connect: => connect: =>
# console.log '------------ws connect....--------------' # console.log '------------ws connect....--------------'
@ -103,7 +103,7 @@ class _Singleton extends Spine.Controller
@queue = [] @queue = []
# send ping to check connection # send ping to check connection
@delay @ping, 30000 @delay @ping, 60000
@ws.onmessage = (e) => @ws.onmessage = (e) =>
pipe = JSON.parse( e.data ) pipe = JSON.parse( e.data )