Send JSON bool for room conf

master
Daniel Berteaud 10 years ago
parent 9e20d9208f
commit fb3f5fa05f
  1. 22
      public/js/vroom.js
  2. 37
      vroom.pl

@ -586,11 +586,11 @@ function initAdminRooms(){
}
adjustAddRemoveEmailButtons();
// Update config switches
$('#lockedSet').bootstrapSwitch('state', data.locked == 'yes');
$('#askForNameSet').bootstrapSwitch('state', data.ask_for_name == 'yes');
$('#joinPassSet').bootstrapSwitch('state', data.join_auth == 'yes');
$('#ownerPassSet').bootstrapSwitch('state', data.owner_auth == 'yes');
$('#persistentSet').bootstrapSwitch('state', data.persistent == 'yes');
$('#lockedSet').bootstrapSwitch('state', data.locked);
$('#askForNameSet').bootstrapSwitch('state', data.ask_for_name);
$('#joinPassSet').bootstrapSwitch('state', data.join_auth);
$('#ownerPassSet').bootstrapSwitch('state', data.owner_auth);
$('#persistentSet').bootstrapSwitch('state', data.persistent);
$('#maxMembers').val(data.max_members);
// Hide the password inputs
$('#joinPassFields,#ownerPassFields').hide();
@ -767,7 +767,7 @@ function initVroom(room) {
else{
// Hide owner reserved elements
$('.ownerEl').hide(500);
if (data.owner_auth == 'yes'){
if (data.owner_auth){
$('.unauthEl').show(500);
}
else{
@ -775,12 +775,12 @@ function initVroom(room) {
}
}
// Update config switches
$('#lockedSet').bootstrapSwitch('state', data.locked == 'yes');
$('#askForNameSet').bootstrapSwitch('state', data.ask_for_name == 'yes');
$('#joinPassSet').bootstrapSwitch('state', data.join_auth == 'yes');
$('#ownerPassSet').bootstrapSwitch('state', data.owner_auth == 'yes');
$('#lockedSet').bootstrapSwitch('state', data.locked);
$('#askForNameSet').bootstrapSwitch('state', data.ask_for_name);
$('#joinPassSet').bootstrapSwitch('state', data.join_auth);
$('#ownerPassSet').bootstrapSwitch('state', data.owner_auth);
if (ev === 'join'){
if (data.ask_for_name && data.ask_for_name === 'yes'){
if (data.ask_for_name){
$('#display-name-pre').slideDown();
}
else{

@ -964,6 +964,21 @@ helper get_turn_creds => sub {
}
};
# Format room config as a hash to be sent in JSON response
helper get_room_conf => sub {
my $self = shift;
my $room = shift;
return {
owner_auth => ($room->{owner_password}) ? Mojo::JSON::true : Mojo::JSON::false,
join_auth => ($room->{join_password}) ? Mojo::JSON::true : Mojo::JSON::false,
locked => ($room->{locked}) ? Mojo::JSON::true : Mojo::JSON::false,
ask_for_name => ($room->{ask_for_name}) ? Mojo::JSON::true : Mojo::JSON::false,
persistent => ($room->{persistent}) ? Mojo::JSON::true : Mojo::JSON::false,
max_members => $room->{max_members},
notif => $self->get_email_notifications($room->{name})
};
};
# Socket.IO handshake
get '/socket.io/:ver' => sub {
my $self = shift;
@ -1789,15 +1804,7 @@ any '/api' => sub {
# Return just room config
elsif ($req->{action} eq 'get_room_conf'){
return $self->render(
json => {
owner_auth => ($room->{owner_password}) ? 'yes' : 'no',
join_auth => ($room->{join_password}) ? 'yes' : 'no',
locked => ($room->{locked}) ? 'yes' : 'no',
ask_for_name => ($room->{ask_for_name}) ? 'yes' : 'no',
persistent => ($room->{persistent}) ? 'yes' : 'no',
max_members => $room->{max_members},
notif => $self->get_email_notifications($room->{name}),
}
json => $self->get_room_conf($room)
);
}
# Return your role and various info about the room
@ -1830,16 +1837,10 @@ any '/api' => sub {
);
}
}
my $conf = $self->get_room_conf($room);
$conf->{role} = $self->session($room->{name})->{role};
return $self->render(
json => {
role => $self->session($room->{name})->{role},
owner_auth => ($room->{owner_password}) ? 'yes' : 'no',
join_auth => ($room->{join_password}) ? 'yes' : 'no',
locked => ($room->{locked}) ? 'yes' : 'no',
ask_for_name => ($room->{ask_for_name}) ? 'yes' : 'no',
max_members => $room->{max_members},
notif => $self->get_email_notifications($room->{name}),
},
json => $conf
);
}
# Return the role of a peer

Loading…
Cancel
Save