diff --git a/app/controllers/long_polling_controller.rb b/app/controllers/long_polling_controller.rb index 62de0857a..282690c63 100644 --- a/app/controllers/long_polling_controller.rb +++ b/app/controllers/long_polling_controller.rb @@ -33,16 +33,18 @@ class LongPollingController < ApplicationController if params['data']['action'] == 'spool' log 'notice', "request spool data", client_id - spool = Session.spool_list( params['data']['timestamp'], current_user.id ) - spool.each { |item| - if item[:type] == 'direct' - log 'notice', "send spool to (user_id=#{ current_user.id })", client_id - Session.send( client_id, item[:message]['data'] ) - else - log 'notice', "send spool", client_id - Session.send( client_id, item[:message]['data'] ) - end - } + if current_user + spool = Session.spool_list( params['data']['timestamp'], current_user.id ) + spool.each { |item| + if item[:type] == 'direct' + log 'notice', "send spool to (user_id=#{ current_user.id })", client_id + Session.send( client_id, item[:message]['data'] ) + else + log 'notice', "send spool", client_id + Session.send( client_id, item[:message]['data'] ) + end + } + end # send spool:sent event to client sleep 0.2 diff --git a/script/websocket-server.rb b/script/websocket-server.rb index 72f067cf8..20d94f40e 100755 --- a/script/websocket-server.rb +++ b/script/websocket-server.rb @@ -139,20 +139,22 @@ EventMachine.run { if data['action'] == 'spool' log 'notice', "request spool data", client_id - spool = Session.spool_list( data['timestamp'], @clients[client_id][:session]['id'] ) - spool.each { |item| + if @clients[client_id][:session]['id'] + spool = Session.spool_list( data['timestamp'], @clients[client_id][:session]['id'] ) + spool.each { |item| - # create new msg to push to client - msg = JSON.generate( item[:message] ) + # create new msg to push to client + msg = JSON.generate( item[:message] ) - if item[:type] == 'direct' - log 'notice', "send spool to (user_id=#{ @clients[client_id][:session]['id'] })", client_id - @clients[client_id][:websocket].send( "[#{ msg }]" ) - else - log 'notice', "send spool", client_id - @clients[client_id][:websocket].send( "[#{ msg }]" ) - end - } + if item[:type] == 'direct' + log 'notice', "send spool to (user_id=#{ @clients[client_id][:session]['id'] })", client_id + @clients[client_id][:websocket].send( "[#{ msg }]" ) + else + log 'notice', "send spool", client_id + @clients[client_id][:websocket].send( "[#{ msg }]" ) + end + } + end # send spool:sent event to client log 'notice', "send spool:sent event", client_id