Improved spool feature to use server site timestamps (to have no conflict with different times on server/client).
This commit is contained in:
parent
12acacfc47
commit
7a7a956f24
3 changed files with 26 additions and 6 deletions
|
@ -37,6 +37,7 @@ class _Singleton extends App.Controller
|
||||||
queue: []
|
queue: []
|
||||||
supported: true
|
supported: true
|
||||||
lastSpoolMessage: undefined
|
lastSpoolMessage: undefined
|
||||||
|
sentSpoolFinished: true
|
||||||
connectionKeepDown: false
|
connectionKeepDown: false
|
||||||
connectionEstablished: false
|
connectionEstablished: false
|
||||||
connectionWasEstablished: false
|
connectionWasEstablished: false
|
||||||
|
@ -48,7 +49,7 @@ class _Singleton extends App.Controller
|
||||||
super
|
super
|
||||||
|
|
||||||
# on auth, send new auth data to server
|
# on auth, send new auth data to server
|
||||||
App.Event.bind 'auth', =>
|
App.Event.bind 'auth', (data) =>
|
||||||
@auth()
|
@auth()
|
||||||
|
|
||||||
# bind to send messages
|
# bind to send messages
|
||||||
|
@ -60,6 +61,21 @@ class _Singleton extends App.Controller
|
||||||
@spool()
|
@spool()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# get spool:sent
|
||||||
|
App.Event.bind( 'spool:sent', (data) =>
|
||||||
|
|
||||||
|
# set timestamp to get spool messages later
|
||||||
|
if !data
|
||||||
|
@lastSpoolMessage = Math.round( +new Date()/1000 )
|
||||||
|
else
|
||||||
|
@lastSpoolMessage = data.timestamp
|
||||||
|
|
||||||
|
# set sentSpoolFinished
|
||||||
|
@sentSpoolFinished = true
|
||||||
|
|
||||||
|
@clearDelay 'reset-spool-sent-if-not-returned', 'ws'
|
||||||
|
)
|
||||||
|
|
||||||
# inital connect
|
# inital connect
|
||||||
@connect()
|
@connect()
|
||||||
|
|
||||||
|
@ -93,6 +109,8 @@ class _Singleton extends App.Controller
|
||||||
@send(data)
|
@send(data)
|
||||||
|
|
||||||
spool: =>
|
spool: =>
|
||||||
|
return if !@sentSpoolFinished
|
||||||
|
@sentSpoolFinished = false
|
||||||
|
|
||||||
# build data to send to server
|
# build data to send to server
|
||||||
data =
|
data =
|
||||||
|
@ -102,15 +120,17 @@ class _Singleton extends App.Controller
|
||||||
|
|
||||||
@log 'Websocket', 'debug', 'spool', data
|
@log 'Websocket', 'debug', 'spool', data
|
||||||
|
|
||||||
|
# reset @sentSpoolFinished if spool:sent will not return
|
||||||
|
reset = =>
|
||||||
|
@sentSpoolFinished = true
|
||||||
|
@delay reset, 60000, 'reset-spool-sent-finished-if-not-returned', 'ws'
|
||||||
|
|
||||||
# ask for spool messages
|
# ask for spool messages
|
||||||
App.Event.trigger(
|
App.Event.trigger(
|
||||||
'ws:send'
|
'ws:send'
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
|
|
||||||
# set timestamp to get spool messages later
|
|
||||||
@lastSpoolMessage = Math.round( +new Date()/1000 )
|
|
||||||
|
|
||||||
close: ( params = {} ) =>
|
close: ( params = {} ) =>
|
||||||
if params['force']
|
if params['force']
|
||||||
@connectionKeepDown = true
|
@connectionKeepDown = true
|
||||||
|
|
|
@ -47,7 +47,7 @@ class LongPollingController < ApplicationController
|
||||||
# send spool:sent event to client
|
# send spool:sent event to client
|
||||||
sleep 0.2
|
sleep 0.2
|
||||||
log 'notice', "send spool:sent event", client_id
|
log 'notice', "send spool:sent event", client_id
|
||||||
Session.send( client_id, { :event => 'spool:sent' } )
|
Session.send( client_id, { :event => 'spool:sent', :timestamp => Time.now.to_i } )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -154,7 +154,7 @@ EventMachine.run {
|
||||||
|
|
||||||
# send spool:sent event to client
|
# send spool:sent event to client
|
||||||
log 'notice', "send spool:sent event", client_id
|
log 'notice', "send spool:sent event", client_id
|
||||||
@clients[client_id][:websocket].send( '[{"event":"spool:sent"}]' )
|
@clients[client_id][:websocket].send( '[{"event":"spool:sent","time":' + Time.now.to_i.to_s + '}]' )
|
||||||
end
|
end
|
||||||
|
|
||||||
# get session
|
# get session
|
||||||
|
|
Loading…
Reference in a new issue