diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2022-02-07 18:05:49 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-07 18:05:49 +0300 |
commit | 04fbe4786bb6578e5f06b29821b4f8925770e652 (patch) | |
tree | e98bca35c0f88fe4d1ce308057d95bb908475e5e | |
parent | 6a773d78df71b61f317ae2e40cf9231a91652098 (diff) | |
parent | 96a0ecf8ccfdb7456c2a6f9bea92f3afc077af54 (diff) |
Merge pull request #6841 from nextcloud/backport/6837/stable23
[stable23] Only send 1 HPB request for the "end call for everyone" case
-rw-r--r-- | lib/Events/EndCallForEveryoneEvent.php | 54 | ||||
-rw-r--r-- | lib/Service/ParticipantService.php | 8 | ||||
-rw-r--r-- | lib/Signaling/Listener.php | 30 |
3 files changed, 90 insertions, 2 deletions
diff --git a/lib/Events/EndCallForEveryoneEvent.php b/lib/Events/EndCallForEveryoneEvent.php new file mode 100644 index 000000000..a080e5f07 --- /dev/null +++ b/lib/Events/EndCallForEveryoneEvent.php @@ -0,0 +1,54 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2019 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\Talk\Events; + +use OCA\Talk\Participant; +use OCA\Talk\Room; + +class EndCallForEveryoneEvent extends ModifyRoomEvent { + + /** @var string[] */ + protected $sessionIds; + + public function __construct(Room $room, + ?Participant $actor = null) { + parent::__construct($room, 'in_call', Participant::FLAG_DISCONNECTED, null, $actor); + } + + /** + * @param string[] $sessionIds + * @return void + */ + public function setSessionIds(array $sessionIds): void { + $this->sessionIds = $sessionIds; + } + + /** + * Only available in the after-event + * @return string[] + */ + public function getSessionIds(): array { + return $this->sessionIds; + } +} diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php index d11bf996e..2bd4010fd 100644 --- a/lib/Service/ParticipantService.php +++ b/lib/Service/ParticipantService.php @@ -30,11 +30,11 @@ use OCA\Talk\Config; use OCA\Talk\Events\AddParticipantsEvent; use OCA\Talk\Events\AttendeesAddedEvent; use OCA\Talk\Events\AttendeesRemovedEvent; +use OCA\Talk\Events\EndCallForEveryoneEvent; use OCA\Talk\Events\JoinRoomGuestEvent; use OCA\Talk\Events\JoinRoomUserEvent; use OCA\Talk\Events\ModifyEveryoneEvent; use OCA\Talk\Events\ModifyParticipantEvent; -use OCA\Talk\Events\ModifyRoomEvent; use OCA\Talk\Events\ParticipantEvent; use OCA\Talk\Events\RemoveParticipantEvent; use OCA\Talk\Events\RemoveUserEvent; @@ -908,16 +908,20 @@ class ParticipantService { } public function endCallForEveryone(Room $room, Participant $moderator): void { - $event = new ModifyRoomEvent($room, 'in_call', Participant::FLAG_DISCONNECTED, null, $moderator); + $event = new EndCallForEveryoneEvent($room, $moderator); $this->dispatcher->dispatch(Room::EVENT_BEFORE_END_CALL_FOR_EVERYONE, $event); $participants = $this->getParticipantsInCall($room); + $changedSessionIds = []; // kick out all participants out of the call foreach ($participants as $participant) { + $changedSessionIds[] = $participant->getSession()->getSessionId(); $this->changeInCall($room, $participant, Participant::FLAG_DISCONNECTED, true); } + $event->setSessionIds($changedSessionIds); + $this->dispatcher->dispatch(Room::EVENT_AFTER_END_CALL_FOR_EVERYONE, $event); } diff --git a/lib/Signaling/Listener.php b/lib/Signaling/Listener.php index a7bf3250d..9a62be582 100644 --- a/lib/Signaling/Listener.php +++ b/lib/Signaling/Listener.php @@ -28,6 +28,8 @@ use OCA\Talk\Config; use OCA\Talk\Events\AddParticipantsEvent; use OCA\Talk\Events\ChatEvent; use OCA\Talk\Events\ChatParticipantEvent; +use OCA\Talk\Events\EndCallForEveryoneEvent; +use OCA\Talk\Events\ModifyEveryoneEvent; use OCA\Talk\Events\ModifyParticipantEvent; use OCA\Talk\Events\ParticipantEvent; use OCA\Talk\Events\RemoveParticipantEvent; @@ -235,6 +237,13 @@ class Listener { return; } + if ($event instanceof ModifyEveryoneEvent) { + // If everyone is disconnected, we will not do O(n) requests. + // Instead, the listener of Room::EVENT_AFTER_END_CALL_FOR_EVERYONE + // will send all sessions to the HPB with 1 request. + return; + } + /** @var BackendNotifier $notifier */ $notifier = \OC::$server->query(BackendNotifier::class); @@ -259,6 +268,27 @@ class Listener { $dispatcher->addListener(Room::EVENT_AFTER_SESSION_UPDATE_CALL_FLAGS, $listener); $dispatcher->addListener(Room::EVENT_AFTER_SESSION_LEAVE_CALL, $listener); + $dispatcher->addListener(Room::EVENT_AFTER_END_CALL_FOR_EVERYONE, static function (EndCallForEveryoneEvent $event): void { + if (self::isUsingInternalSignaling()) { + return; + } + + $sessionIds = $event->getSessionIds(); + + if (empty($sessionIds)) { + return; + } + + /** @var BackendNotifier $notifier */ + $notifier = \OC::$server->get(BackendNotifier::class); + + $notifier->roomInCallChanged( + $event->getRoom(), + $event->getNewValue(), + $sessionIds + ); + }); + $dispatcher->addListener(Room::EVENT_AFTER_GUESTS_CLEAN, static function (RoomEvent $event) { if (self::isUsingInternalSignaling()) { return; |