-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TURN server to personal settings.
This implements the second part of #2 to add TURN support. For now each user has to have an account on the TURN server. Support for shared credentials will be added in a separate PR.
- Loading branch information
1 parent
c48d740
commit 930adb5
Showing
9 changed files
with
238 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
$(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); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
/** | ||
* @author Joachim Bauch <[email protected]> | ||
* | ||
* @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; | ||
use OCP\IUserSession; | ||
|
||
class PersonalSettingsController extends Controller { | ||
|
||
/** @var IL10N */ | ||
private $l10n; | ||
/** @var IConfig */ | ||
private $config; | ||
/** | ||
* @var bool|IUser | ||
*/ | ||
private $user; | ||
|
||
/** | ||
* @param string $appName | ||
* @param IRequest $request | ||
* @param IL10N $l10n | ||
* @param IConfig $config | ||
* @param IUserSession $userSession | ||
*/ | ||
public function __construct($appName, | ||
IRequest $request, | ||
IL10N $l10n, | ||
IConfig $config, | ||
IUserSession $userSession) { | ||
parent::__construct($appName, $request); | ||
$this->l10n = $l10n; | ||
$this->config = $config; | ||
$this->user = $userSession && $userSession->isLoggedIn() ? $userSession->getUser() : false; | ||
} | ||
|
||
/** | ||
* Configure the personal settings of the Spreed app. The TURN server must | ||
* be passed in the form "turnserver:port", e.g. "turn.domain.invalid:1234". | ||
* | ||
* @NoAdminRequired | ||
* @param string $turn_server | ||
* @param string $turn_username | ||
* @param string $turn_password | ||
* @param string $turn_protocols | ||
*/ | ||
public function setSpreedSettings($turn_server, $turn_username, $turn_password, $turn_protocols) { | ||
if (!$this->user) { | ||
return array('data' => | ||
array('message' => | ||
(string) $this->l10n->t('Not logged in.') | ||
), | ||
'status' => 'error' | ||
); | ||
} | ||
|
||
$turn_server = trim($turn_server); | ||
if ($turn_server !== "") { | ||
$parts = explode(":", $turn_server); | ||
if (count($parts) > 2) { | ||
return array('data' => | ||
array('message' => | ||
(string) $this->l10n->t('Invalid format, must be turnserver: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' | ||
); | ||
} | ||
} | ||
|
||
if (empty($turn_server) || empty($turn_username) || empty($turn_password)) { | ||
return array('data' => | ||
array('message' => | ||
(string) $this->l10n->t('All fields have to be filled out.') | ||
), | ||
'status' => 'error' | ||
); | ||
} | ||
|
||
$turn_settings = array( | ||
'server' => $turn_server, | ||
'username' => $turn_username, | ||
'password' => $turn_password, | ||
'protocols' => $turn_protocols | ||
); | ||
|
||
$this->config->setUserValue($this->user->getUID(), | ||
'spreed', | ||
'turn_settings', | ||
json_encode($turn_settings)); | ||
return array('data' => | ||
array('message' => | ||
(string) $this->l10n->t('Saved') | ||
), | ||
'status' => 'success' | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
use OCA\Spreed\Util; | ||
|
||
\OC_Util::checkLoggedIn(); | ||
|
||
$tmpl = new OCP\Template('spreed', 'settings-personal'); | ||
$config = \OC::$server->getConfig(); | ||
$uid = \OC::$server->getUserSession()->getUser()->getUID(); | ||
|
||
$settings = Util::getTurnSettings($config, $uid); | ||
//server":"1","username":"2","password":"3","protocols | ||
$tmpl->assign('turnSettings', $settings); | ||
return $tmpl->fetchPage(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
script('spreed', ['settings-personal']); | ||
?> | ||
|
||
<div id="spreedSettings" class="section"> | ||
<form id="spreed_settings_form" class="spreed_settings"> | ||
<h2><?php p($l->t('Spreed')); ?></h2> | ||
<p> | ||
<?php p($l->t('The TURN server is used to relay audio/video streams in cases where the participants can\'t connect directly to each other.')) ?> | ||
</p> | ||
<span id="spreed_settings_msg" class="msg"></span> | ||
<p> | ||
<label for="turn_server"><?php p($l->t('TURN server')) ?></label> | ||
<input type="text" id="turn_server" | ||
name="turn_server" placeholder="turnserver:port" | ||
value="<?php p($_['turnSettings']['server']) ?>" /> | ||
</p> | ||
<p> | ||
<label for="turn_username"><?php p($l->t('Username')) ?></label> | ||
<input type="text" id="turn_username" | ||
name="turn_username" placeholder="username" | ||
value="<?php p($_['turnSettings']['username']) ?>" /> | ||
</p> | ||
<p> | ||
<label for="turn_password"><?php p($l->t('Password')) ?></label> | ||
<input type="text" id="turn_password" | ||
name="turn_password" placeholder="password" | ||
value="<?php p($_['turnSettings']['password']) ?>" /> | ||
</p> | ||
<p> | ||
<label for="turn_protocols"><?php p($l->t('Protocols')) ?></label> | ||
<select id="turn_protocols" name="turn_protocols"> | ||
<option value="udp,tcp" | ||
<?php p($_['turnSettings']['protocols'] === 'udp,tcp' ? 'selected' : '') ?>> | ||
udp and tcp</option> | ||
<option value="udp" | ||
<?php p($_['turnSettings']['protocols'] === 'udp' ? 'selected' : '') ?>> | ||
udp only</option> | ||
<option value="tcp" | ||
<?php p($_['turnSettings']['protocols'] === 'tcp' ? 'selected' : '') ?>> | ||
tcp only</option> | ||
</select> | ||
</p> | ||
</form> | ||
</div> |