diff options
author | Joas Schilling <coding@schilljs.com> | 2020-04-14 14:20:35 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-05-12 11:40:20 +0300 |
commit | bf5489fefe41e66d7fdedee6a70b4f7d53fed354 (patch) | |
tree | 86b43413c62f82632d4a702c30c6109cae70513e /lib/Signaling/BackendNotifier.php | |
parent | 59f83e55fec981f86045a4ab19793cd7d3564c02 (diff) |
Hand in the Room object to the deeper levels
So we can use it to decide which HPB to talk to
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Signaling/BackendNotifier.php')
-rw-r--r-- | lib/Signaling/BackendNotifier.php | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/lib/Signaling/BackendNotifier.php b/lib/Signaling/BackendNotifier.php index 6be38c826..da76192d5 100644 --- a/lib/Signaling/BackendNotifier.php +++ b/lib/Signaling/BackendNotifier.php @@ -79,24 +79,32 @@ class BackendNotifier { /** * Perform a request to the signaling backend. * - * @param string $url + * @param Room $room * @param array $data * @throws \Exception */ - private function backendRequest(string $url, array $data): void { + private function backendRequest(Room $room, array $data): void { if ($this->config->getSignalingMode() === Config::SIGNALING_INTERNAL) { return; } + $servers = $this->config->getSignalingServers(); + $serverId = null; if ($this->config->getSignalingMode() === Config::SIGNALING_CLUSTER_CONVERSATION) { // FIXME need to send it to the right signaling server + $serverId = $room->getAssignedSignalingServer(); + // FIXME some need to go to all HPBs? + } + if ($serverId === null) { + // We can use any server of the available backends. + $serverId = random_int(0, count($servers) - 1); } - $servers = $this->config->getSignalingServers(); - // We can use any server of the available backends. - $signaling = $servers[random_int(0, count($servers) - 1)]; + $signaling = $servers[$serverId]; $signaling['server'] = rtrim($signaling['server'], '/'); - $url = rtrim($signaling['server'], '/') . $url; + + $url = '/api/v1/room/' . $room->getToken(); + $url = $signaling['server'] . $url; if (strpos($url, 'wss://') === 0) { $url = 'https://' . substr($url, 6); } else if (strpos($url, 'ws://') === 0) { @@ -135,7 +143,7 @@ class BackendNotifier { foreach ($users as $user) { $userIds[] = $user['userId']; } - $this->backendRequest('/api/v1/room/' . $room->getToken(), [ + $this->backendRequest($room, [ 'type' => 'invite', 'invite' => [ 'userids' => $userIds, @@ -156,7 +164,7 @@ class BackendNotifier { */ public function roomsDisinvited(Room $room, array $userIds): void { $this->logger->info('No longer invited to ' . $room->getToken() . ': ' . print_r($userIds, true), ['app' => 'spreed']); - $this->backendRequest('/api/v1/room/' . $room->getToken(), [ + $this->backendRequest($room, [ 'type' => 'disinvite', 'disinvite' => [ 'userids' => $userIds, @@ -177,7 +185,7 @@ class BackendNotifier { */ public function roomSessionsRemoved(Room $room, array $sessionIds): void { $this->logger->info('Removed from ' . $room->getToken() . ': ' . print_r($sessionIds, true), ['app' => 'spreed']); - $this->backendRequest('/api/v1/room/' . $room->getToken(), [ + $this->backendRequest($room, [ 'type' => 'disinvite', 'disinvite' => [ 'sessionids' => $sessionIds, @@ -197,7 +205,7 @@ class BackendNotifier { */ public function roomModified(Room $room): void { $this->logger->info('Room modified: ' . $room->getToken(), ['app' => 'spreed']); - $this->backendRequest('/api/v1/room/' . $room->getToken(), [ + $this->backendRequest($room, [ 'type' => 'update', 'update' => [ 'userids' => $room->getParticipantUserIds(), @@ -216,7 +224,7 @@ class BackendNotifier { public function roomDeleted(Room $room, array $participants): void { $this->logger->info('Room deleted: ' . $room->getToken(), ['app' => 'spreed']); $userIds = array_keys($participants['users']); - $this->backendRequest('/api/v1/room/' . $room->getToken(), [ + $this->backendRequest($room, [ 'type' => 'delete', 'delete' => [ 'userids' => $userIds, @@ -258,7 +266,7 @@ class BackendNotifier { $changed[] = $participant; } } - $this->backendRequest('/api/v1/room/' . $room->getToken(), [ + $this->backendRequest($room, [ 'type' => 'participants', 'participants' => [ 'changed' => $changed, @@ -301,7 +309,7 @@ class BackendNotifier { } } - $this->backendRequest('/api/v1/room/' . $room->getToken(), [ + $this->backendRequest($room, [ 'type' => 'incall', 'incall' => [ 'incall' => $flags, @@ -320,7 +328,7 @@ class BackendNotifier { * @throws \Exception */ public function sendRoomMessage(Room $room, array $message): void { - $this->backendRequest('/api/v1/room/' . $room->getToken(), [ + $this->backendRequest($room, [ 'type' => 'message', 'message' => [ 'data' => $message, |