Improved re-spool of spool messages after connection was down.
This commit is contained in:
parent
4dd231053e
commit
f5c65bced4
3 changed files with 24 additions and 8 deletions
|
@ -207,9 +207,7 @@ class _webSocketSingleton extends App.Controller
|
||||||
# take connection down and keep it down
|
# take connection down and keep it down
|
||||||
return if @connectionKeepDown
|
return if @connectionKeepDown
|
||||||
|
|
||||||
# set timestamp to get spool messages later
|
|
||||||
if @connectionEstablished
|
if @connectionEstablished
|
||||||
@lastSpoolMessage = Math.round( +new Date()/1000 )
|
|
||||||
@connectionEstablished = false
|
@connectionEstablished = false
|
||||||
|
|
||||||
return if @backend is 'ajax'
|
return if @backend is 'ajax'
|
||||||
|
@ -248,6 +246,10 @@ class _webSocketSingleton extends App.Controller
|
||||||
# go through all blocks
|
# go through all blocks
|
||||||
for item in data
|
for item in data
|
||||||
|
|
||||||
|
# set timestamp to get spool messages later
|
||||||
|
if item['spool']
|
||||||
|
@lastSpoolMessage = Math.round( +new Date()/1000 )
|
||||||
|
|
||||||
# reset reconnect loop
|
# reset reconnect loop
|
||||||
if item['action'] is 'pong'
|
if item['action'] is 'pong'
|
||||||
@pong()
|
@pong()
|
||||||
|
|
|
@ -31,7 +31,13 @@ class LongPollingController < ApplicationController
|
||||||
|
|
||||||
# get spool messages and send them to new client connection
|
# get spool messages and send them to new client connection
|
||||||
if params['data']['action'] == 'spool'
|
if params['data']['action'] == 'spool'
|
||||||
log 'notice', "request spool data", client_id
|
|
||||||
|
# error handling
|
||||||
|
if params['data']['timestamp']
|
||||||
|
log 'notice', "request spool data > '#{Time.at( params['data']['timestamp'] ).to_s}'", client_id
|
||||||
|
else
|
||||||
|
log 'notice', "request spool init data", client_id
|
||||||
|
end
|
||||||
|
|
||||||
if current_user
|
if current_user
|
||||||
spool = Session.spool_list( params['data']['timestamp'], current_user.id )
|
spool = Session.spool_list( params['data']['timestamp'], current_user.id )
|
||||||
|
@ -49,7 +55,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', :data => { :timestamp => Time.now.to_i } } )
|
Session.send( client_id, { :event => 'spool:sent', :data => { :timestamp => Time.now.utc.to_i } } )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ OptionParser.new do |opts|
|
||||||
end.parse!
|
end.parse!
|
||||||
|
|
||||||
if ARGV[0] != 'start' && ARGV[0] != 'stop'
|
if ARGV[0] != 'start' && ARGV[0] != 'stop'
|
||||||
puts "Usage: websocket-server.rb start|stop [options]"
|
puts "Usage: #{File.basename(__FILE__)} start|stop [options]"
|
||||||
exit;
|
exit;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -137,9 +137,15 @@ EventMachine.run {
|
||||||
|
|
||||||
# get spool messages and send them to new client connection
|
# get spool messages and send them to new client connection
|
||||||
if data['action'] == 'spool'
|
if data['action'] == 'spool'
|
||||||
log 'notice', "request spool data", client_id
|
|
||||||
|
|
||||||
if @clients[client_id][:session]['id']
|
# error handling
|
||||||
|
if data['timestamp']
|
||||||
|
log 'notice', "request spool data > '#{Time.at(data['timestamp']).to_s}'", client_id
|
||||||
|
else
|
||||||
|
log 'notice', "request spool with init data", client_id
|
||||||
|
end
|
||||||
|
|
||||||
|
if @clients[client_id] && @clients[client_id][:session] && @clients[client_id][:session]['id']
|
||||||
spool = Session.spool_list( data['timestamp'], @clients[client_id][:session]['id'] )
|
spool = Session.spool_list( data['timestamp'], @clients[client_id][:session]['id'] )
|
||||||
spool.each { |item|
|
spool.each { |item|
|
||||||
|
|
||||||
|
@ -153,11 +159,13 @@ EventMachine.run {
|
||||||
@clients[client_id][:websocket].send( "[#{ msg }]" )
|
@clients[client_id][:websocket].send( "[#{ msg }]" )
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
log 'error', "can't send spool, session not authenticated", client_id
|
||||||
end
|
end
|
||||||
|
|
||||||
# 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","data":{"timestamp":' + Time.now.to_i.to_s + '}}]' )
|
@clients[client_id][:websocket].send( '[{"event":"spool:sent","data":{"timestamp":' + Time.now.utc.to_i.to_s + '}}]' )
|
||||||
end
|
end
|
||||||
|
|
||||||
# get session
|
# get session
|
||||||
|
|
Loading…
Reference in a new issue