diff --git a/app/assets/javascripts/app/controllers/task_widget.js.coffee b/app/assets/javascripts/app/controllers/task_widget.js.coffee index 2d4f8c04a..3d1c62401 100644 --- a/app/assets/javascripts/app/controllers/task_widget.js.coffee +++ b/app/assets/javascripts/app/controllers/task_widget.js.coffee @@ -26,6 +26,18 @@ class App.TaskWidget extends App.Controller App.Event.bind 'spool:sent', => @spoolSent = true + # broadcast to other browser instance + App.WebSocket.send( + action: 'broadcast' + event: 'session:takeover' + spool: true + recipient: + user_id: [ App.Session.get( 'id' ) ] + data: + taskbar_id: App.TaskManager.TaskbarId() + ) + + # session take over message App.Event.bind 'session:takeover', (data) => diff --git a/app/assets/javascripts/app/lib/app_post/task_manager.js.coffee b/app/assets/javascripts/app/lib/app_post/task_manager.js.coffee index c48aa53de..0446cfb4a 100644 --- a/app/assets/javascripts/app/lib/app_post/task_manager.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/task_manager.js.coffee @@ -342,17 +342,6 @@ class _taskManagerSingleton extends App.Controller # check if we have different - # broadcast to other browser instance - App.WebSocket.send( - action: 'broadcast' - event: 'session:takeover' - spool: true - data: - recipient: - user_id: [ App.Session.get( 'id' ) ] - taskbar_id: @TaskbarId() - ) - tasks = @all() return if !tasks diff --git a/app/controllers/long_polling_controller.rb b/app/controllers/long_polling_controller.rb index 282690c63..1fe195366 100644 --- a/app/controllers/long_polling_controller.rb +++ b/app/controllers/long_polling_controller.rb @@ -25,7 +25,7 @@ class LongPollingController < ApplicationController # spool messages for new connects if params['data']['spool'] - msg = JSON.generate( params ) + msg = JSON.generate( params['data'] ) Session.spool_create(msg) end @@ -38,10 +38,10 @@ class LongPollingController < ApplicationController 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'] ) + Session.send( client_id, item[:message] ) else log 'notice', "send spool", client_id - Session.send( client_id, item[:message]['data'] ) + Session.send( client_id, item[:message] ) end } end @@ -72,8 +72,8 @@ class LongPollingController < ApplicationController if local_client_id != client_id # broadcast to recipient list - if params['data']['data']['recipient'] && params['data']['data']['recipient']['user_id'] - params['data']['data']['recipient']['user_id'].each { |user_id| + if params['data']['recipient'] && params['data']['recipient']['user_id'] + params['data']['recipient']['user_id'].each { |user_id| if local_client[:user][:id] == user_id log 'notice', "send broadcast from (#{client_id.to_s}) to (user_id #{user_id})", local_client_id Session.send( local_client_id, params['data'] ) diff --git a/lib/session.rb b/lib/session.rb index 2fac3e874..3dc6a633b 100644 --- a/lib/session.rb +++ b/lib/session.rb @@ -86,19 +86,18 @@ module Session end # add spool attribute to push spool info to clients - message_parsed['data']['spool'] = true + message_parsed['spool'] = true # only send not already now messages if !timestamp || timestamp < spool['timestamp'] # spool to recipient list - if message_parsed['data'] && message_parsed['data']['data'] && message_parsed['data']['data']['recipient'] && message_parsed['data']['data']['recipient']['user_id'] - message_parsed['data']['data']['recipient']['user_id'].each { |user_id| + if message_parsed['recipient'] && message_parsed['recipient']['user_id'] + message_parsed['recipient']['user_id'].each { |user_id| if current_user_id == user_id item = { :type => 'direct', :message => message_parsed, - :spool => spool, } data.push item end @@ -109,7 +108,6 @@ module Session item = { :type => 'broadcast', :message => message_parsed, - :spool => spool, } data.push item end diff --git a/script/websocket-server.rb b/script/websocket-server.rb index 2ed2e2d03..6c0d4ca29 100755 --- a/script/websocket-server.rb +++ b/script/websocket-server.rb @@ -145,7 +145,6 @@ EventMachine.run { # 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 }]" ) @@ -178,18 +177,19 @@ EventMachine.run { client_list = Session.list client_list.each {|local_client_id, local_client| if local_client_id != client_id + # broadcast to recipient list - if data['data']['recipient'] - if data['data']['recipient'].class != Hash - log 'error', "recipient attribute isn't a hash '#{ data['data']['recipient'].inspect }'" + if data['recipient'] + if data['recipient'].class != Hash + log 'error', "recipient attribute isn't a hash '#{ data['recipient'].inspect }'" else - if !data['data']['recipient'].has_key?('user_id') - log 'error', "need recipient.user_id attribute '#{ data['data']['recipient'].inspect }'" + if !data['recipient'].has_key?('user_id') + log 'error', "need recipient.user_id attribute '#{ data['recipient'].inspect }'" else - if data['data']['recipient']['user_id'].class != Array - log 'error', "recipient.user_id attribute isn't an array '#{ data['data']['recipient']['user_id'].inspect }'" + if data['recipient']['user_id'].class != Array + log 'error', "recipient.user_id attribute isn't an array '#{ data['recipient']['user_id'].inspect }'" else - data['data']['recipient']['user_id'].each { |user_id| + data['recipient']['user_id'].each { |user_id| if local_client[:user][:id].to_i == user_id.to_i log 'notice', "send broadcast from (#{client_id.to_s}) to (user_id=#{user_id})", local_client_id if local_client[:meta][:type] == 'websocket' && @clients[ local_client_id ]