You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

41 lines
1.0 KiB

<?php
require __DIR__ . '/../vendor/autoload.php';
$bootstrap = new Movim\Bootstrap;
$bootstrap->boot(true);
use App\Workers\Pusher\Pusher;
use Psr\Http\Message\ServerRequestInterface;
use React\EventLoop\Loop;
use React\Http\HttpServer;
use React\Promise\Promise;
use React\Socket\SocketServer;
$loop = Loop::get();
$pusher = new Pusher;
$handler = function (ServerRequestInterface $request) use ($pusher) {
$data = json_decode((string)$request->getBody());
return new Promise(function () use ($data, $pusher) {
$pusher->send(
userId: $data->user_id,
linkerPushEndpoints: (array)$data->linker_push_endpoints,
title: $data->title,
tag: $data->tag,
body: $data->body,
picture: $data->picture,
actions: $data->actions,
data: (array)$data->data,
);
});
};
$server = new HttpServer($handler);
$server->on('error', function (\Throwable $e) {
\logError($e);
});
$path = 'unix://' . PUSHER_SOCKET;
$server->listen(new SocketServer($path));