diff --git a/appinfo/info.xml b/appinfo/info.xml index b73b57c985..9e23c74419 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -42,7 +42,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m https://github.com/nextcloud/spreed/issues https://github.com/nextcloud/spreed.git - 2.1.5 + 2.1.6 @@ -61,8 +61,9 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m - OCA\Spreed\Settings\Admin - OCA\Spreed\Settings\AdminSection + OCA\Spreed\Settings\Admin\TurnServer + OCA\Spreed\Settings\Admin\StunServer + OCA\Spreed\Settings\Admin\Section diff --git a/css/settings-admin.css b/css/settings-admin.css deleted file mode 100644 index 9bf7d1d4ac..0000000000 --- a/css/settings-admin.css +++ /dev/null @@ -1,8 +0,0 @@ -#spreed_settings_form label { - min-width: 200px; - display: inline-block; -} - -#spreed_settings_form input { - width: 300px; -} diff --git a/css/settings-admin.scss b/css/settings-admin.scss new file mode 100644 index 0000000000..7e511b5dda --- /dev/null +++ b/css/settings-admin.scss @@ -0,0 +1,19 @@ +.videocalls.section { + input { + width: 300px; + } + + .icon-delete, + div.stun-server:last-child .icon-add { + display: inline-block; + } + + .error { + border-color: $color-error; + } + + label { + min-width: 200px; + display: inline-block; + } +} diff --git a/js/admin/stun-server.js b/js/admin/stun-server.js new file mode 100644 index 0000000000..af1cd9bfed --- /dev/null +++ b/js/admin/stun-server.js @@ -0,0 +1,100 @@ +/* global OC, OCP, OCA, $, _ */ + +(function(OC, OCP, OCA, $, _) { + 'use strict'; + + OCA.VideoCalls = OCA.VideoCalls || {}; + OCA.VideoCalls.Admin = OCA.VideoCalls.Admin || {}; + OCA.VideoCalls.Admin.StunServer = { + + TEMPLATE: '
' + + ' ' + + ' ' + + ' ' + + '
', + $list: undefined, + template: undefined, + + init: function() { + this.template = Handlebars.compile(this.TEMPLATE); + this.$list = $('div.stun-servers'); + this.renderList(); + }, + + 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('stun.nextcloud.com:443'); + } + }, + + addNewTemplate: function(server) { + server = server || ''; + this.$list.append( + this.renderServer(server) + ); + }, + + deleteServer: function(e) { + e.stopPropagation(); + + var $server = $(e.currentTarget).parents('div.stun-server').first(); + $server.remove(); + + this.saveServers(); + + if (this.$list.find('div.stun-server').length === 0) { + this.addNewTemplate('stun.nextcloud.com:443'); + } + + }, + + saveServers: function() { + var servers = []; + + this.$list.find('input').each(function() { + var server = this.value, + parts = server.split(':'); + if (parts.length !== 2) { + $(this).addClass('error'); + } else { + if (parts[1].match(/^([1-9]\d{0,4})$/) === null || + parseInt(parts[1]) > Math.pow(2, 16)) { //65536 + $(this).addClass('error'); + } else { + servers.push(this.value); + $(this).removeClass('error'); + } + } + }); + + OCP.AppConfig.setValue('spreed', 'stun_server', JSON.stringify(servers)); + }, + + renderServer: function(server) { + var $template = $(this.template({ + server: 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.StunServer.init(); +}); diff --git a/js/settings-admin.js b/js/settings-admin.js deleted file mode 100644 index 62036dbb52..0000000000 --- a/js/settings-admin.js +++ /dev/null @@ -1,13 +0,0 @@ -$(document).ready(function(){ - - $('#spreed_settings_form').change(function(){ - OC.msg.startSaving('#spreed_settings_msg'); - var post = $( "#spreed_settings_form" ).serialize(); - $.post(OC.generateUrl('/apps/spreed/settings/admin'), post, function(data){ - OC.msg.finishedSaving('#spreed_settings_msg', data); - }).fail(function(){ - OC.msg.finishedError('#spreed_settings_msg', t('spreed', 'Saving failed')); - }); - }); - -}); diff --git a/js/settings-personal.js b/js/settings-personal.js deleted file mode 100644 index d92bd8c01c..0000000000 --- a/js/settings-personal.js +++ /dev/null @@ -1,11 +0,0 @@ -$(document).ready(function(){ - - $('#spreed_settings_form').change(function(){ - OC.msg.startSaving('#spreed_settings_msg'); - var post = $("#spreed_settings_form").serialize(); - $.post(OC.generateUrl('/apps/spreed/settings/personal'), post, function(data){ - OC.msg.finishedSaving('#spreed_settings_msg', data); - }); - }); - -}); diff --git a/lib/Config.php b/lib/Config.php index c50c21b94a..736115e57e 100644 --- a/lib/Config.php +++ b/lib/Config.php @@ -47,7 +47,18 @@ class Config { * @return string */ public function getStunServer() { - return $this->config->getAppValue('spreed', 'stun_server', 'stun.nextcloud.com:443'); + $config = $this->config->getAppValue('spreed', 'stun_server', 'stun.nextcloud.com:443'); + $servers = json_decode($config); + + if ($servers === null) { + return $config ?: 'stun.nextcloud.com:443'; + } + + if (is_array($servers) && !empty($servers)) { + return $servers[mt_rand(0, count($servers) - 1)]; + } + + return 'stun.nextcloud.com:443'; } /** diff --git a/lib/Controller/AppSettingsController.php b/lib/Controller/AppSettingsController.php index 75827fad3b..ce5dfaf1c6 100644 --- a/lib/Controller/AppSettingsController.php +++ b/lib/Controller/AppSettingsController.php @@ -49,46 +49,14 @@ class AppSettingsController extends Controller { } /** - * Configure the settings of the Spreed app. The STUN server must be passed - * in the form "stunserver:port", e.g. "stun.domain.invalid:1234". + * Configure the settings of the Spreed app. * - * @param string $stun_server * @param string $turn_server * @param string $turn_server_secret + * @param string $turn_server_protocols + * @return array */ - public function setSpreedSettings($stun_server, $turn_server, $turn_server_secret, $turn_server_protocols) { - $stun_server = trim($stun_server); - if ($stun_server !== "") { - if (substr($stun_server, 0, 5) === "stun:") { - $stun_server = substr($stun_server, 5); - } - - $parts = explode(":", $stun_server); - if (count($parts) > 2) { - return array('data' => - array('message' => - (string) $this->l10n->t('Invalid format, must be stunserver:port.') - ), - 'status' => 'error' - ); - } - - $options = array( - 'options' => array( - 'default' => 0, - 'max_range' => 65535, - 'min_range' => 1, - ), - ); - if (count($parts) === 2 && !filter_var($parts[1], FILTER_VALIDATE_INT, $options)) { - return array('data' => - array('message' => - (string) $this->l10n->t('Invalid port specified.') - ), - 'status' => 'error' - ); - } - } + 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' => diff --git a/lib/Settings/AdminSection.php b/lib/Settings/Admin/Section.php similarity index 96% rename from lib/Settings/AdminSection.php rename to lib/Settings/Admin/Section.php index 4ba1fe767d..139844c275 100644 --- a/lib/Settings/AdminSection.php +++ b/lib/Settings/Admin/Section.php @@ -19,14 +19,14 @@ * */ -namespace OCA\Spreed\Settings; +namespace OCA\Spreed\Settings\Admin; use OCP\IL10N; use OCP\IURLGenerator; use OCP\Settings\IIconSection; -class AdminSection implements IIconSection { +class Section implements IIconSection { /** @var IL10N */ private $l; diff --git a/lib/Settings/Admin/StunServer.php b/lib/Settings/Admin/StunServer.php new file mode 100644 index 0000000000..129c67e6c9 --- /dev/null +++ b/lib/Settings/Admin/StunServer.php @@ -0,0 +1,70 @@ + + * + * @author Joas Schilling + * + * @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 . + * + */ + + +namespace OCA\Spreed\Settings\Admin; + + +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use OCP\Settings\ISettings; + +class StunServer implements ISettings { + + /** @var IConfig */ + private $config; + + public function __construct(IConfig $config) { + $this->config = $config; + } + + /** + * @return TemplateResponse + */ + public function getForm() { + $parameters = [ + 'stunServer' => $this->config->getAppValue('spreed', 'stun_server', 'stun.nextcloud.com:443'), + ]; + + return new TemplateResponse('spreed', 'settings/admin/stun-server', $parameters, ''); + } + + /** + * @return string the section ID, e.g. 'sharing' + */ + public function getSection() { + return 'stun_server'; + } + + /** + * @return int whether the form should be rather on the top or bottom of + * the admin section. The forms are arranged in ascending order of the + * priority values. It is required to return a value between 0 and 100. + * + * E.g.: 70 + */ + public function getPriority() { + return 65; + } + +} diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin/TurnServer.php similarity index 88% rename from lib/Settings/Admin.php rename to lib/Settings/Admin/TurnServer.php index 7bfe3938ca..f11bab0855 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin/TurnServer.php @@ -19,14 +19,14 @@ * */ -namespace OCA\Spreed\Settings; +namespace OCA\Spreed\Settings\Admin; use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\Settings\ISettings; -class Admin implements ISettings { +class TurnServer implements ISettings { /** @var IConfig */ private $config; @@ -40,13 +40,12 @@ class Admin implements ISettings { */ public function getForm() { $parameters = [ - 'stunServer' => $this->config->getAppValue('spreed', 'stun_server', 'stun.nextcloud.com:443'), 'turnServer' => $this->config->getAppValue('spreed', 'turn_server', ''), 'turnServerSecret' => $this->config->getAppValue('spreed', 'turn_server_secret', ''), 'turnServerProtocols' => $this->config->getAppValue('spreed', 'turn_server_protocols', ''), ]; - return new TemplateResponse('spreed', 'settings-admin', $parameters, ''); + return new TemplateResponse('spreed', 'settings/admin/turn-server', $parameters, ''); } /** diff --git a/templates/settings-admin.php b/templates/settings-admin.php deleted file mode 100644 index 4aeac411c2..0000000000 --- a/templates/settings-admin.php +++ /dev/null @@ -1,56 +0,0 @@ - - -
-
-

t('Video calls')) ?>

-

t('The STUN server is necessary so participants can connect to calls. The TURN server makes sure connection works even through firewalls.')); ?>

- - -

- - -

-

- t('The STUN server is used to determine the public IP address of participants behind a router.')) ?> -

-

- - -

-

- - -

-

- - -

-

- t('The TURN server is used to proxy the traffic from participants behind a firewall.')) ?> -

-
-
diff --git a/templates/settings/admin/stun-server.php b/templates/settings/admin/stun-server.php new file mode 100644 index 0000000000..7d93f680d6 --- /dev/null +++ b/templates/settings/admin/stun-server.php @@ -0,0 +1,14 @@ + + +
+

t('STUN servers')) ?>

+

t('A STUN server is used to determine the public IP address of participants behind a router.')); ?>

+ +
+
+
diff --git a/templates/settings/admin/turn-server.php b/templates/settings/admin/turn-server.php new file mode 100644 index 0000000000..19946828e2 --- /dev/null +++ b/templates/settings/admin/turn-server.php @@ -0,0 +1,40 @@ + + +
+

t('TURN server')) ?>

+

t('The TURN server is used to proxy the traffic from participants behind a firewall.')); ?>

+

+ + +

+

+ + +

+

+ + +

+