Some changes in the way peer role is handled

master
Daniel Berteaud 10 years ago
parent a2c65ad26c
commit 1edd844272
  1. 52
      public/js/vroom.js
  2. 90
      vroom.pl

@ -724,10 +724,9 @@ function initVroom(room) {
$.ajax({
data: {
req: JSON.stringify({
action: 'get_room_info',
action: 'get_room_conf',
param: {
room: roomName,
peer_id: peers.local.id
}
})
},
@ -735,16 +734,7 @@ function initVroom(room) {
showApiError(data);
},
success: function(data){
// Notify others if our role changed
if (data.role != peers.local.role){
webrtc.sendToAll('role_change', {});
}
peers.local.role = data.role;
roomInfo = data;
// Enable owner reserved menu
if (data.role == 'owner'){
$('.unauthEl').hide(500);
$('.ownerEl').show(500);
// Reset the list of email displayed, so first remove evry input field but the last one
// We keep it so we can clone it again
$('.email-list').find('.email-entry:not(:last)').remove();
@ -759,18 +749,6 @@ function initVroom(room) {
$('.email-list').find('.email-entry:first').find('input:first').val('');
}
adjustAddRemoveEmailButtons();
}
// We're are not owner of the room
else{
// Hide owner reserved elements
$('.ownerEl').hide(500);
if (data.owner_auth){
$('.unauthEl').show(500);
}
else{
$('.unauthEl').hide(500);
}
}
// Update config switches
$('#lockedSet').bootstrapSwitch('state', data.locked);
$('#askForNameSet').bootstrapSwitch('state', data.ask_for_name);
@ -804,7 +782,23 @@ function initVroom(room) {
showApiError(data);
},
success: function(data){
if (peers[id]){
if (id === peers.local.id){
if (data.role != peers.local.role){
webrtc.sendToAll('role_change', {});
}
peers.local.role = data.role;
if (data.role == 'owner'){
$('.unauthEl').hide(500);
$('.ownerEl').show(500);
}
else {
if (roomInfo.owner_auth){
$('.unauthEl').show(500);
}
$('.ownerEl').hide(500);
}
}
else if (peers[id]){
peers[id].role = data.role;
if (data.role == 'owner'){
// If this peer is a owner, we add the mark on its preview
@ -1320,7 +1314,7 @@ function initVroom(room) {
}
if (data.payload.peer && data.payload.peer == peers.local.id && peers.local.role != 'owner'){
var who = (peers[data.id].hasName) ? peers[data.id].displayName : localize('A_ROOM_ADMIN');
getRoomInfo();
getPeerRole(peers.local.id);
if (peers.local.role == 'owner'){
$.notify(sprintf(localize('s_IS_PROMOTING_YOU'), who), 'success');
}
@ -1523,6 +1517,7 @@ function initVroom(room) {
});
}
}, 10000);
}
// Ping the room every minutes
// Used to detect inactive rooms
setInterval(function(){
@ -1548,7 +1543,6 @@ function initVroom(room) {
}
});
}, 60000);
}
// Notify the server a new participant has joined (ourself)
// If we were prompted for our display name before joining
// we send it. Not that I like sending this kind of data to the server
@ -1559,7 +1553,8 @@ function initVroom(room) {
action: 'join',
param: {
room: roomName,
name: (peers.local.hasName) ? peers.local.displayName : ''
name: (peers.local.hasName) ? peers.local.displayName : '',
peer_id: peers.local.id
}
})
},
@ -1572,6 +1567,7 @@ function initVroom(room) {
}
$('#videoLocalContainer').show(200);
$('#timeCounterXs,#timeCounter').tinyTimer({ from: new Date });
getPeerRole(peers.local.id);
setTimeout(function(){
$('#connecting').modal('hide');
}, 200);
@ -1884,7 +1880,7 @@ function initVroom(room) {
success: function(data){
$('#authPass').val('');
$('#ownerAuthModal').modal('hide');
getRoomInfo();
getPeerRole(peers.local.id);
$('#joinPassFields,#ownerPassFields').hide();
$.notify(data.msg, 'success');
}

@ -838,6 +838,35 @@ helper make_key_admin => sub {
return 1;
};
# Get the role of an API key for a room
helper get_key_role => sub {
my $self = shift;
my ($token,$room) = @_;
my $key = $self->get_key_by_token($token);
if (!$key){
$self->app->log->debug("Invalid API key");
return 0;
}
# An admin key is considered owner of any room
if ($key->{admin}){
return 'owner';
}
# Now, lookup the DB the role of this key for this room
my $sth = eval {
$self->db->prepare('SELECT `role`
FROM `room_keys`
LEFT JOIN `rooms` ON `room_keys`.`room_id`=`rooms`.`id`
WHERE `room_keys`.`key_id`=?
AND `rooms`.`name`=?
LIMIT 1');
};
$sth->execute($key->{id},$room);
$sth->bind_columns(\$key->{role});
$sth->fetch;
$self->app->log->debug("Key $token has role:" . $key->{role} . " in room $room");
return $key->{role};
};
# Check if a key can perform an action against a room
helper key_can_do_this => sub {
my $self = shift;
@ -866,19 +895,8 @@ helper key_can_do_this => sub {
$self->app->log->debug("Invalid room ID");
return 0;
}
$key->{role} = $self->get_key_role($data->{token}, $data->{param}->{room});
# Now, lookup the DB the role of this key for this room
my $sth = eval {
$self->db->prepare('SELECT `role`
FROM `room_keys`
LEFT JOIN `rooms` ON `room_keys`.`room_id`=`rooms`.`id`
WHERE `room_keys`.`key_id`=?
AND `rooms`.`name`=?
LIMIT 1');
};
$sth->execute($key->{id},$data->{param}->{room});
$sth->bind_columns(\$key->{role});
$sth->fetch;
$self->app->log->debug("Key role: " . $key->{role} . " and action: " . $data->{action});
# If this key has owner privileges on this room, allow both owner and partitipant actions
if ($key->{role} eq 'owner' && ($actions->{owner}->{$data->{action}} || $actions->{participant}->{$data->{action}})){
@ -1823,10 +1841,19 @@ any '/api' => sub {
json => $self->get_room_conf($room)
);
}
# Return your role and various info about the room
elsif ($req->{action} eq 'get_room_info'){
# Return the role of a peer
elsif ($req->{action} eq 'get_peer_role'){
my $peer_id = $req->{param}->{peer_id};
if ($self->session($room->{name}) && $self->session($room->{name})->{role}){
if (!$peer_id){
return $self->render(
json => {
msg => $self->l('ERROR_PEER_ID_MISSING'),
err => 'ERROR_PEER_ID_MISSING'
},
status => 400
);
}
if ($self->session('peer_id') && $self->session('peer_id') eq $peer_id){
# If we just have been promoted to owner
if ($self->session($room->{name})->{role} ne 'owner' &&
$self->get_peer_role({room => $room->{name}, peer_id => $peer_id}) &&
@ -1837,7 +1864,6 @@ any '/api' => sub {
key => $self->session('key'),
role => 'owner'
);
}
my $res = $self->set_peer_role({
room => $room->{name},
peer_id => $peer_id,
@ -1853,23 +1879,6 @@ any '/api' => sub {
);
}
}
my $conf = $self->get_room_conf($room);
$conf->{role} = $self->session($room->{name})->{role};
return $self->render(
json => $conf
);
}
# Return the role of a peer
elsif ($req->{action} eq 'get_peer_role'){
my $peer_id = $req->{param}->{peer_id};
if (!$peer_id){
return $self->render(
json => {
msg => $self->l('ERROR_PEER_ID_MISSING'),
err => 'ERROR_PEER_ID_MISSING'
},
status => 400
);
}
my $role = $self->get_peer_role({room => $room->{name}, peer_id => $peer_id});
if (!$role){
@ -1890,6 +1899,21 @@ any '/api' => sub {
# Notify the backend when we join a room
elsif ($req->{action} eq 'join'){
my $name = $req->{param}->{name} || '';
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});
# Send notifications
my $recipients = $self->get_email_notifications($room->{name});

Loading…
Cancel
Save