Laravel Echo and Whisper, listenForWhisper not work

Viewed 3467

I'm running Echo server and Beyondcode (Pusher). Presence channels work perfectly, and messaging I have built for it works. Now I'm trying to get the whisper to work for the typing status as well but no luck.

Sending whisper:

let channel = Echo.join('chat')

setTimeout( () => {
    channel.whisper('typing', {
    user: Laravel.user.id,
    typing: true
    })
}, 300)

Listen whisper:

Echo.join('chat')
.listenForWhisper('typing', (e) => {
    console.log(e)
});

In my echo server log, when i'm typing message:

testapp: connection id 332742863.966987392 received message: 
{
    "event":"client-typing",
    "data":{
        "user":2,
        "typing":true
    },
    "channel":"presence-chat"
}

Broadcast channel (routes/channels.php)

Broadcast::channel('chat', function ($user) {
    return [
        'id' => $user->id,
        'name' => $user->name
    ];
});

Connection id 332742863.966987392 is second user (not the one from which I typed the message).

But nothing appears in browser console.

2 Answers

I know this is old, but my problem was I didn't enable an option called "Enable client events" from pusher app settings.

Just leaving this here for future user who might be facing issue with receiving events in

.listenForWhisper(..)

If you are using laravel-websockets, make sure you enable 'enable_client_messages'

Related