Laravel echo with redis and socket io

I have a SomeEvent.php event

So:

<?php namespace App\Events; use Illuminate\Broadcasting\Channel; use Illuminate\Queue\SerializesModels; use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Broadcasting\PresenceChannel; use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; class SomeEvent implements ShouldBroadcast { use InteractsWithSockets, SerializesModels; public $data; /** * Create a new event instance. * * @return void */ public function __construct($array) { $this->data = $array; } /** * Get the channels the event should broadcast on. * * @return Channel|array */ public function broadcastOn() { return new PrivateChannel('channel-name'); } } 

I included the following in my bootstrap.js and compiled it with gulp

 import Echo from "laravel-echo" window.Echo = new Echo({ broadcaster: 'socket.io', host: 'http://site.dev:6001' }); window.Echo.private('channel-name') .listen('SomeEvent', (e) => { console.log(e); }); 

then I installed tlaverdure / laravel-echo-server, and here is my laravel-echo-server.json

 { "appKey": "[generated]", "authHost": "http://site.dev", "authEndpoint": "/broadcasting/auth", "database": "redis", "databaseConfig": { "redis": {}, "sqlite": { "databasePath": "/database/laravel-echo-server.sqlite" } }, "devMode": false, "host": "sitei.dev", "port": "6001", "referrers": [], "socketio": {}, "sslCertPath": "", "sslKeyPath": "" } 

now when i run laravel echo server with launch laravel-echo-server, it starts very well, but when i fire the above event like

 event(new SomeEvent(json_encode(['name' => 'some-name']))); 

I see an event posted in redis, however nothing is written to my client console: I also include the io socket in my master.blade.php

above also happens with notifications

Any help would be greatly appreciated. Thanks guys

+6
source share
1 answer

Have you defined an authentication rule for your channel in BroadcastServiceProvider?

Do you see any information about connecting and exiting the channel if you insert devMode in laravel-echo-server.json?

I had a lot of problems trying to set up my network connection, but finally it turned out, and my code is very similar to yours.

Good luck

+1
source

Source: https://habr.com/ru/post/1011951/


All Articles