diff --git a/app/controllers/long_polling_controller.rb b/app/controllers/long_polling_controller.rb index e2f8aa8b2..5512175e8 100644 --- a/app/controllers/long_polling_controller.rb +++ b/app/controllers/long_polling_controller.rb @@ -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 diff --git a/lib/sessions.rb b/lib/sessions.rb index 6731c8869..86b83c41b 100644 --- a/lib/sessions.rb +++ b/lib/sessions.rb @@ -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 diff --git a/script/websocket-server.rb b/script/websocket-server.rb index 9b5bb0ddc..7d784c31d 100755 --- a/script/websocket-server.rb +++ b/script/websocket-server.rb @@ -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}]" )