phplaravellaravel-websockets

Laravel echo listenForWhisper not working with laravel-websockets


I'm trying to create a room where we will broadcast changes made to a document.

Currently, I have the following code:

const channel = window.Echo.private('some-channel');


setInterval(() => {
  channel.whisper('something', { payload: 'foo' });
}, 1000);

window.Echo.private('some-channel').listenForWhisper('something', (e) => {
  console.log('someone whispered');
  console.log(e);
  console.log('-------');
})

With the full payload being:

{"event":"client-something","data":{"payload":"foo"},"channel":"private-some-channel"}

I login into my application from two different browsers (Chrome and Chrome in incognito mode) but I do not see any console.log in my browser's console.

I can see the messages are being sent:

enter image description here

I have enabled enable_client_messages in my config/websockets.php file:

'apps' => [
  [
    'id' => env('PUSHER_APP_ID'),
    'name' => env('APP_NAME'),
    'key' => env('PUSHER_APP_KEY'),
    'secret' => env('PUSHER_APP_SECRET'),
    'path' => env('PUSHER_APP_PATH'),
    'capacity' => null,
    'enable_client_messages' => true,
    'enable_statistics' => true,
  ],
],

What am I doing wrong? Why am I not being able to see the console.log in user A or user B browser consoles?


Solution

  • I forgot to add the route authentication in routes/channels.php

    Broadcast::channel('some-channel', function ($user) {
        return $user;
    });