diff --git a/app/assets/javascripts/app/lib/app_post/websocket.js.coffee b/app/assets/javascripts/app/lib/app_post/websocket.js.coffee index e415d5e95..6f23ab554 100644 --- a/app/assets/javascripts/app/lib/app_post/websocket.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/websocket.js.coffee @@ -207,9 +207,7 @@ class _webSocketSingleton extends App.Controller # take connection down and keep it down return if @connectionKeepDown - # set timestamp to get spool messages later if @connectionEstablished - @lastSpoolMessage = Math.round( +new Date()/1000 ) @connectionEstablished = false return if @backend is 'ajax' @@ -248,6 +246,10 @@ class _webSocketSingleton extends App.Controller # go through all blocks for item in data + # set timestamp to get spool messages later + if item['spool'] + @lastSpoolMessage = Math.round( +new Date()/1000 ) + # reset reconnect loop if item['action'] is 'pong' @pong() diff --git a/app/controllers/long_polling_controller.rb b/app/controllers/long_polling_controller.rb index 1fe195366..8bc6ef49e 100644 --- a/app/controllers/long_polling_controller.rb +++ b/app/controllers/long_polling_controller.rb @@ -31,7 +31,13 @@ class LongPollingController < ApplicationController # get spool messages and send them to new client connection 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 spool = Session.spool_list( params['data']['timestamp'], current_user.id ) @@ -49,7 +55,7 @@ class LongPollingController < ApplicationController # send spool:sent event to client sleep 0.2 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 diff --git a/script/websocket-server.rb b/script/websocket-server.rb index 6c0d4ca29..627bcdd39 100755 --- a/script/websocket-server.rb +++ b/script/websocket-server.rb @@ -55,7 +55,7 @@ OptionParser.new do |opts| end.parse! if ARGV[0] != 'start' && ARGV[0] != 'stop' - puts "Usage: websocket-server.rb start|stop [options]" + puts "Usage: #{File.basename(__FILE__)} start|stop [options]" exit; end @@ -137,9 +137,15 @@ EventMachine.run { # get spool messages and send them to new client connection 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.each { |item| @@ -153,11 +159,13 @@ EventMachine.run { @clients[client_id][:websocket].send( "[#{ msg }]" ) end } + else + log 'error', "can't send spool, session not authenticated", client_id end # send spool:sent event to client 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 # get session