Some code refactoring

Reduce duplicate code
Also add some more checks that event received from the signaling channel are sent by owners (ignore them if it's not the case)
master
Daniel Berteaud 11 years ago
parent 36d202585c
commit 950a84fbbe
  1. 72
      public/js/vroom.js

@ -804,78 +804,71 @@ function initVroom(room) {
// A new notified email has been added // A new notified email has been added
webrtc.on('notif_change', function(data){ webrtc.on('notif_change', function(data){
if (peers.local.role != 'owner' || data.roomType == 'screen'){ if (peers.local.role != 'owner' || data.roomType == 'screen' || peers[data.id].role != 'owner'){
return; return;
} }
$('#emailNotificationList > li').remove(); $('#emailNotificationList > li').remove();
getRoomInfo(); getRoomInfo();
}); });
// askForName set // askForName set/unset
webrtc.on('ask_for_name_on', function(data){ webrtc.on('ask_for_name', function(data){
if (peers.local.role != 'owner'){ if (peers.local.role != 'owner' || peers[data.id].role != 'owner'){
return; return;
} }
getRoomInfo(); if (data.payload.action == 'set'){
roomInfo.ask_for_name = 'yes';
$('#askForNameLabel').addClass('btn-danger active'); $('#askForNameLabel').addClass('btn-danger active');
$('#askForNameButton').prop('checked', true); $('#askForNameButton').prop('checked', true);
});
webrtc.on('ask_for_name_off', function(data){
if (peers.local.role != 'owner'){
return;
} }
getRoomInfo(); else{
roomInfo.ask_for_name = 'no';
$('#askForNameLabel').removeClass('btn-danger active'); $('#askForNameLabel').removeClass('btn-danger active');
$('#askForNameButton').prop('checked', false); $('#askForNameButton').prop('checked', false);
}
}); });
// A few notif on password set/unset or lock/unlock // A few notif on password set/unset or lock/unlock
webrtc.on('room_locked', function(data){ webrtc.on('room_lock', function(data){
if (data.roomType == 'screen'){ if (data.roomType == 'screen' || peers[data.id].role != 'owner'){
return; return;
} }
if (data.payload.action == 'lock'){
roomInfo.locked = 'yes';
$('#lockLabel').addClass('btn-danger active'); $('#lockLabel').addClass('btn-danger active');
$('#lockButton').prop('checked', true); $('#lockButton').prop('checked', true);
$.notify(sprintf(locale.ROOM_LOCKED_BY_s, stringEscape(peers[data.id].displayName)), 'info'); $.notify(sprintf(locale.ROOM_LOCKED_BY_s, stringEscape(peers[data.id].displayName)), 'info');
});
webrtc.on('room_unlocked', function(data){
if (data.roomType == 'screen'){
return;
} }
else{
roomInfo.locked = 'no';
$('#lockLabel').removeClass('btn-danger active'); $('#lockLabel').removeClass('btn-danger active');
$('#lockButton').prop('checked', false); $('#lockButton').prop('checked', false);
$.notify(sprintf(locale.ROOM_UNLOCKED_BY_s, stringEscape(peers[data.id].displayName)), 'info'); $.notify(sprintf(locale.ROOM_UNLOCKED_BY_s, stringEscape(peers[data.id].displayName)), 'info');
}
}); });
webrtc.on('password_protect_on', function(data){ webrtc.on('password_protect', function(data){
if (data.roomType == 'screen'){ if (data.roomType == 'screen' || peers[data.id].role != 'owner'){
return; return;
} }
if (data.payload.action == 'set'){
$.notify(sprintf(locale.PASSWORD_PROTECT_ON_BY_s, stringEscape(peers[data.id].displayName)), 'info'); $.notify(sprintf(locale.PASSWORD_PROTECT_ON_BY_s, stringEscape(peers[data.id].displayName)), 'info');
});
webrtc.on('password_protect_off', function(data){
if (data.roomType == 'screen'){
return;
} }
else{
$.notify(sprintf(locale.PASSWORD_PROTECT_OFF_BY_s, stringEscape(peers[data.id].displayName)), 'info'); $.notify(sprintf(locale.PASSWORD_PROTECT_OFF_BY_s, stringEscape(peers[data.id].displayName)), 'info');
}
}); });
webrtc.on('owner_password_changed', function(data){ webrtc.on('owner_password', function(data){
if (data.roomType == 'screen'){ if (data.roomType == 'screen' || peers[data.id].role != 'owner'){
return; return;
} }
if (peers.local.role == 'owner'){ if (peers.local.role == 'owner'){
if (data.payload.action == 'set'){
$.notify(sprintf(locale.OWNER_PASSWORD_CHANGED_BY_s, stringEscape(peers[data.id].displayName)), 'warn'); $.notify(sprintf(locale.OWNER_PASSWORD_CHANGED_BY_s, stringEscape(peers[data.id].displayName)), 'warn');
} }
else{ else{
getRoomInfo();
}
});
webrtc.on('owner_password_removed', function(data){
if (data.roomType == 'screen'){
return;
}
if (peers.local.role == 'owner'){
$.notify(sprintf(locale.OWNER_PASSWORD_REMOVED_BY_s, stringEscape(peers[data.id].displayName)), 'warn'); $.notify(sprintf(locale.OWNER_PASSWORD_REMOVED_BY_s, stringEscape(peers[data.id].displayName)), 'warn');
} }
}
else{ else{
getRoomInfo(); getRoomInfo();
} }
@ -1091,12 +1084,12 @@ function initVroom(room) {
$.notify(data.msg, 'info'); $.notify(data.msg, 'info');
if (action === 'lock'){ if (action === 'lock'){
$('#lockLabel').addClass('btn-danger active'); $('#lockLabel').addClass('btn-danger active');
webrtc.sendToAll('room_locked', {});
} }
else{ else{
on_off = 'off';
$('#lockLabel').removeClass('btn-danger active'); $('#lockLabel').removeClass('btn-danger active');
webrtc.sendToAll('room_unlocked', {});
} }
webrtc.sendToAll('room_lock', {action: action});
} }
else{ else{
$.notify(data.msg, 'error'); $.notify(data.msg, 'error');
@ -1123,12 +1116,11 @@ function initVroom(room) {
$.notify(data.msg, 'info'); $.notify(data.msg, 'info');
if (type === 'set'){ if (type === 'set'){
$('#askForNameLabel').addClass('btn-danger active'); $('#askForNameLabel').addClass('btn-danger active');
webrtc.sendToAll('ask_for_name_on', {});
} }
else{ else{
$('#askForNameLabel').removeClass('btn-danger active'); $('#askForNameLabel').removeClass('btn-danger active');
webrtc.sendToAll('ask_for_name_off', {});
} }
webrtc.sendToAll('ask_for_name', {action: type});
} }
else{ else{
$.notify(data.msg, 'error'); $.notify(data.msg, 'error');
@ -1275,7 +1267,7 @@ function initVroom(room) {
$('#joinPass').val(''); $('#joinPass').val('');
if (data.status == 'success'){ if (data.status == 'success'){
$.notify(data.msg, 'success'); $.notify(data.msg, 'success');
webrtc.sendToAll('password_protect_on', {}); webrtc.sendToAll('password_protect', {action: 'set'});
} }
else{ else{
$.notify(data.msg, 'error'); $.notify(data.msg, 'error');
@ -1299,7 +1291,7 @@ function initVroom(room) {
$('#joinPass').val(''); $('#joinPass').val('');
if (data.status == 'success'){ if (data.status == 'success'){
$.notify(data.msg, 'success'); $.notify(data.msg, 'success');
webrtc.sendToAll('password_protect_off', {}); webrtc.sendToAll('password_protect', {action: 'unset'});
} }
else{ else{
$.notify(data.msg, 'error'); $.notify(data.msg, 'error');
@ -1337,7 +1329,7 @@ function initVroom(room) {
$('#ownerPass').val(''); $('#ownerPass').val('');
if (data.status == 'success'){ if (data.status == 'success'){
$.notify(data.msg, 'success'); $.notify(data.msg, 'success');
webrtc.sendToAll('owner_password_changed', {}); webrtc.sendToAll('owner_password', {action: 'set'});
} }
else{ else{
$.notify(data.msg, 'error'); $.notify(data.msg, 'error');
@ -1361,7 +1353,7 @@ function initVroom(room) {
$('#ownerPass').val(''); $('#ownerPass').val('');
if (data.status == 'success'){ if (data.status == 'success'){
$.notify(data.msg, 'success'); $.notify(data.msg, 'success');
webrtc.sendToAll('owner_password_removed', {}); webrtc.sendToAll('owner_password', {action: 'remove'});
} }
else{ else{
$.notify(data.msg, 'error'); $.notify(data.msg, 'error');

Loading…
Cancel
Save