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

Standalone signaling support #366

Merged
merged 31 commits into from
Nov 2, 2017
Merged

Standalone signaling support #366

merged 31 commits into from
Nov 2, 2017

Conversation

fancycode
Copy link
Member

@fancycode fancycode commented Jul 20, 2017

This PR adds support for using a standalone signaling server.

See https://github.com/nextcloud/spreed/wiki/Spreed-Signaling-API for the documentation of message formats. In a follow-up PR, the same messages will be implemented for the PHP backend, so there is only one API that clients need to implement.

@nickvergessen @Ivansss

@codecov
Copy link

codecov bot commented Jul 20, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@d7ef5ef). Click here to learn what that means.
The diff coverage is 1.32%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #366   +/-   ##
=========================================
  Coverage          ?   10.32%           
  Complexity        ?      394           
=========================================
  Files             ?       23           
  Lines             ?     1975           
  Branches          ?        0           
=========================================
  Hits              ?      204           
  Misses            ?     1771           
  Partials          ?        0
Impacted Files Coverage Δ Complexity Δ
appinfo/app.php 0% <ø> (ø) 0 <0> (?)
lib/AppInfo/Application.php 0% <0%> (ø) 3 <2> (?)
lib/Controller/PageController.php 0% <0%> (ø) 20 <4> (?)
lib/Controller/RoomController.php 0% <0%> (ø) 94 <0> (?)
lib/Controller/AppSettingsController.php 0% <0%> (ø) 19 <18> (?)
appinfo/routes.php 0% <0%> (ø) 0 <0> (?)
lib/BackendNotifier.php 0% <0%> (ø) 13 <13> (?)
lib/Controller/SignallingController.php 0% <0%> (ø) 37 <16> (?)
lib/Manager.php 0% <0%> (ø) 45 <1> (?)
lib/Room.php 0% <0%> (ø) 42 <3> (?)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d7ef5ef...85bdea6. Read the comment docs.

@fancycode fancycode force-pushed the standalone-signaling branch 2 times, most recently from 03a5bb1 to efd0986 Compare July 25, 2017 10:37
@fancycode
Copy link
Member Author

@nickvergessen @Ivansss this is now ready for some testing 😃

@fancycode fancycode changed the title [WIP] Standalone signaling support Standalone signaling support Aug 1, 2017
@fancycode
Copy link
Member Author

@nickvergessen @Ivansss this is now pending for quite some time - would be great to get some feedback...

@fancycode fancycode mentioned this pull request Sep 1, 2017
@nickvergessen
Copy link
Member

I will have a look on monday/tuesday, sorry conf was too busy

if (!filter_var($server, FILTER_VALIDATE_URL)) {
return array('data' =>
array('message' =>
(string) $this->l10n->t('Invalid signaling server url.')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cast is not required anymore

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency I would rather keep this aligned with surrounding code and remove the cast here and in other locations in a follow-up PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, same as in the comment below, just ignore for now ;)

$servers = explode('\n', $signaling_server);
foreach($servers as $server) {
if (!filter_var($server, FILTER_VALIDATE_URL)) {
return array('data' =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use the short array syntax [ ]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, just saw you only copy pasted, so okay

@@ -55,8 +55,11 @@ public function __construct($appName,
* @param string $stun_server
* @param string $turn_server
* @param string $turn_server_secret
* @param string $signaling_server
* @param string $signaling_secret
* @param string $signaling_skip_verify_cert
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

order is mixed up
can you also add $turn_server_protocols to the docs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

}

$currentSignalingSkipVerifyCert = $this->config->getAppValue('spreed', 'signaling_skip_verify_cert', '');
if ($signaling_skip_verify_cert === null) {
Copy link
Member

@nickvergessen nickvergessen Sep 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$signaling_skip_verify_cert = (string) $signaling_skip_verify_cert;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't understand what you want to have changed here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You set the variable to an empty string when it is null, so you can also just cast it to string, getting rid of the if-block. Should have the same result?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

php magic 🙈

@@ -305,6 +310,11 @@ protected function createOneToOneRoom($targetUserName) {
$room->addParticipant($targetUser->getUID(), Participant::OWNER);
$this->createNotification($currentUser, $targetUser, $room);

$this->backend->roomInvited($room, [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would move this into the methods of the Room class.
For better decoupling we could also trigger a hook? This would allow any app to listen to those events and provide a signaling backend?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now updated to use events in the latest commit.

@@ -76,6 +82,11 @@ public function __construct($appName,
* @return JSONResponse
*/
public function signalling($messages) {
$signaling = $this->config->getSignalingServer();
if (!empty($signaling)) {
throw new \Exception('Internal signaling disabled.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should return new JSONResponse('Internal signaling disabled.', Http::STATUS_BAD_REQUEST); instead of throwing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

* @return JSONResponse
*/
public function backend() {
$json = file_get_contents('php://input');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't you use $this->request ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->request is a OCP\IRequest which only provides access to the request variables / -headers but I need the body of the request. Maybe there is a better way to get that - if so I didn't find it ;-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you post a json body to the server using parameters instead of the body? ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean sending a body body=the-json-object and then using the value of variable body? That sounds hackish ;-)

use OCP\IRequest;
use OCP\Security\ISecureRandom;

class BackendController extends Controller {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This controller has no routes, drop it?
Or you forgot to commit something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer a controller now.

* @param Room $room
* @param array $userIds
*/
public function roomInvited($room, $userIds) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is only reachable for admins, right?

@nickvergessen
Copy link
Member

The main question is at which point the things should be decoupled.
I guess currently this app contains the bridge code as well, right?
So that the "external" signalings can focus on signaling instead of also having to do the php app code to listen to the events, etc?

lib/Room.php Outdated
'type' => $participantType,
'sessionId' => $sessionId,
]));
foreach ($participants as &$participant) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the reference &

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

lib/Room.php Outdated
'sessionId' => $sessionId,
]));
foreach ($participants as &$participant) {
$query = $this->db->getQueryBuilder();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create this outside of the foreach, use $query->createParameter('userId') and so on, and inside the loop just call setParameter('userId', $participant)->setParameter(....); $query->execute();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

$notifier = $this->getContainer()->query(BackendNotifier::class);

$dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
$dispatcher->addListener('\OCA\Spreed\Room::postAddParticipants', function($event) use ($notifier) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use ->addListener(Room::class . '::postAddParticipants') like we do in other places as well already

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed. I based my code on the dav app, where the complete strings are used - using the classes makes more sense though!

lib/Room.php Outdated
@@ -146,6 +152,8 @@ public function getParticipant($userId) {
}

public function deleteRoom() {
$this->dispatcher->dispatch('\OCA\Spreed\Room::preDeleteRoom',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self::class . '::preDeleteRoom'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

@fancycode fancycode force-pushed the standalone-signaling branch from eced7a5 to 8f912a7 Compare September 6, 2017 15:01
@fancycode
Copy link
Member Author

Rebased to current master.

fancycode and others added 21 commits November 2, 2017 11:23
Signed-off-by: Joachim Bauch <bauch@struktur.de>
Signed-off-by: Joachim Bauch <bauch@struktur.de>
Signed-off-by: Joachim Bauch <bauch@struktur.de>
Signed-off-by: Joachim Bauch <bauch@struktur.de>
Signed-off-by: Joachim Bauch <bauch@struktur.de>
Signed-off-by: Joachim Bauch <bauch@struktur.de>
…s disabled.

Signed-off-by: Joachim Bauch <bauch@struktur.de>
Signed-off-by: Joachim Bauch <bauch@struktur.de>
Signed-off-by: Joachim Bauch <bauch@struktur.de>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joachim Bauch <bauch@struktur.de>
Signed-off-by: Joachim Bauch <bauch@struktur.de>
…date users.

Signed-off-by: Joachim Bauch <bauch@struktur.de>
Signed-off-by: Joachim Bauch <bauch@struktur.de>
Signed-off-by: Joachim Bauch <bauch@struktur.de>
Signed-off-by: Joachim Bauch <bauch@struktur.de>
This is necessary so the post-handlers can perform actions on the users
that were previously invited (but that already have been removed from
the DB)

Signed-off-by: Joachim Bauch <bauch@struktur.de>
Signed-off-by: Joachim Bauch <bauch@struktur.de>
Signed-off-by: Joachim Bauch <bauch@struktur.de>
Signed-off-by: Joachim Bauch <bauch@struktur.de>
Signed-off-by: Joachim Bauch <bauch@struktur.de>
@fancycode fancycode force-pushed the standalone-signaling branch from 0b285f6 to 6d13722 Compare November 2, 2017 10:24
@fancycode
Copy link
Member Author

Rebased again.

Copy link
Member

@nickvergessen nickvergessen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normal signaling still works

@nickvergessen
Copy link
Member

Linting fail is unrelated

Signed-off-by: Joas Schilling <coding@schilljs.com>
@nickvergessen
Copy link
Member

Only increased the version to trigger update of the settings again.

Merging

@nickvergessen nickvergessen merged commit 08b470a into master Nov 2, 2017
@nickvergessen nickvergessen deleted the standalone-signaling branch November 2, 2017 12:15
marcoambrosini pushed a commit that referenced this pull request Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review enhancement feature: signaling 📶 Internal and external signaling backends
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants