Switch get_room_info to the new api handler

master
Daniel Berteaud 10 years ago
parent 0a6e2d4f9b
commit c8a17e7be8
  1. 3
      lib/Vroom/Constants.pm
  2. 9
      public/js/vroom.js
  3. 87
      vroom.pl

@ -167,7 +167,8 @@ use constant API_ACTIONS => {
}, },
participant => { participant => {
ping => 1, ping => 1,
authenticate => 1 authenticate => 1,
get_room_info => 1
} }
}; };

@ -522,10 +522,15 @@ function initVroom(room) {
// Get our role and other room settings from the server // Get our role and other room settings from the server
function getRoomInfo(){ function getRoomInfo(){
$.ajax({ $.ajax({
url: rootUrl + 'api',
data: { data: {
action: 'getRoomInfo', req: JSON.stringify({
action: 'get_room_info',
param: {
room: roomName, room: roomName,
id: peers.local.id peer_id: peers.local.id
}
})
}, },
async: false, async: false,
error: function(data){ error: function(data){

@ -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 # 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 # Return the role of a peer
elsif ($action eq 'getPeerRole'){ elsif ($action eq 'getPeerRole'){
my $id = $self->param('id'); my $id = $self->param('id');

Loading…
Cancel
Save