Only broadcast to authenticated clients.

This commit is contained in:
Martin Edenhofer 2015-12-08 14:22:13 +01:00
parent 3b47de0014
commit 08c2a59569

View file

@ -19,7 +19,7 @@ module Sessions
start new session start new session
Sessions.create( client_id, session_data, { :type => 'websocket' } ) Sessions.create( client_id, session_data, { type: 'websocket' } )
returns returns
@ -124,21 +124,21 @@ returns
{ {
'4711' => { '4711' => {
:user => { user: {
'id' => 123, 'id' => 123,
}, },
:meta => { meta: {
:type => 'websocket', type: 'websocket',
:last_ping => time_of_last_ping, last_ping: time_of_last_ping,
} }
}, },
'4712' => { '4712' => {
:user => { user: {
'id' => 124, 'id' => 124,
}, },
:meta => { meta: {
:type => 'ajax', type: 'ajax',
:last_ping => time_of_last_ping, last_ping: time_of_last_ping,
} }
}, },
} }
@ -230,12 +230,12 @@ get session data
returns returns
{ {
:user => { user: {
'id' => 123, 'id' => 123,
}, },
:meta => { meta: {
:type => 'websocket', type: 'websocket',
:last_ping => time_of_last_ping, last_ping: time_of_last_ping,
} }
} }
@ -345,7 +345,7 @@ returns
=begin =begin
send message to all client send message to all authenticated client
Sessions.broadcast(data) Sessions.broadcast(data)
@ -360,6 +360,10 @@ returns
# list all current clients # list all current clients
client_list = sessions client_list = sessions
client_list.each {|client_id| client_list.each {|client_id|
session = Sessions.get(client_id)
next if !session
next if !session[:user]
next if !session[:user]['id']
Sessions.send(client_id, data) Sessions.send(client_id, data)
} }
true true