1
0
Fork 0

implemented draft spec of web push transport

This commit is contained in:
Jonathan Treffler 2024-06-17 15:23:21 +02:00
parent e0f6f3d27a
commit b0335735fe

View file

@ -27,18 +27,49 @@ declare(strict_types=1);
namespace OCA\DavPush\PushTransports; namespace OCA\DavPush\PushTransports;
use OCA\DavPush\Transport\Transport; use OCA\DavPush\Transport\Transport;
use Sabre\Xml\Service;
class WebPushTransport extends Transport { class WebPushTransport extends Transport {
protected $id = "web-push"; protected $id = "web-push";
public function registerSubscription($options) { public function registerSubscription($options) {
return [ $pushResource = False;
'success' => True,
'response' => "web push test", foreach($options as $option) {
]; if ($option["name"] == "{DAV:Push}push-resource") {
$pushResource = $option["value"];
}
}
if($pushResource) {
return [
'success' => True,
'response' => "",
'data' => [ "pushResource" => $pushResource ],
];
} else {
return [
'success' => False,
'error' => "push resource not provided",
];
}
} }
public function notify(string $userId, string $collectionName, $data) { public function notify(string $userId, string $collectionName, $data) {
$xmlService = new Service();
$content = $xmlService->write('{DAV:Push}push-message', [
'topic' => $collectionName,
]);
$options = [
'http' => [
'method' => 'POST',
'content' => $content,
],
];
$context = stream_context_create($options);
$result = file_get_contents($data["pushResource"], false, $context);
} }
} }