From 9cca6be1346af6f372ecd3eedeb4b65a72b7059f Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 10 May 2013 23:10:02 +0200 Subject: [PATCH] Improved spool feature of init connection messages. --- script/websocket-server.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/script/websocket-server.rb b/script/websocket-server.rb index 7e20e2fa5..449ae9f1f 100755 --- a/script/websocket-server.rb +++ b/script/websocket-server.rb @@ -141,6 +141,17 @@ EventMachine.run { if data['action'] == 'spool' @spool.each { |message| + begin + message_parsed = JSON.parse( message[:msg] ) + rescue => e + log 'error', "can't parse spool message: #{ message }, #{ e.inspect }" + next + end + + # add spool attribute to push spool info to clients + message_parsed['data']['spool'] = true + msg = JSON.generate( message_parsed ) + # only send not already now messages if !data['timestamp'] || data['timestamp'] < message[:timestamp] @@ -149,14 +160,14 @@ EventMachine.run { message[:msg_object]['recipient']['user_id'].each { |user_id| if @clients[client_id][:session]['id'] == user_id log 'notice', "send spool to (user_id=#{user_id})", client_id - @clients[client_id][:websocket].send( "[#{ message[:msg] }]" ) + @clients[client_id][:websocket].send( "[#{ msg }]" ) end } - # spool every client + # spool to every client else log 'notice', "send spool", client_id - @clients[client_id][:websocket].send( "[#{ message[:msg] }]" ) + @clients[client_id][:websocket].send( "[#{ msg }]" ) end end