diff --git a/lib/BackgroundJob/CheckHostedSignalingServer.php b/lib/BackgroundJob/CheckHostedSignalingServer.php index 9ab28b6394b..29e064b5b5f 100644 --- a/lib/BackgroundJob/CheckHostedSignalingServer.php +++ b/lib/BackgroundJob/CheckHostedSignalingServer.php @@ -8,6 +8,7 @@ namespace OCA\Talk\BackgroundJob; +use OCA\Talk\Config; use OCA\Talk\DataObjects\AccountId; use OCA\Talk\Exceptions\HostedSignalingServerAPIException; use OCA\Talk\Service\HostedSignalingServerService; @@ -32,6 +33,7 @@ public function __construct( private IGroupManager $groupManager, private IURLGenerator $urlGenerator, private LoggerInterface $logger, + private Config $talkConfig, ) { parent::__construct($timeFactory); @@ -41,6 +43,62 @@ public function __construct( } + private function formatTurnSchemes(array $schemes): string { + if (in_array('turn', $schemes) && in_array('turns', $schemes)) { + return 'turn,turns'; + } elseif (in_array('turn', $schemes)) { + return 'turn'; + } elseif (in_array('turns', $schemes)) { + return 'turns'; + } else { + return 'turn'; + } + } + + private function formatTurnProtocols(array $protocols): string { + if (in_array('udp', $protocols) && in_array('tcp', $protocols)) { + return 'udp,tcp'; + } elseif (in_array('udp', $protocols)) { + return 'udp'; + } elseif (in_array('tcp', $protocols)) { + return 'tcp'; + } else { + return 'udp'; + } + } + + private function updateStunTurnSettings(array $oldAccountInfo, array $accountInfo) { + if (!empty($accountInfo['stun']['servers'])) { + if ($this->talkConfig->getStunServers() !== $accountInfo['stun']['servers']) { + // STUN servers were added / changed + $this->config->setAppValue('spreed', 'stun_servers', json_encode($accountInfo['stun']['servers'])); + } + } elseif (!empty($oldAccountInfo['stun']['servers'])) { + // STUN servers are no longer available, reset to default. + $this->config->deleteAppValue('spreed', 'stun_servers'); + } + + if (!empty($accountInfo['turn']['servers'])) { + $newTurnServers = []; + foreach ($accountInfo['turn']['servers'] as $server) { + $newTurnServers[] = [ + 'server' => $server['server'], + 'secret' => $server['secret'], + 'schemes' => $this->formatTurnSchemes($server['schemes']), + 'protocols' => $this->formatTurnProtocols($server['protocols']), + ]; + } + + if ($this->talkConfig->getTurnServers() !== $newTurnServers) { + // TURN servers were added / changed + $this->config->setAppValue('spreed', 'turn_servers', json_encode($newTurnServers)); + } + } elseif (!empty($oldAccountInfo['turn']['servers'])) { + // TURN servers are no longer available, reset to default. + $this->config->deleteAppValue('spreed', 'turn_servers'); + } + } + #[\Override] protected function run($argument): void { $accountId = $this->config->getAppValue('spreed', 'hosted-signaling-server-account-id', ''); @@ -91,6 +149,7 @@ protected function run($argument): void { ], 'secret' => $accountInfo['signaling']['secret'], ])); + $this->updateStunTurnSettings($oldAccountInfo, $accountInfo); $notificationSubject = 'added'; } @@ -104,19 +163,20 @@ protected function run($argument): void { } // only credentials have changed - } elseif ($newStatus === 'active' && ( - $oldAccountInfo['signaling']['url'] !== $accountInfo['signaling']['url'] - || $oldAccountInfo['signaling']['secret'] !== $accountInfo['signaling']['secret']) - ) { - $this->config->setAppValue('spreed', 'signaling_servers', json_encode([ - 'servers' => [ - [ - 'server' => $accountInfo['signaling']['url'], - 'verify' => true, - ] - ], - 'secret' => $accountInfo['signaling']['secret'], - ])); + } elseif ($newStatus === 'active') { + if ($oldAccountInfo['signaling']['url'] !== $accountInfo['signaling']['url'] + || $oldAccountInfo['signaling']['secret'] !== $accountInfo['signaling']['secret']) { + $this->config->setAppValue('spreed', 'signaling_servers', json_encode([ + 'servers' => [ + [ + 'server' => $accountInfo['signaling']['url'], + 'verify' => true, + ] + ], + 'secret' => $accountInfo['signaling']['secret'], + ])); + } + $this->updateStunTurnSettings($oldAccountInfo, $accountInfo); } // store new account info diff --git a/src/components/AdminSettings/HostedSignalingServer.vue b/src/components/AdminSettings/HostedSignalingServer.vue index 168c437b6c1..8ed08c2cd18 100644 --- a/src/components/AdminSettings/HostedSignalingServer.vue +++ b/src/components/AdminSettings/HostedSignalingServer.vue @@ -13,6 +13,7 @@

{{ t('spreed', 'Our partner Struktur AG provides a service where a hosted signaling server can be requested. For this you only need to fill out the form below and your Nextcloud will request it. Once the server is set up for you the credentials will be filled automatically. This will overwrite the existing signaling server settings.') }} + {{ t('spreed', 'If your high-performance backend account includes STUN and/or TURN functionality, the settings will be updated accordingly.') }}