1

I'm using Websocket with SSL but if SSL has any issue I'm not able to findout out the exact issue. After Investigation "SecureServer.php" has a code which are emit the error but that error is not getting through pusher.

This is the code in SecureServer.php enter image description here

With a valid SSL (certificate & private key) it's working fine. but I need to show an error when there is issue

can anyone help me on this to get this emitted error message through pusher?

Versions:

  • Laravel: 9.52.4
  • laravel-websockets: 1.13.2
  • react/socket: 1.12.0
  • pusher-js: 7.0.3

I've created a Custom WebSocketHandler sending pusher:error from OnError() function

    public function onError(ConnectionInterface $connection, Exception $exception)
    {
        if ($exception instanceof WebSocketException) {
            $connection->send(
                json_encode([
                    "event" => "pusher:error",
                    "data" => json_encode([
                        "socket_id" => $connection->socketId,
                        "activity_timeout" => 30,
                        "exception" => json_encode($exception->getPayload()),
                    ]),
                ])
            );
        }
    }

But didn't worked.

1 Answer 1

1

Maybe It's not an optimized solution

Solution Steps:

Step 1: Created another command MyStartWebSocketServer.php & copy all the content from vendor/beyondcode/laravel-websockets/src/Console/StartWebSocketServer.php And change command signature from

websockets:serve

to

mywebsockets:serve

Step 2: Created another file under /app folder with a name MyWebSocketServerFactory.php & copy all content from vendor/beyondcode/laravel-websockets/src/Server/WebSocketServerFactory.php

Step 3: Goto Line Number 148 in MyStartWebSocketServer.php file & changed from

(new WebSocketServerFactory())

to

(new MyWebSocketServerFactory())

Step 4: Created another file under /app folder with a name MySecureServer.php & copy all content from vendor/react/socket/src/SecureServer.php

Step 5: Goto Line Number 79 in MyWebSocketServerFactory.php file & changed from

$socket = new SecureServer($socket, $this->loop, config('websockets.ssl'));

to

$socket = new MySecureServer($socket, $this->loop, config('websockets.ssl'));

Step 6: Goto line 200 in MySecureServer.php file and log the error when connection is not formed & show a proper message to user

$this->encryption->enable($connection)->then(
        function ($conn) use ($that) {
            $that->emit("connection", [$conn]);
        },
        function ($error) use ($that, $connection, $remote) {
            $error = new \RuntimeException("Connection from " . $remote . " failed during TLS handshake: " . $error->getMessage(), $error->getCode());

            // your code to send error message on UI

            $that->emit("error", [$error]);
            $connection->close();
        }
    );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.