Using custom and default handlers together #309
Description
After reading the Custom WebSocket Handlers documentation and the Router code, I understood that by using WebSocketsRouter::webSocket()
a new websocket endpoint is added to the server, that still keeps the default /app/{appKey}
route (compliant with the Pusher protocol).
Then, after setting my custom handler endpoint in routes/web.php
:
WebSocketsRouter::webSocket('/test', \App\SimpleWebsocketHandler::class);
That just logs that the connection happened:
class SimpleWebsocketHandler implements MessageComponentInterface
{
public function onOpen(ConnectionInterface $connection) { Log::info('onOpen'); }
...
I can verify that the server has both the /app/{appKey}
and /test
endpoints.
However, when the Laravel Echo instance in the browser tries to connect using the default route:
GET ws://localhost:6001/app/816622f4d65f3c4e1d2e11011658b785?protocol=7&client=js&version=5.0.3&flash=false
The custom onOpen
function is executed instead:
Starting the WebSocket server on port 6001...
New connection opened for app key 816622f4d65f3c4e1d2e11011658b785.
[2020-01-30 00:30:51] local.DEBUG: onOpen
Connection id closed.
And since the custom handler doesn't establish the connection and nothing is returned to the browser, the Laravel Echo connection fails with the error:
app.js:1 WebSocket connection to 'wss://localhost/app/816622f4d65f3c4e1d2e11011658b785?protocol=7&client=js&version=5.0.3&flash=false' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
So, is my understanding wrong? Is it not possible to use both a custom handler and the default Pusher compliant handler together?
In the issue #21 the example provided is a child of the default WebSocketHandler
, but then when calling the parent::onOpen()
, the Pusher format will be expected.