|
| 1 | +<?php |
| 2 | +namespace OCA\Solid\WellKnown; |
| 3 | + |
| 4 | +use OCP\IRequest; |
| 5 | +use OCP\IUserManager; |
| 6 | +use OCP\IURLGenerator; |
| 7 | +use OCP\IConfig; |
| 8 | + |
| 9 | +use OCP\AppFramework\Http\JSONResponse; |
| 10 | +use OCP\Http\WellKnown\IHandler; |
| 11 | +use OCP\Http\WellKnown\IRequestContext; |
| 12 | +use OCP\Http\WellKnown\IResponse; |
| 13 | + |
| 14 | +class SolidHandler implements IHandler { |
| 15 | + /* @var IURLGenerator */ |
| 16 | + private $urlGenerator; |
| 17 | + |
| 18 | + public function __construct(IRequest $request, IURLGenerator $urlGenerator, IConfig $config, IUserManager $userManager) |
| 19 | + { |
| 20 | + require_once(__DIR__.'/../../vendor/autoload.php'); |
| 21 | + $this->urlGenerator = $urlGenerator; |
| 22 | + } |
| 23 | + |
| 24 | + public function handle(string $service, IRequestContext $context, ?IResponse $previousResponse): ?IResponse { |
| 25 | + if ($service !== 'solid') { |
| 26 | + return $previousResponse; |
| 27 | + } |
| 28 | + |
| 29 | + $body = [ |
| 30 | + "@context" => [ |
| 31 | + "https://www.w3.org/ns/solid/notification/v1" |
| 32 | + ], |
| 33 | + "notificationChannel" => [ |
| 34 | + [ |
| 35 | + "id" => "websocketNotification", |
| 36 | + "type" => ["WebSocketSubscription2021"], |
| 37 | + "subscription" => "https://websocket.example/subscription", |
| 38 | + "feature" => ["state", "rate", "expiration"] |
| 39 | + ] |
| 40 | + ] |
| 41 | + ]; |
| 42 | + $result = new JSONResponse($body); |
| 43 | + $result->addHeader("Access-Control-Allow-Origin", "*"); |
| 44 | + $result->setStatus(200); |
| 45 | + return $result; |
| 46 | + } |
| 47 | +} |
0 commit comments