From 2b262733b1f34778554c102cbf27f0ece11c0d5f Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Fri, 26 Jun 2015 15:09:28 +0200 Subject: [PATCH] Handle peer_id generation during Socket.IO handshake --- vroom.pl | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/vroom.pl b/vroom.pl index d135a30..901f8a7 100755 --- a/vroom.pl +++ b/vroom.pl @@ -999,8 +999,10 @@ helper get_room_conf => sub { # Socket.IO handshake get '/socket.io/:ver' => sub { my $self = shift; + my $sid = $self->get_random(256); + $self->session( peer_id => $sid ); my $handshake = Protocol::SocketIO::Handshake->new( - session_id => $self->session('peer_id'), + session_id => $sid, heartbeat_timeout => 20, close_timeout => 40, transports => [qw/websocket/] @@ -1050,6 +1052,11 @@ websocket '/socket.io/:ver/websocket/:id' => sub { $self->finish; 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 ? my $limit = $self->get_member_limit($room); 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 $reason; 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)){ $role = 'owner'; } @@ -1510,11 +1514,6 @@ any '/api' => sub { if ($ec && !$self->session($room->{name})->{etherpadSession}){ $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( room => $room->{name}, key => $self->session('key'),