Move ping action to the new API handler

master
Daniel Berteaud 10 years ago
parent 90c49fc6a1
commit 9d67d1afc0
  1. 4
      lib/Vroom/Constants.pm
  2. 13
      public/js/vroom.js
  3. 82
      vroom.pl

@ -162,7 +162,9 @@ use constant API_ACTIONS => {
lock_room => 1,
unlock_room => 1
},
participant => {}
participant => {
ping => 1
}
};
1;

@ -2277,17 +2277,22 @@ function initVroom(room) {
// Ping the room every minutes
// Used to detect inactive rooms
setInterval(function pingRoom(){
setInterval(function(){
$.ajax({
url: rootUrl + 'api',
data: {
action: 'ping',
room: roomName
req: JSON.stringify({
action: 'ping',
param: {
room: roomName
}
})
},
error: function(data) {
$.notify(locale.ERROR_OCCURRED, 'error');
},
success: function(data) {
if (data.status == 'success' && data.msg && data.msg != ''){
if (data.status === 'success' && data.msg && data.msg != ''){
$.notify(data.msg, {
className: 'info',
autoHide: false

@ -948,7 +948,7 @@ helper key_can_do_this => sub {
return 1;
}
# Else, deny
$self->app->log->debug("API Key " . $data->{key} . " cannot run action " . $data->{action} . " on room " . $data->{param}->{room});
$self->app->log->debug("API Key " . $data->{token} . " cannot run action " . $data->{action} . " on room " . $data->{param}->{room});
return 0;
};
@ -1293,6 +1293,40 @@ any '/api' => sub {
}
);
}
# Handle activity pings sent every minute by each participant
elsif ($req->{action} eq 'ping'){
$self->ping_room($room);
# Cleanup expired rooms every ~10 pings
if ((int (rand 100)) <= 10){
$self->purge_rooms;
$self->purge_invitations;
$self->purge_participants;
}
# Check if we got any invitation response to process
my $invitations = $self->get_invitation_list($self->session('name'));
my $msg = '';
foreach my $invit (keys %{$invitations}){
$msg .= sprintf($self->l('INVITE_REPONSE_FROM_s'), $invitations->{$invit}->{email}) . "\n" ;
if ($invitations->{$invit}->{response} && $invitations->{$invit}->{response} eq 'later'){
$msg .= $self->l('HE_WILL_TRY_TO_JOIN_LATER');
}
else{
$msg .= $self->l('HE_WONT_JOIN');
}
if ($invitations->{$invit}->{message} && $invitations->{$invit}->{message} ne ''){
$msg .= "\n" . $self->l('MESSAGE') . ":\n" . $invitations->{$invit}->{message} . "\n";
}
$msg .= "\n";
$self->mark_invitation_processed($invitations->{$invit}->{token});
}
return $self->render(
json => {
msg => $msg,
status => 'success'
}
);
}
};
# Catch all route: if nothing else match, it's the name of a room
@ -1433,52 +1467,6 @@ post '/*jsapi' => { jsapi => [qw(jsapi admin/jsapi)] } => sub {
);
}
# Handle activity pings sent every minute by each participant
elsif ($action eq 'ping'){
my $status = 'error';
my $msg = $self->l('ERROR_OCCURRED');
my $res = $self->ping_room($room);
# Cleanup expired rooms every ~10 pings
if ((int (rand 100)) <= 10){
$self->purge_rooms;
}
# And same for expired invitation links
if ((int (rand 100)) <= 10){
$self->purge_invitations;
}
# And also remove inactive participants
if ((int (rand 100)) <= 10){
$self->purge_participants;
}
if ($res){
$status = 'success';
$msg = '';
}
my $invitations = $self->get_invitation_list($self->session('name'));
$msg = '';
# Check if we have invitation's response, and if we do
# send them to the client
foreach my $invit (keys %{$invitations}){
$msg .= sprintf($self->l('INVITE_REPONSE_FROM_s'), $invitations->{$invit}->{email}) . "\n" ;
if ($invitations->{$invit}->{response} && $invitations->{$invit}->{response} eq 'later'){
$msg .= $self->l('HE_WILL_TRY_TO_JOIN_LATER');
}
else{
$msg .= $self->l('HE_WONT_JOIN');
}
if ($invitations->{$invit}->{message} && $invitations->{$invit}->{message} ne ''){
$msg .= "\n" . $self->l('MESSAGE') . ":\n" . $invitations->{$invit}->{message} . "\n";
}
$msg .= "\n";
$self->mark_invitation_processed($invitations->{$invit}->{token});
}
return $self->render(
json => {
msg => $msg,
status => $status
}
);
}
# Handle password (join and owner)
elsif ($action eq 'setPassword'){
my $pass = $self->param('password');

Loading…
Cancel
Save