0

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()
    })
stalwart1014
  • 451
  • 1
  • 9
  • 29
  • When user A leaves the channel, the leaving function will be triggered for user B and immediately after the toast, user B will whisper in the channel. So in your test user C is not receiving the whisper, right? – Parsa_Gholipour Dec 10 '20 at 20:44
  • Isn't it: user A whos leaving the channel will do the whisper , and user B will receive it ? @Parsa_Gholipour – stalwart1014 Dec 11 '20 at 05:16
  • No. When user A is leaving, the leaving event will be triggered for everyone else present in the channel and the 'user' object is user A. – Parsa_Gholipour Dec 11 '20 at 11:32

0 Answers0