From 2e4d09ad0ecf4eb6d458abf41c5a7109e954a9fb Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Sun, 18 Jan 2015 21:19:16 +0100 Subject: [PATCH] Switch set_ask_for_name to the new api handler --- lib/Vroom/Constants.pm | 3 ++- public/js/vroom.js | 17 +++++++++++------ vroom.pl | 39 +++++++++++++++++++-------------------- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/lib/Vroom/Constants.pm b/lib/Vroom/Constants.pm index 970d235..d002ad4 100644 --- a/lib/Vroom/Constants.pm +++ b/lib/Vroom/Constants.pm @@ -163,7 +163,8 @@ use constant API_ACTIONS => { lock_room => 1, unlock_room => 1, set_join_password => 1, - set_owner_password => 1 + set_owner_password => 1, + set_ask_for_name => 1 }, participant => { ping => 1, diff --git a/public/js/vroom.js b/public/js/vroom.js index 67665ea..3a058d6 100644 --- a/public/js/vroom.js +++ b/public/js/vroom.js @@ -1718,12 +1718,17 @@ function initVroom(room) { // Force participants to set a name $('#askForNameButton').change(function() { - var type = ($(this).is(":checked")) ? 'set':'unset'; + var set = ($(this).is(":checked")) ? 'on':'off'; $.ajax({ + url: rootUrl + 'api', data: { - action: 'askForName', - type: type, - room: roomName + req: JSON.stringify({ + action: 'set_ask_for_name', + param: { + set: set, + room: roomName + } + }) }, error: function(data) { $.notify(locale.ERROR_OCCURRED, 'error'); @@ -1731,13 +1736,13 @@ function initVroom(room) { success: function(data) { if (data.status == 'success'){ $.notify(data.msg, 'info'); - if (type === 'set'){ + if (set === 'on'){ $('#askForNameLabel').addClass('btn-danger active'); } else{ $('#askForNameLabel').removeClass('btn-danger active'); } - webrtc.sendToAll('ask_for_name', {action: type}); + webrtc.sendToAll('ask_for_name', {action: set}); } else{ $.notify(data.msg, 'error'); diff --git a/vroom.pl b/vroom.pl index 95db0f9..64049a2 100755 --- a/vroom.pl +++ b/vroom.pl @@ -1390,6 +1390,25 @@ any '/api' => sub { } ); } + # Set/unset askForName + elsif ($req->{action} eq 'set_ask_for_name'){ + my $set = $req->{param}->{set}; + $room->{ask_for_name} = ($set eq 'on') ? 1 : 0; + if ($self->modify_room($room)){ + return $self->render( + json => { + status => 'success', + msg => $self->l(($set eq 'on') ? 'FORCE_DISPLAY_NAME' : 'NAME_WONT_BE_ASKED') + } + ); + } + return $self->render( + json => { + msg => $self->l('ERROR_OCCURRED'), + status => 'error' + } + ); + } elsif ($req->{action} eq 'authenticate'){ my $pass = $req->{param}->{'password'}; # Auth succeed ? lets promote him to owner of the room @@ -1643,26 +1662,6 @@ post '/*jsapi' => { jsapi => [qw(jsapi admin/jsapi)] } => sub { } ); } - # Set/unset askForName - elsif ($action eq 'askForName'){ - my $type = $self->param('type'); - my $status = 'error'; - my $msg = $self->l('ERROR_OCCURRED'); - if ($prefix ne 'admin' && $self->session($room)->{role} ne 'owner'){ - $msg = $self->l('NOT_ALLOWED'); - } - $data->{ask_for_name} = ($type eq 'set') ? 1 : 0; - if ($self->modify_room($data)){ - $status = 'success'; - $msg = $self->l(($type eq 'set') ? 'FORCE_DISPLAY_NAME' : 'NAME_WONT_BE_ASKED'); - } - return $self->render( - json => { - msg => $msg, - status => $status - } - ); - } # New participant joined the room elsif ($action eq 'join'){ my $name = $self->param('name') || '';