Skip to content

Commit 5a3b128

Browse files
add websockets subscribe endpoint
1 parent 22636a6 commit 5a3b128

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

solid/appinfo/routes.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@
5454
['name' => 'solidWebhook#listWebhooks', 'url' => '/webhook/list', 'verb' => 'GET'],
5555
['name' => 'solidWebhook#register', 'url' => '/webhook/register', 'verb' => 'POST'],
5656
['name' => 'solidWebhook#unregister', 'url' => '/webhook/unregister', 'verb' => 'POST'],
57-
57+
58+
['name' => 'solidWebsocket#register', 'url' => '/websocket/register', 'verb' => 'POST'],
59+
5860
['name' => 'app#appLauncher', 'url' => '/', 'verb' => 'GET'],
5961
]
6062
];
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace OCA\Solid\Controller;
4+
5+
use OCP\AppFramework\Controller;
6+
use OCP\AppFramework\Http\DataResponse;
7+
8+
class SolidWebhookController extends Controller
9+
{
10+
/**
11+
* @PublicPage
12+
* @NoAdminRequired
13+
* @NoCSRFRequired
14+
*/
15+
public function register(): DataResponse
16+
{
17+
$pubsub = getenv("PUBSUB_URL") ?: "http://pubsub:8080";
18+
return new DataResponse([
19+
"@context" => "https://www.w3.org/ns/solid/notification/v1",
20+
"type" => "WebSocketSubscription2021",
21+
"source" => $pubsub . "/?type=WebSocketSubscription2021"
22+
]);
23+
}
24+
}

solid/lib/WellKnown/SolidHandler.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public function handle(string $service, IRequestContext $context, ?IResponse $pr
3131
if (strlen($webhooksRegisterEndpoint) == 0) {
3232
$webhooksRegisterEndpoint = $this->urlGenerator->linkToRoute('solid.app.appLauncher') . 'webhook/register';
3333
}
34+
35+
$websocketsRegisterEndpoint = $this->urlGenerator->linkToRoute('solid.solidWebsocket.register');
36+
// FIXME: this shouldn't happen:
37+
if (strlen($websocketsRegisterEndpoint) == 0) {
38+
$websocketsRegisterEndpoint = $this->urlGenerator->linkToRoute('solid.app.appLauncher') . 'websocket/register';
39+
}
3440
$body = [
3541
"@context" => [
3642
"https://www.w3.org/ns/solid/notification/v1"
@@ -39,6 +45,7 @@ public function handle(string $service, IRequestContext $context, ?IResponse $pr
3945
[
4046
"id" => "websocketNotification",
4147
"type" => ["WebSocketSubscription2021"],
48+
"subscription" => $websocketsRegisterEndpoint,
4249
"feature" => []
4350
],
4451
[

0 commit comments

Comments
 (0)