Automatically clean calls.

This commit is contained in:
Pierre HUBERT 2019-01-26 08:40:29 +01:00
parent f99e16c23e
commit bdea890aaa
4 changed files with 73 additions and 2 deletions

View File

@ -5,7 +5,11 @@ This project is the main Comunic RestAPI. It assures data backend support.
(c) Pierre HUBERT since 2017
# Crons required for Comunic
Currently, this server does not make use of crons.
## Calls cron
There is a cron to automatically cleanup old conversation. Ideally this cron should be executed every 30 seconds. The file to execute is `bin/clean_calls`
# Use calls in Comunic
To use calls in Comunic, you need a WebRTCSignalExchangerServer, a small signal exchanging server written using NodeJS. You also need to modify your configuration file located at `config/overwrite.php` by copying and pasting commented configuration located at `config/calls.php` and make it fit your needs.

18
bin/clean_calls Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env php
############################
# ComunicAPI calls cleaner #
# #
# @author Pierre HUBERT #
############################
Automatically remove old calls
<?php
require __DIR__."/../init.php";
if(!components()->calls->cleanCalls())
echo "Could not clean calls!";
echo "Calls successfully cleaned.";

View File

@ -304,6 +304,47 @@ class CallsComponents {
return true;
}
/**
* Delete all old call
*
* @return bool TRUE for a success / FALSE else
*/
public function cleanCalls() : bool {
//Compute timeout time
$old_time = time() - cs()->config->get("calls_expiration");
//Get the list of old calls
$calls = db()->select(
self::CALLS_LIST_TABLE,
"WHERE last_active < ?",
array($old_time),
array("id")
);
//Process each result
foreach($calls as $call){
//Delete all the members of the call
db()->deleteEntry(
self::CALLS_MEMBERS_TABLE,
"call_id = ?",
array($call["id"])
);
}
//Delete calls entries
db()->deleteEntry(
self::CALLS_LIST_TABLE,
"last_active < ?",
array($old_time)
);
//Success
return true;
}
/**
* Turn a database entry into a CallInformation object
*

View File

@ -26,4 +26,12 @@ $config->set("calls", array(
"turn_username" => "anonymous",
"turn_password" => "anonymous"
));
*/
*/
/**
* Calls expiration time
*
* The amount of time of inactivity for what the call get
* automatically deleted
*/
$config->set("calls_expiration", 30);