Skip to content

Commit ebfdaa4

Browse files
Merge pull request #4010 from nextcloud/enh/matterbridge-backend
[PoC] [WIP] Matterbridge integration
2 parents 2243713 + 4700152 commit ebfdaa4

File tree

18 files changed

+1959
-8
lines changed

18 files changed

+1959
-8
lines changed

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m
1616
1717
]]></description>
1818

19-
<version>10.0.0-dev.3</version>
19+
<version>10.0.0-dev.4</version>
2020
<licence>agpl</licence>
2121

2222
<author>Daniel Calviño Sánchez</author>

appinfo/routes.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,56 @@
363363
],
364364
],
365365

366+
/**
367+
* Bridge settings
368+
*/
369+
[
370+
'name' => 'MatterbridgeSettings#stopAllBridges',
371+
'url' => '/api/{apiVersion}/bridge',
372+
'verb' => 'DELETE',
373+
'requirements' => [
374+
'apiVersion' => 'v1',
375+
],
376+
],
377+
[
378+
'name' => 'MatterbridgeSettings#getMatterbridgeVersion',
379+
'url' => '/api/{apiVersion}/bridge/version',
380+
'verb' => 'GET',
381+
'requirements' => [
382+
'apiVersion' => 'v1',
383+
],
384+
],
385+
386+
/**
387+
* Bridges
388+
*/
389+
[
390+
'name' => 'Matterbridge#getBridgeOfRoom',
391+
'url' => '/api/{apiVersion}/bridge/{token}',
392+
'verb' => 'GET',
393+
'requirements' => [
394+
'apiVersion' => 'v1',
395+
'token' => '^[a-z0-9]{4,30}$',
396+
],
397+
],
398+
[
399+
'name' => 'Matterbridge#editBridgeOfRoom',
400+
'url' => '/api/{apiVersion}/bridge/{token}',
401+
'verb' => 'PUT',
402+
'requirements' => [
403+
'apiVersion' => 'v1',
404+
'token' => '^[a-z0-9]{4,30}$',
405+
],
406+
],
407+
[
408+
'name' => 'Matterbridge#deleteBridgeOfRoom',
409+
'url' => '/api/{apiVersion}/bridge/{token}',
410+
'verb' => 'DELETE',
411+
'requirements' => [
412+
'apiVersion' => 'v1',
413+
'token' => '^[a-z0-9]{4,30}$',
414+
],
415+
],
366416

367417
/**
368418
* PublicShareAuth

css/settings-admin.scss

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@
4646
}
4747

4848

49-
.commands.section {
49+
.commands.section,
50+
.matterbridge.section {
5051
.icon-beta-feature {
5152
@include icon-color('customization', 'categories', $color-warning, 1, true);
5253
}
54+
}
5355

54-
p.settings-hint > a {
55-
text-decoration: underline !important;
56-
}
57-
56+
.commands.section {
5857
#commands_list {
5958
display: grid;
6059
grid-template-columns: minmax(100px, 200px) minmax(100px, 200px) 1fr minmax(100px, 200px) minmax(100px, 200px);

img/bridge-bot.png

2.97 KB
Loading
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2020 Julien Veyssier <[email protected]>
6+
*
7+
* @author Julien Veyssier <[email protected]>
8+
*
9+
* @license GNU AGPL version 3 or any later version
10+
*
11+
* This program is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU Affero General Public License as
13+
* published by the Free Software Foundation, either version 3 of the
14+
* License, or (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*
24+
*/
25+
26+
namespace OCA\Talk\Controller;
27+
28+
use OCA\Talk\Exceptions\ImpossibleToKillException;
29+
use OCA\Talk\Manager;
30+
use OCA\Talk\MatterbridgeManager;
31+
use OCP\AppFramework\Http;
32+
use OCP\AppFramework\Http\DataResponse;
33+
use OCP\IRequest;
34+
35+
class MatterbridgeController extends AEnvironmentAwareController {
36+
/** @var string|null */
37+
protected $userId;
38+
/** @var Manager */
39+
protected $manager;
40+
/** @var MatterbridgeManager */
41+
protected $bridgeManager;
42+
43+
public function __construct(string $appName,
44+
?string $UserId,
45+
IRequest $request,
46+
Manager $manager,
47+
MatterbridgeManager $bridgeManager) {
48+
parent::__construct($appName, $request);
49+
$this->userId = $UserId;
50+
$this->manager = $manager;
51+
$this->bridgeManager = $bridgeManager;
52+
}
53+
54+
/**
55+
* Get bridge information of one room
56+
*
57+
* @NoAdminRequired
58+
* @RequireLoggedInModeratorParticipant
59+
*
60+
* @return DataResponse
61+
*/
62+
public function getBridgeOfRoom(): DataResponse {
63+
$this->bridgeManager->checkBridge($this->room);
64+
$bridge = $this->bridgeManager->getBridgeOfRoom($this->room);
65+
return new DataResponse($bridge);
66+
}
67+
68+
/**
69+
* Edit bridge information of one room
70+
*
71+
* @NoAdminRequired
72+
* @RequireLoggedInModeratorParticipant
73+
*
74+
* @param bool $enabled
75+
* @param array $parts
76+
* @return DataResponse
77+
*/
78+
public function editBridgeOfRoom(bool $enabled, array $parts = []): DataResponse {
79+
try {
80+
$success = $this->bridgeManager->editBridgeOfRoom($this->room, $enabled, $parts);
81+
} catch (ImpossibleToKillException $e) {
82+
return new DataResponse(['error' => $e->getMessage()], Http::STATUS_NOT_ACCEPTABLE);
83+
}
84+
return new DataResponse($success);
85+
}
86+
87+
/**
88+
* Delete bridge of one room
89+
*
90+
* @NoAdminRequired
91+
* @RequireLoggedInModeratorParticipant
92+
*
93+
* @return DataResponse
94+
*/
95+
public function deleteBridgeOfRoom(): DataResponse {
96+
try {
97+
$success = $this->bridgeManager->deleteBridgeOfRoom($this->room);
98+
} catch (ImpossibleToKillException $e) {
99+
return new DataResponse(['error' => $e->getMessage()], Http::STATUS_NOT_ACCEPTABLE);
100+
}
101+
return new DataResponse($success);
102+
}
103+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2020 Joas Schilling <[email protected]>
6+
*
7+
* @author Joas Schilling <[email protected]>
8+
*
9+
* @license GNU AGPL version 3 or any later version
10+
*
11+
* This program is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU Affero General Public License as
13+
* published by the Free Software Foundation, either version 3 of the
14+
* License, or (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*
24+
*/
25+
26+
namespace OCA\Talk\Controller;
27+
28+
use OCA\Talk\MatterbridgeManager;
29+
use OCA\Talk\Exceptions\ImpossibleToKillException;
30+
use OCP\AppFramework\Http;
31+
use OCP\AppFramework\Http\DataResponse;
32+
use OCP\AppFramework\OCSController;
33+
use OCP\IRequest;
34+
35+
class MatterbridgeSettingsController extends OCSController {
36+
/** @var MatterbridgeManager */
37+
protected $bridgeManager;
38+
39+
public function __construct(string $appName,
40+
IRequest $request,
41+
MatterbridgeManager $bridgeManager) {
42+
parent::__construct($appName, $request);
43+
$this->bridgeManager = $bridgeManager;
44+
}
45+
46+
/**
47+
* Get Matterbridge version
48+
*
49+
* @return DataResponse
50+
*/
51+
public function getMatterbridgeVersion(): DataResponse {
52+
$version = $this->bridgeManager->getCurrentVersionFromBinary();
53+
if ($version === null) {
54+
return new DataResponse([
55+
'error' => 'binary',
56+
], Http::STATUS_BAD_REQUEST);
57+
}
58+
59+
return new DataResponse([
60+
'version' => $version,
61+
]);
62+
}
63+
64+
/**
65+
* Stop all bridges
66+
*
67+
* @return DataResponse
68+
*/
69+
public function stopAllBridges(): DataResponse {
70+
try {
71+
$success = $this->bridgeManager->stopAllBridges();
72+
} catch (ImpossibleToKillException $e) {
73+
return new DataResponse(['error' => $e->getMessage()], Http::STATUS_NOT_ACCEPTABLE);
74+
}
75+
return new DataResponse($success);
76+
}
77+
}

lib/Controller/PageController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ public function index(string $token = '', string $callUser = '', string $passwor
249249
}
250250

251251
$this->publishInitialStateForUser($user, $this->rootFolder, $this->appManager);
252+
$this->initialStateService->provideInitialState('talk', 'enable_matterbridge', $this->serverConfig->getAppValue('spreed', 'enable_matterbridge', '0') === '1');
252253

253254
if (class_exists(LoadViewer::class)) {
254255
$this->eventDispatcher->dispatchTyped(new LoadViewer());
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2020 Julien Veyssier <[email protected]>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
25+
namespace OCA\Talk\Exceptions;
26+
27+
class ImpossibleToKillException extends \Exception {
28+
}

0 commit comments

Comments
 (0)