Handle peer_id generation during Socket.IO handshake

master
Daniel Berteaud 10 years ago
parent ae2d160f9e
commit 2b262733b1
  1. 17
      vroom.pl

@ -999,8 +999,10 @@ helper get_room_conf => sub {
# Socket.IO handshake # Socket.IO handshake
get '/socket.io/:ver' => sub { get '/socket.io/:ver' => sub {
my $self = shift; my $self = shift;
my $sid = $self->get_random(256);
$self->session( peer_id => $sid );
my $handshake = Protocol::SocketIO::Handshake->new( my $handshake = Protocol::SocketIO::Handshake->new(
session_id => $self->session('peer_id'), session_id => $sid,
heartbeat_timeout => 20, heartbeat_timeout => 20,
close_timeout => 40, close_timeout => 40,
transports => [qw/websocket/] transports => [qw/websocket/]
@ -1050,6 +1052,11 @@ websocket '/socket.io/:ver/websocket/:id' => sub {
$self->finish; $self->finish;
return; return;
} }
$self->set_peer_role({
room => $room,
peer_id => $self->session('peer_id'),
role => $self->session($room)->{role}
});
# Are we under the limit of members ? # Are we under the limit of members ?
my $limit = $self->get_member_limit($room); my $limit = $self->get_member_limit($room);
if ($limit > 0 && scalar $self->get_room_members($room) >= $limit){ if ($limit > 0 && scalar $self->get_room_members($room) >= $limit){
@ -1493,9 +1500,6 @@ any '/api' => sub {
my $role = $self->get_key_role($token, $room->{name}); my $role = $self->get_key_role($token, $room->{name});
my $reason; my $reason;
my $code = 401; my $code = 401;
if (!$self->session('peer_id') || $self->session('peer_id') eq ''){
$self->session(peer_id => $self->get_random(256));
}
if ($room->{owner_password} && Crypt::SaltedHash->validate($room->{owner_password}, $pass)){ if ($room->{owner_password} && Crypt::SaltedHash->validate($room->{owner_password}, $pass)){
$role = 'owner'; $role = 'owner';
} }
@ -1510,11 +1514,6 @@ any '/api' => sub {
if ($ec && !$self->session($room->{name})->{etherpadSession}){ if ($ec && !$self->session($room->{name})->{etherpadSession}){
$self->create_etherpad_session($room->{name}); $self->create_etherpad_session($room->{name});
} }
$self->set_peer_role({
room => $room->{name},
peer_id => $self->session('peer_id'),
role => $role
});
$self->associate_key_to_room( $self->associate_key_to_room(
room => $room->{name}, room => $room->{name},
key => $self->session('key'), key => $self->session('key'),

Loading…
Cancel
Save