laravel-websockets-demo icon indicating copy to clipboard operation
laravel-websockets-demo copied to clipboard

Custom websocket handler not working

Open mujuonly opened this issue 4 years ago • 1 comments

web.php


use Symfony\Component\Console\Output\NullOutput;
use BeyondCode\LaravelWebSockets\Server\Logger\WebsocketsLogger;

app()->singleton(WebsocketsLogger::class, function () {
    return (new WebsocketsLogger(new NullOutput()))->enable(false);
});

use BeyondCode\LaravelWebSockets\Facades\WebSocketsRouter;

WebSocketsRouter::webSocket('/my-websocket', \App\MyCustomWebSocketHandler::class);

MyCustomWebSocketHandler

<?php

namespace App;

use Ratchet\ConnectionInterface;
use Ratchet\RFC6455\Messaging\MessageInterface;
use Ratchet\WebSocket\MessageComponentInterface;
use BeyondCode\LaravelWebSockets\WebSockets\WebSocketHandler;

class MyCustomWebSocketHandler extends WebSocketHandler
{

    public function onMessage(ConnectionInterface $connection, MessageInterface $msg)
    {
        // TODO: Implement onMessage() method.
    }
}

Client let socket = new WebSocket("ws://localhost:6001/app/websocketkey/my-websocket?protocol=7&client=js&version=4.3.1&flash=false"); When trying to run the client connection, it's not getting connected to the custom handler. The default handler is working fine.

The Websocket:serve and artisan:serve are running

Any thoughts on this.?

mujuonly avatar Mar 06 '20 05:03 mujuonly

Have you tried this:

<?php

namespace App;

use Ratchet\ConnectionInterface;
use Ratchet\RFC6455\Messaging\MessageInterface;
use Ratchet\WebSocket\MessageComponentInterface;
use BeyondCode\LaravelWebSockets\WebSockets\WebSocketHandler;

class MyCustomWebSocketHandler extends WebSocketHandler
{

    public function onMessage(ConnectionInterface $connection, MessageInterface $msg)
    {
        parent:onMessage( $connection, $msg);

        // TODO: Implement onMessage() method.
    }
}

DouglasLeiteFonseca avatar May 16 '20 14:05 DouglasLeiteFonseca