From 4f0dd410286747a79253dbac4898207a2768bc74 Mon Sep 17 00:00:00 2001 From: a6a2f5842 Date: Thu, 12 Jun 2025 16:16:07 +0200 Subject: [PATCH] I added better error display --- src/Websocket/Handler.php | 60 ++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/src/Websocket/Handler.php b/src/Websocket/Handler.php index 91a32d3..37f2cea 100644 --- a/src/Websocket/Handler.php +++ b/src/Websocket/Handler.php @@ -41,34 +41,42 @@ class Handler implements MessageComponentInterface public function onOpen(ConnectionInterface $connection) { - if (! $this->connectionCanBeMade($connection)) { - return $connection->close(); - } + try{ + if (! $this->connectionCanBeMade($connection)) { + return $connection->close(); + } - // Set IP to connection - $connection->remoteAddress = trim( - explode( - ',', - $connection->httpRequest->getHeaderLine('X-Forwarded-For') - )[0] ?? $connection->remoteAddress - ); - request()->server->set('REMOTE_ADDR', $connection->remoteAddress); - Log::channel('websocket')->info('WS onOpen IP: ' . $connection->remoteAddress); - - $this->verifyAppKey($connection); - $this->verifyOrigin($connection); - $this->limitConcurrentConnections($connection); - $this->generateSocketId($connection); - $this->establishConnection($connection); - - if (isset($connection->app)) { - $this->channelManager->subscribeToApp($connection->app->id); - $this->channelManager->connectionPonged($connection); - - NewConnection::dispatch( - $connection->app->id, - $connection->socketId + // Set IP to connection + $connection->remoteAddress = trim( + explode( + ',', + $connection->httpRequest->getHeaderLine('X-Forwarded-For') + )[0] ?? $connection->remoteAddress ); + request()->server->set('REMOTE_ADDR', $connection->remoteAddress); + Log::channel('websocket')->info('WS onOpen IP: ' . $connection->remoteAddress); + + $this->verifyAppKey($connection); + $this->verifyOrigin($connection); + $this->limitConcurrentConnections($connection); + $this->generateSocketId($connection); + $this->establishConnection($connection); + + if (isset($connection->app)) { + $this->channelManager->subscribeToApp($connection->app->id); + $this->channelManager->connectionPonged($connection); + + NewConnection::dispatch( + $connection->app->id, + $connection->socketId + ); + } + }catch (UnknownAppKey $e) { + Log::channel('websocket')->error('Root level error: '. $e->getMessage(), [ + 'file' => $e->getFile(), + 'line' => $e->getLine(), + 'trace' => $e->getTraceAsString(), + ]); } }