|
|
@ -341,7 +341,7 @@ helper set_peer_role => sub { |
|
|
|
} |
|
|
|
} |
|
|
|
$peers->{$data->{peer_id}}->{role} = $data->{role}; |
|
|
|
$peers->{$data->{peer_id}}->{role} = $data->{role}; |
|
|
|
$self->app->log->info("Peer " . $data->{peer_id} . " has now the " . |
|
|
|
$self->app->log->info("Peer " . $data->{peer_id} . " has now the " . |
|
|
|
$data->{role} . " role in room " . $data->{room}); |
|
|
|
$data->{role} . " role"); |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -355,10 +355,9 @@ helper get_peer_role => sub { |
|
|
|
# Promote a peer to owner |
|
|
|
# Promote a peer to owner |
|
|
|
helper promote_peer => sub { |
|
|
|
helper promote_peer => sub { |
|
|
|
my $self = shift; |
|
|
|
my $self = shift; |
|
|
|
my ($data) = @_; |
|
|
|
my ($peer_id) = @_; |
|
|
|
return $self->set_peer_role({ |
|
|
|
return $self->set_peer_role({ |
|
|
|
peer_id => $data->{peer_id}, |
|
|
|
peer_id => $peer_id, |
|
|
|
room => $data->{room}, |
|
|
|
|
|
|
|
role => 'owner' |
|
|
|
role => 'owner' |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
@ -1020,6 +1019,8 @@ websocket '/socket.io/:ver/websocket/:id' => sub { |
|
|
|
return $self->send('Bad session'); |
|
|
|
return $self->send('Bad session'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my $key = $self->session('key'); |
|
|
|
|
|
|
|
|
|
|
|
$self->app->log->debug("Adding new peer $id to the global peer hash"); |
|
|
|
$self->app->log->debug("Adding new peer $id to the global peer hash"); |
|
|
|
# We create the peer in the global hash |
|
|
|
# We create the peer in the global hash |
|
|
|
$peers->{$id}->{socket} = $self->tx; |
|
|
|
$peers->{$id}->{socket} = $self->tx; |
|
|
@ -1041,22 +1042,18 @@ websocket '/socket.io/:ver/websocket/:id' => sub { |
|
|
|
# Here's a client joining a room |
|
|
|
# Here's a client joining a room |
|
|
|
if ($msg->{data}->{name} eq 'join'){ |
|
|
|
if ($msg->{data}->{name} eq 'join'){ |
|
|
|
my $room = $msg->{data}->{args}[0]; |
|
|
|
my $room = $msg->{data}->{args}[0]; |
|
|
|
|
|
|
|
my $role = $self->get_key_role($key, $room); |
|
|
|
|
|
|
|
$peers->{$id}->{role} = $role; |
|
|
|
# Is this peer allowed to join the room ? |
|
|
|
# Is this peer allowed to join the room ? |
|
|
|
if (!$self->get_room_by_name($room) || |
|
|
|
if (!$self->get_room_by_name($room) || |
|
|
|
!$self->session($room) || |
|
|
|
!$role || |
|
|
|
!$self->session($room)->{role} || |
|
|
|
$role !~ m/^owner|participant$/){ |
|
|
|
$self->session($room)->{role} !~ m/^owner|participant$/){ |
|
|
|
|
|
|
|
$self->app->log->debug("Failed to connect to the signaling channel, " . $self->get_name . |
|
|
|
$self->app->log->debug("Failed to connect to the signaling channel, " . $self->get_name . |
|
|
|
" (session ID " . $self->session('id') . ") has no role in room $room"); |
|
|
|
" (session ID " . $self->session('id') . ") has no role in room $room"); |
|
|
|
$self->send( Protocol::SocketIO::Message->new( type => 'disconnect' ) ); |
|
|
|
$self->send( Protocol::SocketIO::Message->new( type => 'disconnect' ) ); |
|
|
|
$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){ |
|
|
@ -1853,11 +1850,6 @@ any '/api' => sub { |
|
|
|
key => $self->session('key'), |
|
|
|
key => $self->session('key'), |
|
|
|
role => 'owner' |
|
|
|
role => 'owner' |
|
|
|
); |
|
|
|
); |
|
|
|
my $res = $self->set_peer_role({ |
|
|
|
|
|
|
|
room => $room->{name}, |
|
|
|
|
|
|
|
peer_id => $peer_id, |
|
|
|
|
|
|
|
role => $self->session($room->{name})->{role} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
if (!$res){ |
|
|
|
if (!$res){ |
|
|
|
return $self->render( |
|
|
|
return $self->render( |
|
|
|
json => { |
|
|
|
json => { |
|
|
@ -1889,20 +1881,6 @@ any '/api' => sub { |
|
|
|
elsif ($req->{action} eq 'join'){ |
|
|
|
elsif ($req->{action} eq 'join'){ |
|
|
|
my $name = $req->{param}->{name} || ''; |
|
|
|
my $name = $req->{param}->{name} || ''; |
|
|
|
my $peer_id = $req->{param}->{peer_id}; |
|
|
|
my $peer_id = $req->{param}->{peer_id}; |
|
|
|
my $res = $self->set_peer_role({ |
|
|
|
|
|
|
|
room => $room->{name}, |
|
|
|
|
|
|
|
peer_id => $peer_id, |
|
|
|
|
|
|
|
role => $self->session($room->{name})->{role} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
if (!$res){ |
|
|
|
|
|
|
|
return $self->render( |
|
|
|
|
|
|
|
json => { |
|
|
|
|
|
|
|
msg => $self->l('ERROR_OCCURRED'), |
|
|
|
|
|
|
|
err => 'ERROR_OCCURRED' |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
status => 503 |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
my $subj = sprintf($self->l('s_JOINED_ROOM_s'), ($name eq '') ? $self->l('SOMEONE') : $name, $room->{name}); |
|
|
|
my $subj = sprintf($self->l('s_JOINED_ROOM_s'), ($name eq '') ? $self->l('SOMEONE') : $name, $room->{name}); |
|
|
|
# Send notifications |
|
|
|
# Send notifications |
|
|
|
my $recipients = $self->get_email_notifications($room->{name}); |
|
|
|
my $recipients = $self->get_email_notifications($room->{name}); |
|
|
@ -1933,7 +1911,7 @@ any '/api' => sub { |
|
|
|
status => 400 |
|
|
|
status => 400 |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
elsif ($self->promote_peer({room => $room->{name}, peer_id => $peer_id})){ |
|
|
|
elsif ($self->promote_peer($peer_id)){ |
|
|
|
return $self->render( |
|
|
|
return $self->render( |
|
|
|
json => { |
|
|
|
json => { |
|
|
|
msg => $self->l('PEER_PROMOTED') |
|
|
|
msg => $self->l('PEER_PROMOTED') |
|
|
|