diff options
author | Joas Schilling <coding@schilljs.com> | 2020-10-14 16:53:51 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-10-30 12:38:07 +0300 |
commit | 89bdbe0c51a509891a70c4a84b0c92d0c6825319 (patch) | |
tree | 0f18774c22bba2531949cdb6399b515f77e192d0 /lib | |
parent | ab2e30a6506da13b09aeac3b08f208d2e5e5085f (diff) |
Add an endpoint to enable the SIP per conversation
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Controller/RoomController.php | 3 | ||||
-rw-r--r-- | lib/Controller/WebinarController.php | 17 | ||||
-rw-r--r-- | lib/Manager.php | 2 | ||||
-rw-r--r-- | lib/Migration/Version10000Date20201012144235.php | 2 | ||||
-rw-r--r-- | lib/Room.php | 48 |
5 files changed, 65 insertions, 7 deletions
diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index 5788613e5..e38ec4add 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -485,6 +485,7 @@ class RoomController extends AEnvironmentAwareController { 'notificationLevel' => Participant::NOTIFY_NEVER, 'lobbyState' => Webinary::LOBBY_NONE, 'lobbyTimer' => 0, + 'sipEnabled' => Webinary::SIP_DISABLED, 'lastPing' => 0, 'sessionId' => '0', 'guestList' => '', @@ -516,6 +517,7 @@ class RoomController extends AEnvironmentAwareController { 'lastActivity' => $lastActivity, 'lobbyState' => $room->getLobbyState(), 'lobbyTimer' => $lobbyTimer, + 'sipEnabled' => $room->getSIPEnabled(), ]); } @@ -537,6 +539,7 @@ class RoomController extends AEnvironmentAwareController { 'notificationLevel' => $currentParticipant->getNotificationLevel(), 'lobbyState' => $room->getLobbyState(), 'lobbyTimer' => $lobbyTimer, + 'sipEnabled' => $room->getSIPEnabled(), 'lastPing' => $currentParticipant->getLastPing(), 'sessionId' => $currentParticipant->getSessionId(), ]); diff --git a/lib/Controller/WebinarController.php b/lib/Controller/WebinarController.php index c3ac6e5d5..406495158 100644 --- a/lib/Controller/WebinarController.php +++ b/lib/Controller/WebinarController.php @@ -67,4 +67,21 @@ class WebinarController extends AEnvironmentAwareController { return new DataResponse(); } + + /** + * @NoAdminRequired + * @RequireModeratorParticipant + * + * @param int $state + * @return DataResponse + */ + public function setSIPEnabled(int $state): DataResponse { + // TODO Check if user is in "SIP groups" + + if (!$this->room->setSIPEnabled($state)) { + return new DataResponse([], Http::STATUS_BAD_REQUEST); + } + + return new DataResponse(); + } } diff --git a/lib/Manager.php b/lib/Manager.php index 7d3df1e48..9cc3dc0da 100644 --- a/lib/Manager.php +++ b/lib/Manager.php @@ -148,7 +148,7 @@ class Manager { (int) $row['type'], (int) $row['read_only'], (int) $row['lobby_state'], - (int) $row['sip_status'], + (int) $row['sip_enabled'], $assignedSignalingServer, (string) $row['token'], (string) $row['name'], diff --git a/lib/Migration/Version10000Date20201012144235.php b/lib/Migration/Version10000Date20201012144235.php index f361bf438..d76142930 100644 --- a/lib/Migration/Version10000Date20201012144235.php +++ b/lib/Migration/Version10000Date20201012144235.php @@ -44,7 +44,7 @@ class Version10000Date20201012144235 extends SimpleMigrationStep { $schema = $schemaClosure(); $table = $schema->getTable('talk_rooms'); - $table->addColumn('sip_status', Type::SMALLINT, [ + $table->addColumn('sip_enabled', Type::SMALLINT, [ 'notnull' => true, 'default' => 0, 'unsigned' => true, diff --git a/lib/Room.php b/lib/Room.php index 8582b19e8..fa8102b7e 100644 --- a/lib/Room.php +++ b/lib/Room.php @@ -81,6 +81,8 @@ class Room { public const EVENT_AFTER_READONLY_SET = self::class . '::postSetReadOnly'; public const EVENT_BEFORE_LOBBY_STATE_SET = self::class . '::preSetLobbyState'; public const EVENT_AFTER_LOBBY_STATE_SET = self::class . '::postSetLobbyState'; + public const EVENT_BEFORE_SIP_ENABLED_SET = self::class . '::preSetSIPEnabled'; + public const EVENT_AFTER_SIP_ENABLED_SET = self::class . '::postSetSIPEnabled'; public const EVENT_BEFORE_USERS_ADD = self::class . '::preAddUsers'; public const EVENT_AFTER_USERS_ADD = self::class . '::postAddUsers'; public const EVENT_BEFORE_PARTICIPANT_TYPE_SET = self::class . '::preSetParticipantType'; @@ -126,7 +128,7 @@ class Room { /** @var int */ private $lobbyState; /** @var int */ - private $sipStatus; + private $sipEnabled; /** @var int|null */ private $assignedSignalingServer; /** @var \DateTime|null */ @@ -167,7 +169,7 @@ class Room { int $type, int $readOnly, int $lobbyState, - int $sipStatus, + int $sipEnabled, ?int $assignedSignalingServer, string $token, string $name, @@ -190,7 +192,7 @@ class Room { $this->type = $type; $this->readOnly = $readOnly; $this->lobbyState = $lobbyState; - $this->sipStatus = $sipStatus; + $this->sipEnabled = $sipEnabled; $this->assignedSignalingServer = $assignedSignalingServer; $this->token = $token; $this->name = $name; @@ -222,8 +224,8 @@ class Room { return $this->lobbyState; } - public function getSIPStatus(): int { - return $this->sipStatus; + public function getSIPEnabled(): int { + return $this->sipEnabled; } public function getLobbyTimer(): ?\DateTime { @@ -680,6 +682,42 @@ class Room { return true; } + public function setSIPEnabled(int $newSipEnabled): bool { + $oldSipEnabled = $this->sipEnabled; + + if ($newSipEnabled === $oldSipEnabled) { + return false; + } + + if (!in_array($this->getType(), [self::GROUP_CALL, self::PUBLIC_CALL], true)) { + return false; + } + + if (!in_array($newSipEnabled, [Webinary::SIP_ENABLED, Webinary::SIP_DISABLED], true)) { + return false; + } + + if (!preg_match('/^\d+$/', $this->token)) { + return false; + } + + $event = new ModifyRoomEvent($this, 'sipStatus', $newSipEnabled, $oldSipEnabled); + $this->dispatcher->dispatch(self::EVENT_BEFORE_SIP_ENABLED_SET, $event); + + $query = $this->db->getQueryBuilder(); + $query->update('talk_rooms') + ->set('sip_enabled', $query->createNamedParameter($newSipEnabled, IQueryBuilder::PARAM_INT)) + ->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT))); + $query->execute(); + + $this->sipEnabled = $newSipEnabled; + + $this->dispatcher->dispatch(self::EVENT_AFTER_SIP_ENABLED_SET, $event); + + + return true; + } + public function ensureOneToOneRoomIsFilled(): void { if ($this->getType() !== self::ONE_TO_ONE_CALL) { return; |