Laravel echo leaving doesn't fire event

524 Views Asked by At

I'm trying to send a whisper event when a user is leaving the channel but the user-disconnected event doesn't fire. Oddly, the user-connected event works when a user is joining.

let channel = Echo.join(`consultation`)
    channel.here((users) => {
        usersCount = users.length;
        $('#total-users').text(usersCount)
    })
    channel.joining((user) => {
        usersCount = usersCount+1;
        $('#total-users').text(usersCount)
        Toast.fire({
            icon: 'info',
            title: user.name+' has joined the room.'
        })
        channel.whisper('user-connected',myPeerId) //works
    })
    channel.leaving((user) => {
        usersCount = usersCount-1;
        $('#total-users').text(usersCount)
        Toast.fire({
            icon: 'info',
            title: user.name+' has left the room.'
        })
        channel.whisper('user-disconnected',myPeerId) //doesnt work
    })
    channel.listenForWhisper('user-disconnected',(e)=> {
        console.log('userDisconect')
        if (peers[e]) peers[e].close()
    })
0

There are 0 best solutions below