Fixed spool issues.

This commit is contained in:
Martin Edenhofer 2013-06-29 00:26:04 +02:00
parent 1f61d1f728
commit 92fa09d5f2
5 changed files with 29 additions and 30 deletions

View file

@ -26,6 +26,18 @@ class App.TaskWidget extends App.Controller
App.Event.bind 'spool:sent', => App.Event.bind 'spool:sent', =>
@spoolSent = true @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 # session take over message
App.Event.bind 'session:takeover', (data) => App.Event.bind 'session:takeover', (data) =>

View file

@ -342,17 +342,6 @@ class _taskManagerSingleton extends App.Controller
# check if we have different # 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() tasks = @all()
return if !tasks return if !tasks

View file

@ -25,7 +25,7 @@ class LongPollingController < ApplicationController
# spool messages for new connects # spool messages for new connects
if params['data']['spool'] if params['data']['spool']
msg = JSON.generate( params ) msg = JSON.generate( params['data'] )
Session.spool_create(msg) Session.spool_create(msg)
end end
@ -38,10 +38,10 @@ class LongPollingController < ApplicationController
spool.each { |item| spool.each { |item|
if item[:type] == 'direct' if item[:type] == 'direct'
log 'notice', "send spool to (user_id=#{ current_user.id })", client_id 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 else
log 'notice', "send spool", client_id log 'notice', "send spool", client_id
Session.send( client_id, item[:message]['data'] ) Session.send( client_id, item[:message] )
end end
} }
end end
@ -72,8 +72,8 @@ class LongPollingController < ApplicationController
if local_client_id != client_id if local_client_id != client_id
# broadcast to recipient list # broadcast to recipient list
if params['data']['data']['recipient'] && params['data']['data']['recipient']['user_id'] if params['data']['recipient'] && params['data']['recipient']['user_id']
params['data']['data']['recipient']['user_id'].each { |user_id| params['data']['recipient']['user_id'].each { |user_id|
if local_client[:user][:id] == 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 log 'notice', "send broadcast from (#{client_id.to_s}) to (user_id #{user_id})", local_client_id
Session.send( local_client_id, params['data'] ) Session.send( local_client_id, params['data'] )

View file

@ -86,19 +86,18 @@ module Session
end end
# add spool attribute to push spool info to clients # add spool attribute to push spool info to clients
message_parsed['data']['spool'] = true message_parsed['spool'] = true
# only send not already now messages # only send not already now messages
if !timestamp || timestamp < spool['timestamp'] if !timestamp || timestamp < spool['timestamp']
# spool to recipient list # spool to recipient list
if message_parsed['data'] && message_parsed['data']['data'] && message_parsed['data']['data']['recipient'] && message_parsed['data']['data']['recipient']['user_id'] if message_parsed['recipient'] && message_parsed['recipient']['user_id']
message_parsed['data']['data']['recipient']['user_id'].each { |user_id| message_parsed['recipient']['user_id'].each { |user_id|
if current_user_id == user_id if current_user_id == user_id
item = { item = {
:type => 'direct', :type => 'direct',
:message => message_parsed, :message => message_parsed,
:spool => spool,
} }
data.push item data.push item
end end
@ -109,7 +108,6 @@ module Session
item = { item = {
:type => 'broadcast', :type => 'broadcast',
:message => message_parsed, :message => message_parsed,
:spool => spool,
} }
data.push item data.push item
end end

View file

@ -145,7 +145,6 @@ EventMachine.run {
# create new msg to push to client # create new msg to push to client
msg = JSON.generate( item[:message] ) msg = JSON.generate( item[:message] )
if item[:type] == 'direct' if item[:type] == 'direct'
log 'notice', "send spool to (user_id=#{ @clients[client_id][:session]['id'] })", client_id log 'notice', "send spool to (user_id=#{ @clients[client_id][:session]['id'] })", client_id
@clients[client_id][:websocket].send( "[#{ msg }]" ) @clients[client_id][:websocket].send( "[#{ msg }]" )
@ -178,18 +177,19 @@ EventMachine.run {
client_list = Session.list client_list = Session.list
client_list.each {|local_client_id, local_client| client_list.each {|local_client_id, local_client|
if local_client_id != client_id if local_client_id != client_id
# broadcast to recipient list # broadcast to recipient list
if data['data']['recipient'] if data['recipient']
if data['data']['recipient'].class != Hash if data['recipient'].class != Hash
log 'error', "recipient attribute isn't a hash '#{ data['data']['recipient'].inspect }'" log 'error', "recipient attribute isn't a hash '#{ data['recipient'].inspect }'"
else else
if !data['data']['recipient'].has_key?('user_id') if !data['recipient'].has_key?('user_id')
log 'error', "need recipient.user_id attribute '#{ data['data']['recipient'].inspect }'" log 'error', "need recipient.user_id attribute '#{ data['recipient'].inspect }'"
else else
if data['data']['recipient']['user_id'].class != Array if data['recipient']['user_id'].class != Array
log 'error', "recipient.user_id attribute isn't an array '#{ data['data']['recipient']['user_id'].inspect }'" log 'error', "recipient.user_id attribute isn't an array '#{ data['recipient']['user_id'].inspect }'"
else 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 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 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 ] if local_client[:meta][:type] == 'websocket' && @clients[ local_client_id ]