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

  1. <?php
  2. require __DIR__ . '/../vendor/autoload.php';
  3. $bootstrap = new Movim\Bootstrap;
  4. $bootstrap->boot(true);
  5. use App\Workers\Pusher\Pusher;
  6. use Psr\Http\Message\ServerRequestInterface;
  7. use React\EventLoop\Loop;
  8. use React\Http\HttpServer;
  9. use React\Promise\Promise;
  10. use React\Socket\SocketServer;
  11. $loop = Loop::get();
  12. $pusher = new Pusher;
  13. $handler = function (ServerRequestInterface $request) use ($pusher) {
  14. $data = json_decode((string)$request->getBody());
  15. return new Promise(function () use ($data, $pusher) {
  16. $pusher->send(
  17. userId: $data->user_id,
  18. linkerPushEndpoints: (array)$data->linker_push_endpoints,
  19. title: $data->title,
  20. tag: $data->tag,
  21. body: $data->body,
  22. picture: $data->picture,
  23. actions: $data->actions,
  24. data: (array)$data->data,
  25. );
  26. });
  27. };
  28. $server = new HttpServer($handler);
  29. $server->on('error', function (\Throwable $e) {
  30. \logError($e);
  31. });
  32. $path = 'unix://' . PUSHER_SOCKET;
  33. $server->listen(new SocketServer($path));