Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assign turn server protocols to template #198

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

$manager = \OC::$server->getNotificationManager();
$manager->registerNotifier(function() {
return \OC::$server->query('OCA\Spreed\Notification\Notifier');
return \OC::$server->query(\OCA\Spreed\Notification\Notifier::class);
}, function() {
$l = \OC::$server->getL10N('spreed');

Expand All @@ -46,7 +46,6 @@
});

\OC::$server->getUserManager()->listen('\OC\User', 'postDelete', function ($user) {
\OCA\Spreed\Util::deleteUser($user);
$listener = \OC::$server->query(\OCA\Spreed\HookListener::class);
$listener->deleteUser($user);
});

\OCP\App::registerPersonal('spreed', 'personal');
10 changes: 3 additions & 7 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@
namespace OCA\Spreed\AppInfo;

use OCP\AppFramework\App;
use OCA\Spreed\Controller\PersonalSettingsController;

class Application extends App {

public function __construct () {
parent::__construct('spreed');
$container = $this->getContainer();

$container->registerAlias('PersonalSettingsController', PersonalSettingsController::class);
}
public function __construct() {
parent::__construct('spreed');
}

}
86 changes: 86 additions & 0 deletions lib/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?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;

use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;

class Config {

/** @var IConfig */
protected $config;

/** @var ITimeFactory */
protected $timeFactory;

/**
* Config constructor.
*
* @param IConfig $config
* @param ITimeFactory $timeFactory
*/
public function __construct(IConfig $config, ITimeFactory $timeFactory) {
$this->config = $config;
$this->timeFactory = $timeFactory;
}

/**
* @return string
*/
public function getStunServer() {
return $this->config->getAppValue('spreed', 'stun_server', 'stun.nextcloud.com:443');
}

/**
* Generates a username and password for the TURN server
*
* @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', '');

if ($turnServer === '' || $turnServerSecret === '' || $turnServerProtocols === '') {
return [
'server' => '',
'username' => '',
'password' => '',
'protocols' => '',
];
}

// the 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);

return array(
'server' => $turnServer,
'username' => (string)$username,
'password' => $password,
'protocols' => $turnServerProtocols,
);
}

}
150 changes: 0 additions & 150 deletions lib/Controller/PersonalSettingsController.php

This file was deleted.

36 changes: 13 additions & 23 deletions lib/Controller/SignallingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,18 @@

namespace OCA\Spreed\Controller;

use OCA\Spreed\Config;
use OCA\Spreed\Exceptions\RoomNotFoundException;
use OCA\Spreed\Manager;
use OCA\Spreed\Room;
use OCA\Spreed\Util;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IRequest;
use OCP\ISession;

class SignallingController extends Controller {
/** @var IConfig */
/** @var Config */
private $config;
/** @var ISession */
private $session;
Expand All @@ -46,34 +44,29 @@ class SignallingController extends Controller {
private $dbConnection;
/** @var string */
private $userId;
/** @var ITimeFactory */
private $timeFactory;

/**
* @param string $appName
* @param IRequest $request
* @param IConfig $config
* @param Config $config
* @param ISession $session
* @param Manager $manager
* @param IDBConnection $connection
* @param string $UserId
* @param ITimeFactory $timeFactory
*/
public function __construct($appName,
IRequest $request,
IConfig $config,
Config $config,
ISession $session,
Manager $manager,
IDBConnection $connection,
$UserId,
ITimeFactory $timeFactory) {
$UserId) {
parent::__construct($appName, $request);
$this->config = $config;
$this->session = $session;
$this->dbConnection = $connection;
$this->manager = $manager;
$this->userId = $UserId;
$this->timeFactory = $timeFactory;
}

/**
Expand Down Expand Up @@ -117,28 +110,25 @@ public function signalling($messages) {
break;
case 'stunservers':
$response = [];
$stunServer = Util::getStunServer($this->config);
$stunServer = $this->config->getStunServer();
if ($stunServer) {
array_push($response, [
$response[] = [
'url' => 'stun:' . $stunServer,
]);
];
}
break;
case 'turnservers':
$response = [];
$turnSettings = Util::getTurnSettings($this->config, $this->userId);
if(empty($turnSettings)) {
$turnSettings = Util::generateTurnSettings($this->config, $this->timeFactory);
}
if (!empty($turnSettings)) {
$protocols = explode(",", $turnSettings['protocols']);
$turnSettings = $this->config->getTurnSettings();
if (!empty($turnSettings['server'])) {
$protocols = explode(',', $turnSettings['protocols']);
foreach ($protocols as $proto) {
array_push($response, [
$response[] = [
'url' => ['turn:' . $turnSettings['server'] . '?transport=' . $proto],
'urls' => ['turn:' . $turnSettings['server'] . '?transport=' . $proto],
'username' => $turnSettings['username'],
'credential' => $turnSettings['password'],
]);
];
}
}
break;
Expand Down
Loading