Answer the question
In order to leave comments, you need to log in
How to see event message in pusher socket channel (Laravel Websockets)?
I have an event that should broadcast to a channel, but when it is called, no message is visible in the channel. I am using Laravel Websockets. On the server, the port is opened and I receive the channel object on the client
import Echo from 'laravel-echo'
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
wsHost: window.location.hostname,
wsPort: 6001,
});
let channel = window.Echo.channel('room1');
console.log(channel);
channel
.listen('TestEvent', () => {
console.log('1');
});
class TestEvent
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $data;
public function __construct()
{
$this->data = json_encode(['a' => 1, 'b' => 2]);
}
public function broadcastOn()
{
return new Channel('room1');
}
}
Route::get('test', function() {
App\Events\TestEvent::dispatch();
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question