From c8a17e7be849863f86ea9941d610355176b9320b Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Sun, 18 Jan 2015 20:02:23 +0100 Subject: [PATCH] Switch get_room_info to the new api handler --- lib/Vroom/Constants.pm | 5 +-- public/js/vroom.js | 11 +++++-- vroom.pl | 87 ++++++++++++++++++++++++-------------------------- 3 files changed, 52 insertions(+), 51 deletions(-) diff --git a/lib/Vroom/Constants.pm b/lib/Vroom/Constants.pm index 77d14d9..6b2b3d6 100644 --- a/lib/Vroom/Constants.pm +++ b/lib/Vroom/Constants.pm @@ -166,8 +166,9 @@ use constant API_ACTIONS => { set_owner_password => 1 }, participant => { - ping => 1, - authenticate => 1 + ping => 1, + authenticate => 1, + get_room_info => 1 } }; diff --git a/public/js/vroom.js b/public/js/vroom.js index 11a7b66..738b663 100644 --- a/public/js/vroom.js +++ b/public/js/vroom.js @@ -522,10 +522,15 @@ function initVroom(room) { // Get our role and other room settings from the server function getRoomInfo(){ $.ajax({ + url: rootUrl + 'api', data: { - action: 'getRoomInfo', - room: roomName, - id: peers.local.id + req: JSON.stringify({ + action: 'get_room_info', + param: { + room: roomName, + peer_id: peers.local.id + } + }) }, async: false, error: function(data){ diff --git a/vroom.pl b/vroom.pl index 536fcb7..26fd015 100755 --- a/vroom.pl +++ b/vroom.pl @@ -1424,6 +1424,47 @@ any '/api' => sub { } ); } + # Return your role and various info about the room + elsif ($req->{action} eq 'get_room_info'){ + my $peer_id = $req->{param}->{peer_id}; + if ($self->session($room->{name}) && $self->session($room->{name})->{role}){ + # If we just have been promoted to owner + if ($self->session($room)->{role} ne 'owner' && + $self->get_peer_role({room => $room->{name}, peer_id => $peer_id}) eq 'owner'){ + $self->session($room)->{role} = 'owner'; + $self->associate_key_to_room( + room => $room->{name}, + key => $self->session('key'), + role => 'owner' + ); + } + my $res = $self->set_peer_role({ + room => $room->{name}, + name => $self->session('name'), + peer_id => $peer_id, + role => $self->session($room->{name})->{role} + }); + if (!$res){ + return $self->render( + json => { + status => 'error', + msg => $self->l('ERROR_OCCURRED') + } + ); + } + } + 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', + notif => $self->get_notification($room->{name}), + status => 'success' + }, + ); + } }; # Catch all route: if nothing else match, it's the name of a room @@ -1563,52 +1604,6 @@ post '/*jsapi' => { jsapi => [qw(jsapi admin/jsapi)] } => sub { }, ); } - - # Return your role and various info about the room - elsif ($action eq 'getRoomInfo'){ - my $id = $self->param('id'); - my %emailNotif; - if ($self->session($room) && $self->session($room)->{role}){ - # If we just have been promoted to owner - if ($self->session($room)->{role} ne 'owner' && - $self->get_peer_role({room => $room, peer_id => $id}) eq 'owner'){ - $self->session($room)->{role} = 'owner'; - $self->associate_key_to_room( - room => $room, - key => $self->session('key'), - role => 'owner' - ); - } - my $res = $self->set_peer_role({ - room => $room, - name => $self->session('name'), - peer_id => $id, - role => $self->session($room)->{role} - }); - if (!$res){ - return $self->render( - json => { - status => 'error', - msg => $self->l('ERROR_OCCURRED') - } - ); - } - } - if ($self->session($room)->{role} eq 'owner'){ - my $i = 0; - } - return $self->render( - json => { - role => $self->session($room)->{role}, - owner_auth => ($data->{owner_password}) ? 'yes' : 'no', - join_auth => ($data->{join_password}) ? 'yes' : 'no', - locked => ($data->{locked}) ? 'yes' : 'no', - ask_for_name => ($data->{ask_for_name}) ? 'yes' : 'no', - notif => $self->get_notification($room), - status => 'success' - }, - ); - } # Return the role of a peer elsif ($action eq 'getPeerRole'){ my $id = $self->param('id');