I added better error display

This commit is contained in:
a6a2f5842 2025-06-12 16:16:07 +02:00
parent 556a5aba2e
commit 4f0dd41028
1 changed files with 34 additions and 26 deletions

View File

@ -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(),
]);
}
}