Reset in call flag when a user timed out

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2018-03-09 15:44:27 +01:00
Родитель c563081393
Коммит b88394f265
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 7076EA9751AACDDA
4 изменённых файлов: 94 добавлений и 15 удалений

Просмотреть файл

@ -17,7 +17,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m
]]></description>
<version>3.99.0</version>
<version>3.99.2</version>
<licence>agpl</licence>
<author>Daniel Calviño Sánchez</author>
@ -50,6 +50,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m
<background-jobs>
<job>OCA\Spreed\BackgroundJob\ExpireSignalingMessage</job>
<job>OCA\Spreed\BackgroundJob\RemoveEmptyRooms</job>
<job>OCA\Spreed\BackgroundJob\ResetInCallFlags</job>
</background-jobs>
<settings>

Просмотреть файл

@ -1,6 +1,6 @@
<?php
/**
* @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
* @copyright Copyright (c) 2018 Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
@ -39,6 +39,8 @@ class RemoveEmptyRooms extends TimedJob {
/** @var ILogger */
protected $logger;
protected $numDeletedRooms = 0;
public function __construct(Manager $manager, ILogger $logger) {
// Every 5 minutes
$this->setInterval(60 * 5);
@ -48,22 +50,23 @@ class RemoveEmptyRooms extends TimedJob {
}
protected function run($argument) {
$numDeletedRooms = 0;
$this->manager->forAllRooms(function(Room $room) use (&$numDeletedRooms) {
if ($room->getType() === Room::ONE_TO_ONE_CALL && $room->getNumberOfParticipants(false) <= 1) {
$room->deleteRoom();
$numDeletedRooms++;
} else if ($room->getNumberOfParticipants(false) === 0) {
$room->deleteRoom();
$numDeletedRooms++;
}
});
$this->manager->forAllRooms([$this, 'callback']);
if ($numDeletedRooms) {
if ($this->numDeletedRooms) {
$this->logger->info('Deleted {numDeletedRooms} rooms because they were empty', [
'numDeletedRooms' => $numDeletedRooms,
'numDeletedRooms' => $this->numDeletedRooms,
'app' => 'spreed',
]);
}
}
protected function callback(Room $room) {
if ($room->getType() === Room::ONE_TO_ONE_CALL && $room->getNumberOfParticipants(false) <= 1) {
$room->deleteRoom();
$this->numDeletedRooms++;
} else if ($room->getNumberOfParticipants(false) === 0) {
$room->deleteRoom();
$this->numDeletedRooms++;
}
}
}

Просмотреть файл

@ -0,0 +1,75 @@
<?php
/**
* @copyright Copyright (c) 2018 Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Spreed\BackgroundJob;
use OC\BackgroundJob\TimedJob;
use OCA\Spreed\Exceptions\ParticipantNotFoundException;
use OCA\Spreed\Manager;
use OCA\Spreed\Room;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\ILogger;
/**
* Class ResetInCallFlags
*
* @package OCA\Spreed\BackgroundJob
*/
class ResetInCallFlags extends TimedJob {
/** @var Manager */
protected $manager;
/** @var int */
protected $timeout;
public function __construct(Manager $manager, ITimeFactory $timeFactory) {
// Every 5 minutes
$this->setInterval(60 * 5);
$this->manager = $manager;
$this->timeout = $timeFactory->getTime() - 5 * 60;
}
protected function run($argument) {
$this->manager->forAllRooms([$this, 'callback']);
}
protected function callback(Room $room) {
if (!$room->hasSessionsInCall()) {
return;
}
foreach ($room->getActiveSessions() as $session) {
try {
$participant = $room->getParticipantBySession($session);
} catch (ParticipantNotFoundException $e) {
// Participant was just deleted, ignore …
continue;
}
if ($participant->isInCall() && $participant->getLastPing() < $this->timeout) {
$room->changeInCall($session, false);
}
}
}
}

Просмотреть файл

@ -61,7 +61,7 @@ class Manager {
$this->hasher = $hasher;
}
public function forAllRooms(\Closure $callback) {
public function forAllRooms(callable $callback) {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from('talk_rooms');