Improved error handling.
This commit is contained in:
parent
09531e7a4d
commit
96c479b40b
|
@ -120,7 +120,7 @@ EventMachine.run {
|
||||||
begin
|
begin
|
||||||
data = JSON.parse(msg)
|
data = JSON.parse(msg)
|
||||||
rescue => e
|
rescue => e
|
||||||
log 'error', "can't parse message: #{ msg }, #{ e.inspect}", client_id
|
log 'error', "can't parse message: #{ msg }, #{ e.inspect }", client_id
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -182,17 +182,29 @@ EventMachine.run {
|
||||||
if local_client_id.to_s != client_id.to_s
|
if local_client_id.to_s != client_id.to_s
|
||||||
|
|
||||||
# broadcast to recipient list
|
# broadcast to recipient list
|
||||||
if data['recipient'] && data['recipient']['user_id']
|
if data['recipient']
|
||||||
data['recipient']['user_id'].each { |user_id|
|
if data['recipient'].class != Hash
|
||||||
if local_client[:user][:id] == user_id
|
log 'error', "recipient attribute isn't a hash '#{ data['recipient'].inspect }'"
|
||||||
log 'notice', "send broadcast to (user_id=#{user_id})", local_client_id
|
else
|
||||||
if local_client[:meta][:type] == 'websocket' && @clients[ local_client_id ]
|
if !data['recipient'].has_key?('user_id')
|
||||||
@clients[ local_client_id ][:websocket].send( "[#{msg}]" )
|
log 'error', "need recipient.user_id attribute '#{ data['recipient'].inspect }'"
|
||||||
|
else
|
||||||
|
if data['recipient']['user_id'].class != Array
|
||||||
|
log 'error', "recipient.user_id attribute isn't an array '#{ data['recipient']['user_id'].inspect }'"
|
||||||
else
|
else
|
||||||
Session.send( local_client_id, data )
|
data['recipient']['user_id'].each { |user_id|
|
||||||
|
if local_client[:user][:id].to_i == user_id.to_i
|
||||||
|
log 'notice', "send broadcast 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}]" )
|
||||||
|
else
|
||||||
|
Session.send( local_client_id, data )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
end
|
||||||
|
|
||||||
# broadcast every client
|
# broadcast every client
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue