laravel websockets onsubscribe

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

showing results for - "laravel websockets onsubscribe"
Khadija
08 Jun 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        $message = json_decode($message->getPayload(), true);
33        if ($message['event'] === 'pusher:subscribe') { 
34      		// Your code here...
35        }
36    }
37}