0

当用户离开频道但未触发用户断开连接事件时,我正在尝试发送耳语事件。奇怪的是,用户连接事件在用户加入时起作用。

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()
    })
4

0 回答 0