Fixed websocket messages with recipients.
This commit is contained in:
parent
6a9e77c525
commit
1f65db48ac
3 changed files with 10 additions and 14 deletions
|
@ -75,7 +75,7 @@ class LongPollingController < ApplicationController
|
||||||
# broadcast to recipient list
|
# broadcast to recipient list
|
||||||
if params['data']['recipient'] && params['data']['recipient']['user_id']
|
if params['data']['recipient'] && params['data']['recipient']['user_id']
|
||||||
params['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'].to_s == user_id.to_s
|
||||||
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
|
||||||
Sessions.send( local_client_id, params['data'] )
|
Sessions.send( local_client_id, params['data'] )
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,16 +29,12 @@ returns
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def self.create( client_id, session, meta )
|
def self.create( client_id, session, meta )
|
||||||
data = {}
|
|
||||||
if session
|
|
||||||
data[:id] = session[:id]
|
|
||||||
end
|
|
||||||
path = @path + '/' + client_id.to_s
|
path = @path + '/' + client_id.to_s
|
||||||
FileUtils.mkpath path
|
FileUtils.mkpath path
|
||||||
meta[:last_ping] = Time.new.to_i.to_s
|
meta[:last_ping] = Time.new.to_i.to_s
|
||||||
File.open( path + '/session', 'wb' ) { |file|
|
File.open( path + '/session', 'wb' ) { |file|
|
||||||
data = {
|
data = {
|
||||||
:user => data,
|
:user => session,
|
||||||
:meta => meta,
|
:meta => meta,
|
||||||
}
|
}
|
||||||
file.write Marshal.dump(data)
|
file.write Marshal.dump(data)
|
||||||
|
@ -109,7 +105,7 @@ returns
|
||||||
{
|
{
|
||||||
'4711' => {
|
'4711' => {
|
||||||
:user => {
|
:user => {
|
||||||
:id => 123,
|
'id' => 123,
|
||||||
},
|
},
|
||||||
:meta => {
|
:meta => {
|
||||||
:type => 'websocket',
|
:type => 'websocket',
|
||||||
|
@ -118,7 +114,7 @@ returns
|
||||||
},
|
},
|
||||||
'4712' => {
|
'4712' => {
|
||||||
:user => {
|
:user => {
|
||||||
:id => 124,
|
'id' => 124,
|
||||||
},
|
},
|
||||||
:meta => {
|
:meta => {
|
||||||
:type => 'ajax',
|
:type => 'ajax',
|
||||||
|
@ -214,7 +210,7 @@ returns
|
||||||
|
|
||||||
{
|
{
|
||||||
:user => {
|
:user => {
|
||||||
:id => 123,
|
'id' => 123,
|
||||||
},
|
},
|
||||||
:meta => {
|
:meta => {
|
||||||
:type => 'websocket',
|
:type => 'websocket',
|
||||||
|
@ -301,8 +297,8 @@ returns
|
||||||
session = Sessions.get(client_id)
|
session = Sessions.get(client_id)
|
||||||
next if !session
|
next if !session
|
||||||
next if !session[:user]
|
next if !session[:user]
|
||||||
next if !session[:user][:id]
|
next if !session[:user]['id']
|
||||||
next if session[:user][:id].to_i != user_id.to_i
|
next if session[:user]['id'].to_i != user_id.to_i
|
||||||
Sessions.send( client_id, data )
|
Sessions.send( client_id, data )
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
|
@ -482,8 +478,8 @@ returns
|
||||||
session_data = Sessions.get( client_id )
|
session_data = Sessions.get( client_id )
|
||||||
next if !session_data
|
next if !session_data
|
||||||
next if !session_data[:user]
|
next if !session_data[:user]
|
||||||
next if !session_data[:user][:id]
|
next if !session_data[:user]['id']
|
||||||
user = User.find( session_data[:user][:id] )
|
user = User.lookup( session_data[:user]['id'] )
|
||||||
next if !user
|
next if !user
|
||||||
|
|
||||||
# start client thread
|
# start client thread
|
||||||
|
|
|
@ -199,7 +199,7 @@ EventMachine.run {
|
||||||
log 'error', "recipient.user_id attribute isn't an array '#{ data['recipient']['user_id'].inspect }'"
|
log 'error', "recipient.user_id attribute isn't an array '#{ data['recipient']['user_id'].inspect }'"
|
||||||
else
|
else
|
||||||
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 ]
|
||||||
@clients[ local_client_id ][:websocket].send( "[#{msg}]" )
|
@clients[ local_client_id ][:websocket].send( "[#{msg}]" )
|
||||||
|
|
Loading…
Reference in a new issue