Added Sessions.send_to() to sense messages to dedicated users.
This commit is contained in:
parent
4e5fb8373f
commit
3441799c7a
2 changed files with 38 additions and 0 deletions
|
@ -281,6 +281,33 @@ returns
|
|||
|
||||
=begin
|
||||
|
||||
send message to recipient client
|
||||
|
||||
Sessions.send_to(user_id, data)
|
||||
|
||||
returns
|
||||
|
||||
true|false
|
||||
|
||||
=end
|
||||
|
||||
def self.send_to( user_id, data )
|
||||
|
||||
# list all current clients
|
||||
client_list = self.sessions
|
||||
client_list.each {|client_id|
|
||||
session = Sessions.get(client_id)
|
||||
next if !session
|
||||
next if !session[:user]
|
||||
next if !session[:user][:id]
|
||||
next if session[:user][:id].to_i != user_id.to_i
|
||||
Sessions.send( client_id, data )
|
||||
}
|
||||
true
|
||||
end
|
||||
|
||||
=begin
|
||||
|
||||
send message to all client
|
||||
|
||||
Sessions.broadcast(data)
|
||||
|
|
|
@ -130,6 +130,17 @@ class SessionEnhancedTest < ActiveSupport::TestCase
|
|||
assert_equal( messages.count, 1, 'messages count')
|
||||
assert_equal( 'ooo123123123123123123', messages[0]['msg'], 'messages broadcast 1')
|
||||
|
||||
# send dedicated message to user
|
||||
Sessions.send_to( agent1.id, { :msg => 'ooo1231231231231231234'} )
|
||||
messages = Sessions.queue(client_id1)
|
||||
assert_equal( messages.count, 1, 'messages count')
|
||||
assert_equal( 'ooo1231231231231231234', messages[0]['msg'], 'messages send 1')
|
||||
|
||||
messages = Sessions.queue(client_id2)
|
||||
assert_equal( messages.count, 0, 'messages count')
|
||||
|
||||
messages = Sessions.queue(client_id3)
|
||||
assert_equal( messages.count, 0, 'messages count')
|
||||
|
||||
# start jobs
|
||||
jobs = Thread.new {
|
||||
|
|
Loading…
Reference in a new issue