laravel websockets onmessage

Solutions on MaxInterview for laravel websockets onmessage by the best coders in the world

showing results for - "laravel websockets onmessage"
Isidora
07 Feb 2018
1// Add websocket routes "App\Providers\RouteServiceProvider.php"
2public function map()
3{
4    $this->mapApiRoutes();
5
6    $this->mapWebRoutes();
7  
8    $this->app->singleton('websockets.router', function () {
9        return new Router();
10    });
11}
12
13// Create WebSocket Router "App\WebSockets\Route.php"
14class Router extends \BeyondCode\LaravelWebSockets\Server\Router
15{
16    public function echo()
17    {
18        $this->get('/app/{appKey}', WebSocketHandler::class);
19        $this->post('/apps/{appId}/events', TriggerEventController::class);
20        $this->get('/apps/{appId}/channels', FetchChannelsController::class);
21        $this->get('/apps/{appId}/channels/{channelName}', FetchChannelController::class);
22        $this->get('/apps/{appId}/channels/{channelName}/users', FetchUsersController::class);
23    }
24}
25
26// Create WebSocket Router "App\WebSockets\WebSocketHandler.php"
27class WebSocketHandler extends \BeyondCode\LaravelWebSockets\WebSockets\WebSocketHandler
28{
29    public function onMessage(ConnectionInterface $connection, MessageInterface $message)
30    {
31        parent::onMessage($connection, $message);
32      	// Your code here...
33    }
34}