diff options
author | Joas Schilling <coding@schilljs.com> | 2018-03-09 17:44:27 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2018-03-09 17:49:59 +0300 |
commit | b88394f26580bab982d9e0407d59c2526dd6b7ab (patch) | |
tree | c72cd3040d2bc9963d434bf92a476c4dd44fc75e /lib/BackgroundJob | |
parent | c563081393ec9f28b757cfed7baad1745ed284ed (diff) |
Reset in call flag when a user timed out
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/BackgroundJob')
-rw-r--r-- | lib/BackgroundJob/RemoveEmptyRooms.php | 29 | ||||
-rw-r--r-- | lib/BackgroundJob/ResetInCallFlags.php | 75 |
2 files changed, 91 insertions, 13 deletions
diff --git a/lib/BackgroundJob/RemoveEmptyRooms.php b/lib/BackgroundJob/RemoveEmptyRooms.php index b5af43ad6..246762b39 100644 --- a/lib/BackgroundJob/RemoveEmptyRooms.php +++ b/lib/BackgroundJob/RemoveEmptyRooms.php @@ -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++; + } + } } diff --git a/lib/BackgroundJob/ResetInCallFlags.php b/lib/BackgroundJob/ResetInCallFlags.php new file mode 100644 index 000000000..dbff79a3a --- /dev/null +++ b/lib/BackgroundJob/ResetInCallFlags.php @@ -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); + } + } + } +} |