diff --git a/config/websockets.php b/config/websockets.php index e36f3cd..36c8c14 100644 --- a/config/websockets.php +++ b/config/websockets.php @@ -267,6 +267,8 @@ return [ 'websocket' => \BeyondCode\LaravelWebSockets\Server\WebSocketHandler::class, + 'health' => \BeyondCode\LaravelWebSockets\Server\HealthHandler::class, + 'trigger_event' => \BeyondCode\LaravelWebSockets\API\TriggerEvent::class, 'fetch_channels' => \BeyondCode\LaravelWebSockets\API\FetchChannels::class, diff --git a/src/Server/HealthHandler.php b/src/Server/HealthHandler.php new file mode 100644 index 0000000..75fa90f --- /dev/null +++ b/src/Server/HealthHandler.php @@ -0,0 +1,65 @@ + 'application/json'], + json_encode(['ok' => true]) + ); + + tap($connection)->send(\GuzzleHttp\Psr7\str($response))->close(); + } + + /** + * Handle the incoming message. + * + * @param \Ratchet\ConnectionInterface $connection + * @param \Ratchet\RFC6455\Messaging\MessageInterface $message + * @return void + */ + public function onMessage(ConnectionInterface $connection, MessageInterface $message) + { + // + } + + /** + * Handle the websocket close. + * + * @param \Ratchet\ConnectionInterface $connection + * @return void + */ + public function onClose(ConnectionInterface $connection) + { + // + } + + /** + * Handle the websocket errors. + * + * @param \Ratchet\ConnectionInterface $connection + * @param WebSocketException $exception + * @return void + */ + public function onError(ConnectionInterface $connection, Exception $exception) + { + // + } +} diff --git a/src/Server/Router.php b/src/Server/Router.php index d0ce199..bda9878 100644 --- a/src/Server/Router.php +++ b/src/Server/Router.php @@ -49,6 +49,7 @@ class Router $this->get('/apps/{appId}/channels', config('websockets.handlers.fetch_channels')); $this->get('/apps/{appId}/channels/{channelName}', config('websockets.handlers.fetch_channel')); $this->get('/apps/{appId}/channels/{channelName}/users', config('websockets.handlers.fetch_users')); + $this->get('/health', config('websockets.handlers.health')); } /** diff --git a/tests/HealthTest.php b/tests/HealthTest.php new file mode 100644 index 0000000..61da8ef --- /dev/null +++ b/tests/HealthTest.php @@ -0,0 +1,22 @@ +newConnection(); + + $this->pusherServer = app(HealthHandler::class); + + $this->pusherServer->onOpen($connection); + + $this->assertTrue( + Str::contains($connection->sentRawData[0], '{"ok":true}') + ); + } +}