Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--appinfo/routes.php5
-rw-r--r--css/settings-admin.scss3
-rw-r--r--js/admin/turn-server.js116
-rw-r--r--lib/Config.php24
-rw-r--r--lib/Controller/AppSettingsController.php99
-rw-r--r--lib/Settings/Admin/TurnServer.php4
-rw-r--r--templates/settings/admin/turn-server.php34
7 files changed, 136 insertions, 149 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 688bc7763..012acfefe 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -28,11 +28,6 @@ return [
'url' => '/',
'verb' => 'GET',
],
- [
- 'name' => 'AppSettings#setSpreedSettings',
- 'url' => '/settings/admin',
- 'verb' => 'POST',
- ],
],
'ocs' => [
[
diff --git a/css/settings-admin.scss b/css/settings-admin.scss
index 7e511b5dd..a8aa797e2 100644
--- a/css/settings-admin.scss
+++ b/css/settings-admin.scss
@@ -4,7 +4,8 @@
}
.icon-delete,
- div.stun-server:last-child .icon-add {
+ div.stun-server:last-child .icon-add,
+ div.turn-server:last-child .icon-add {
display: inline-block;
}
diff --git a/js/admin/turn-server.js b/js/admin/turn-server.js
new file mode 100644
index 000000000..7c48902c3
--- /dev/null
+++ b/js/admin/turn-server.js
@@ -0,0 +1,116 @@
+/* global OC, OCP, OCA, $, _ */
+
+(function(OC, OCP, OCA, $, _) {
+ 'use strict';
+
+ OCA.VideoCalls = OCA.VideoCalls || {};
+ OCA.VideoCalls.Admin = OCA.VideoCalls.Admin || {};
+ OCA.VideoCalls.Admin.TurnServer = {
+
+ TEMPLATE: '<div class="turn-server">' +
+ ' <input type="text" class="server" placeholder="https://turn.example.org" value="{{server}}">' +
+ ' <input type="text" class="secret" placeholder="' + t('spreed', 'Shared secret') + '" value="{{secret}}">' +
+ ' <select class="protocols" title="' + t('spreed', 'TURN server protocols') + '">' +
+ ' {{#select protocols}}' +
+ ' <option value="udp,tcp">' + t('spreed', 'UDP and TCP') + '</option>' +
+ ' <option value="udp">' + t('spreed', 'UDP only') + '</option>' +
+ ' <option value="tcp">' + t('spreed', 'TCP only') + '</option>' +
+ ' {{/select}}' +
+ ' </select>' +
+ ' <a class="icon icon-delete" title="' + t('spreed', 'Delete server') + '"></a>' +
+ ' <a class="icon icon-add" title="' + t('spreed', 'Add new server') + '"></a>' +
+ '</div>',
+ $list: undefined,
+ template: undefined,
+
+ init: function() {
+ Handlebars.registerHelper('select', this._handlebarSelectOption);
+ this.template = Handlebars.compile(this.TEMPLATE);
+ this.$list = $('div.turn-servers');
+ this.renderList();
+
+ },
+
+ _handlebarSelectOption: function(value, options) {
+ var $el = $('<select />').html(options.fn(this));
+ $el.find('[value="' + value + '"]').attr({'selected':'selected'});
+ return $el.html();
+ },
+
+ renderList: function() {
+ var servers = this.$list.data('servers');
+
+ _.each(servers, function(server) {
+ this.$list.append(
+ this.renderServer(server)
+ );
+ }.bind(this));
+
+ if (servers.length === 0) {
+ this.addNewTemplate();
+ }
+ },
+
+ addNewTemplate: function() {
+ this.$list.append(
+ this.renderServer({})
+ );
+ },
+
+ deleteServer: function(e) {
+ e.stopPropagation();
+
+ var $server = $(e.currentTarget).parents('div.turn-server').first();
+ $server.remove();
+
+ this.saveServers();
+
+ if (this.$list.find('div.turn-server').length === 0) {
+ this.addNewTemplate();
+ }
+ },
+
+ saveServers: function() {
+ var servers = [];
+
+ this.$list.find('input').removeClass('error');
+ this.$list.find('div.turn-server').each(function() {
+ var $row = $(this),
+ $server = $row.find('input.server'),
+ $secret = $row.find('input.secret'),
+ $protocols = $row.find('select.protocols'),
+ data = {
+ server: $server.val().trim(),
+ secret: $secret.val().trim(),
+ protocols: $protocols.val()
+ };
+ if (data.server === '') {
+ $server.addClass('error');
+ }
+ if (data.secret === '') {
+ $secret.addClass('error');
+ }
+ servers.push(data);
+ });
+
+ OCP.AppConfig.setValue('spreed', 'turn_server', JSON.stringify(servers));
+ },
+
+ renderServer: function(server) {
+ var $template = $(this.template(server));
+
+ $template.find('a.icon-add').on('click', this.addNewTemplate.bind(this));
+ $template.find('a.icon-delete').on('click', this.deleteServer.bind(this));
+ $template.find('input').on('change', this.saveServers.bind(this));
+
+ return $template;
+ }
+
+ };
+
+
+})(OC, OCP, OCA, $, _);
+
+$(document).ready(function(){
+ OCA.VideoCalls.Admin.TurnServer.init();
+});
diff --git a/lib/Config.php b/lib/Config.php
index 736115e57..1049af0a5 100644
--- a/lib/Config.php
+++ b/lib/Config.php
@@ -55,6 +55,7 @@ class Config {
}
if (is_array($servers) && !empty($servers)) {
+ // For now we use a random server from the list
return $servers[mt_rand(0, count($servers) - 1)];
}
@@ -67,12 +68,10 @@ class Config {
* @return array
*/
public function getTurnSettings() {
- // generate from shared secret
- $turnServer = $this->config->getAppValue('spreed', 'turn_server', '');
- $turnServerSecret = $this->config->getAppValue('spreed', 'turn_server_secret', '');
- $turnServerProtocols = $this->config->getAppValue('spreed', 'turn_server_protocols', '');
+ $config = $this->config->getAppValue('spreed', 'stun_server');
+ $servers = json_decode($config);
- if ($turnServer === '' || $turnServerSecret === '' || $turnServerProtocols === '') {
+ if ($servers === null || !empty($servers) || !is_array($servers)) {
return [
'server' => '',
'username' => '',
@@ -81,16 +80,19 @@ class Config {
];
}
- // the credentials are valid for 24h - FIXME add the TTL to the response and properly reconnect then
+ // For now we use a random server from the list
+ $server = $servers[mt_rand(0, count($servers) - 1)];
+
+ // Credentials are valid for 24h
+ // FIXME add the TTL to the response and properly reconnect then
$username = $this->timeFactory->getTime() + 86400;
- $hashedString = hash_hmac('sha1', $username, $turnServerSecret, true);
- $password = base64_encode($hashedString);
+ $password = base64_encode(hash_hmac('sha1', $username, $server['secret'], true));
return array(
- 'server' => $turnServer,
- 'username' => (string)$username,
+ 'server' => $server['server'],
+ 'username' => (string) $username,
'password' => $password,
- 'protocols' => $turnServerProtocols,
+ 'protocols' => $server['protocols'],
);
}
diff --git a/lib/Controller/AppSettingsController.php b/lib/Controller/AppSettingsController.php
deleted file mode 100644
index ce5dfaf1c..000000000
--- a/lib/Controller/AppSettingsController.php
+++ /dev/null
@@ -1,99 +0,0 @@
-<?php
-/**
- * @author Joachim Bauch <mail@joachim-bauch.de>
- *
- * @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\Controller;
-
-use OCP\AppFramework\Controller;
-use OCP\IConfig;
-use OCP\IL10N;
-use OCP\IRequest;
-
-class AppSettingsController extends Controller {
-
- /** @var IL10N */
- private $l10n;
- /** @var IConfig */
- private $config;
-
- /**
- * @param string $appName
- * @param IRequest $request
- * @param IL10N $l10n
- * @param IConfig $config
- */
- public function __construct($appName,
- IRequest $request,
- IL10N $l10n,
- IConfig $config) {
- parent::__construct($appName, $request);
- $this->l10n = $l10n;
- $this->config = $config;
- }
-
- /**
- * Configure the settings of the Spreed app.
- *
- * @param string $turn_server
- * @param string $turn_server_secret
- * @param string $turn_server_protocols
- * @return array
- */
- public function setSpreedSettings($turn_server, $turn_server_secret, $turn_server_protocols) {
- if ($turn_server_protocols !== '') {
- if (!in_array($turn_server_protocols, array('udp,tcp', 'tcp', 'udp'))) {
- return array('data' =>
- array('message' =>
- (string) $this->l10n->t('Invalid protocols specified.')
- ),
- 'status' => 'error'
- );
- }
- }
-
- $currentStunServer = $this->config->getAppValue('spreed', 'stun_server', '');
- if ( $currentStunServer !== $stun_server ) {
- $this->config->setAppValue('spreed', 'stun_server', $stun_server);
- }
-
- $currentTurnServer = $this->config->getAppValue('spreed', 'turn_server', '');
- if ( $currentTurnServer !== $turn_server ) {
- $this->config->setAppValue('spreed', 'turn_server', $turn_server);
- }
-
- $currentTurnServerSecret = $this->config->getAppValue('spreed', 'turn_server_secret', '');
- if ( $currentTurnServerSecret !== $turn_server_secret ) {
- $this->config->setAppValue('spreed', 'turn_server_secret', $turn_server_secret);
- }
-
- $currentTurnServerProtocols = $this->config->getAppValue('spreed', 'turn_server_protocols', '');
- if ( $currentTurnServerProtocols !== $turn_server_protocols ) {
- $this->config->setAppValue('spreed', 'turn_server_protocols', $turn_server_protocols);
- }
-
- return array('data' =>
- array('message' =>
- (string) $this->l10n->t('Saved')
- ),
- 'status' => 'success'
- );
- }
-
-}
diff --git a/lib/Settings/Admin/TurnServer.php b/lib/Settings/Admin/TurnServer.php
index f11bab085..b5ff1d4d6 100644
--- a/lib/Settings/Admin/TurnServer.php
+++ b/lib/Settings/Admin/TurnServer.php
@@ -40,9 +40,7 @@ class TurnServer implements ISettings {
*/
public function getForm() {
$parameters = [
- 'turnServer' => $this->config->getAppValue('spreed', 'turn_server', ''),
- 'turnServerSecret' => $this->config->getAppValue('spreed', 'turn_server_secret', ''),
- 'turnServerProtocols' => $this->config->getAppValue('spreed', 'turn_server_protocols', ''),
+ 'turnServer' => $this->config->getAppValue('spreed', 'turn_server'),
];
return new TemplateResponse('spreed', 'settings/admin/turn-server', $parameters, '');
diff --git a/templates/settings/admin/turn-server.php b/templates/settings/admin/turn-server.php
index 19946828e..ef2376d8f 100644
--- a/templates/settings/admin/turn-server.php
+++ b/templates/settings/admin/turn-server.php
@@ -1,40 +1,14 @@
<?php
/** @var array $_ */
/** @var \OCP\IL10N $l */
-script('spreed', ['settings-admin']);
+script('spreed', ['admin/turn-server']);
style('spreed', ['settings-admin']);
?>
<div class="videocalls section">
<h3><?php p($l->t('TURN server')) ?></h3>
<p class="settings-hint"><?php p($l->t('The TURN server is used to proxy the traffic from participants behind a firewall.')); ?></p>
- <p>
- <label for="turn_server"><?php p($l->t('TURN server')) ?></label>
- <input type="text" id="turn_server"
- name="turn_server" placeholder="https://turn.example.org"
- value="<?php p($_['turnServer']) ?>" />
- </p>
- <p>
- <label for="turn_server_secret"><?php p($l->t('TURN server shared secret')) ?></label>
- <input type="text" id="turn_server_secret"
- name="turn_server_secret" placeholder="shared secret"
- value="<?php p($_['turnServerSecret']) ?>" />
- </p>
- <p>
- <label for="turn_server_protocols"><?php p($l->t('TURN server protocols')) ?></label>
- <select id="turn_server_protocols" name="turn_server_protocols">
- <option value="udp,tcp"
- <?php p($_['turnServerProtocols'] === 'udp,tcp' ? 'selected' : '') ?>>
- <?php p($l->t('UDP and TCP')) ?>
- </option>
- <option value="udp"
- <?php p($_['turnServerProtocols'] === 'udp' ? 'selected' : '') ?>>
- <?php p($l->t('UDP only')) ?>
- </option>
- <option value="tcp"
- <?php p($_['turnServerProtocols'] === 'tcp' ? 'selected' : '') ?>>
- <?php p($l->t('TCP only')) ?>
- </option>
- </select>
- </p>
+
+ <div class="turn-servers" data-servers="<?php p($_['turnServer']) ?>">
+ </div>
</div>