mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-12-24 12:38:58 +00:00
Automatically clean calls.
This commit is contained in:
parent
f99e16c23e
commit
bdea890aaa
@ -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
18
bin/clean_calls
Executable 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.";
|
@ -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
|
||||
*
|
||||
|
@ -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);
|
Loading…
Reference in New Issue
Block a user