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(); adjustAddRemoveEmailButtons();
// Update config switches // Update config switches
$('#lockedSet').bootstrapSwitch('state', data.locked == 'yes'); $('#lockedSet').bootstrapSwitch('state', data.locked);
$('#askForNameSet').bootstrapSwitch('state', data.ask_for_name == 'yes'); $('#askForNameSet').bootstrapSwitch('state', data.ask_for_name);
$('#joinPassSet').bootstrapSwitch('state', data.join_auth == 'yes'); $('#joinPassSet').bootstrapSwitch('state', data.join_auth);
$('#ownerPassSet').bootstrapSwitch('state', data.owner_auth == 'yes'); $('#ownerPassSet').bootstrapSwitch('state', data.owner_auth);
$('#persistentSet').bootstrapSwitch('state', data.persistent == 'yes'); $('#persistentSet').bootstrapSwitch('state', data.persistent);
$('#maxMembers').val(data.max_members); $('#maxMembers').val(data.max_members);
// Hide the password inputs // Hide the password inputs
$('#joinPassFields,#ownerPassFields').hide(); $('#joinPassFields,#ownerPassFields').hide();
@ -767,7 +767,7 @@ function initVroom(room) {
else{ else{
// Hide owner reserved elements // Hide owner reserved elements
$('.ownerEl').hide(500); $('.ownerEl').hide(500);
if (data.owner_auth == 'yes'){ if (data.owner_auth){
$('.unauthEl').show(500); $('.unauthEl').show(500);
} }
else{ else{
@ -775,12 +775,12 @@ function initVroom(room) {
} }
} }
// Update config switches // Update config switches
$('#lockedSet').bootstrapSwitch('state', data.locked == 'yes'); $('#lockedSet').bootstrapSwitch('state', data.locked);
$('#askForNameSet').bootstrapSwitch('state', data.ask_for_name == 'yes'); $('#askForNameSet').bootstrapSwitch('state', data.ask_for_name);
$('#joinPassSet').bootstrapSwitch('state', data.join_auth == 'yes'); $('#joinPassSet').bootstrapSwitch('state', data.join_auth);
$('#ownerPassSet').bootstrapSwitch('state', data.owner_auth == 'yes'); $('#ownerPassSet').bootstrapSwitch('state', data.owner_auth);
if (ev === 'join'){ if (ev === 'join'){
if (data.ask_for_name && data.ask_for_name === 'yes'){ if (data.ask_for_name){
$('#display-name-pre').slideDown(); $('#display-name-pre').slideDown();
} }
else{ 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 # Socket.IO handshake
get '/socket.io/:ver' => sub { get '/socket.io/:ver' => sub {
my $self = shift; my $self = shift;
@ -1789,15 +1804,7 @@ any '/api' => sub {
# Return just room config # Return just room config
elsif ($req->{action} eq 'get_room_conf'){ elsif ($req->{action} eq 'get_room_conf'){
return $self->render( return $self->render(
json => { json => $self->get_room_conf($room)
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}),
}
); );
} }
# Return your role and various info about the 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( return $self->render(
json => { json => $conf
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}),
},
); );
} }
# Return the role of a peer # Return the role of a peer

Loading…
Cancel
Save