Fixed spool issues.
This commit is contained in:
parent
1f61d1f728
commit
92fa09d5f2
5 changed files with 29 additions and 30 deletions
|
@ -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) =>
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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'] )
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ]
|
||||
|
|
Loading…
Reference in a new issue