Fixed websocket messages with recipients.

This commit is contained in:
Martin Edenhofer 2014-10-05 14:38:30 +02:00
parent 6a9e77c525
commit 1f65db48ac
3 changed files with 10 additions and 14 deletions

View file

@ -75,7 +75,7 @@ class LongPollingController < ApplicationController
# broadcast to recipient list
if params['data']['recipient'] && params['data']['recipient']['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
Sessions.send( local_client_id, params['data'] )
end

View file

@ -29,16 +29,12 @@ returns
=end
def self.create( client_id, session, meta )
data = {}
if session
data[:id] = session[:id]
end
path = @path + '/' + client_id.to_s
FileUtils.mkpath path
meta[:last_ping] = Time.new.to_i.to_s
File.open( path + '/session', 'wb' ) { |file|
data = {
:user => data,
:user => session,
:meta => meta,
}
file.write Marshal.dump(data)
@ -109,7 +105,7 @@ returns
{
'4711' => {
:user => {
:id => 123,
'id' => 123,
},
:meta => {
:type => 'websocket',
@ -118,7 +114,7 @@ returns
},
'4712' => {
:user => {
:id => 124,
'id' => 124,
},
:meta => {
:type => 'ajax',
@ -214,7 +210,7 @@ returns
{
:user => {
:id => 123,
'id' => 123,
},
:meta => {
:type => 'websocket',
@ -301,8 +297,8 @@ returns
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
next if !session[:user]['id']
next if session[:user]['id'].to_i != user_id.to_i
Sessions.send( client_id, data )
}
true
@ -482,8 +478,8 @@ returns
session_data = Sessions.get( client_id )
next if !session_data
next if !session_data[:user]
next if !session_data[:user][:id]
user = User.find( session_data[:user][:id] )
next if !session_data[:user]['id']
user = User.lookup( session_data[:user]['id'] )
next if !user
# start client thread

View file

@ -199,7 +199,7 @@ EventMachine.run {
log 'error', "recipient.user_id attribute isn't an array '#{ data['recipient']['user_id'].inspect }'"
else
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
if local_client[:meta][:type] == 'websocket' && @clients[ local_client_id ]
@clients[ local_client_id ][:websocket].send( "[#{msg}]" )