From fb3f5fa05fdb2ef290368a7d9d2eb18755400ad3 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Wed, 18 Mar 2015 10:45:40 +0100 Subject: [PATCH] Send JSON bool for room conf --- public/js/vroom.js | 22 +++++++++++----------- vroom.pl | 37 +++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/public/js/vroom.js b/public/js/vroom.js index ed25dce..779c5fb 100644 --- a/public/js/vroom.js +++ b/public/js/vroom.js @@ -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{ diff --git a/vroom.pl b/vroom.pl index 29cba6c..b203b3d 100755 --- a/vroom.pl +++ b/vroom.pl @@ -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