1

我似乎无法弄清楚如何在“断开连接”事件之后添加“结束”事件挂钩。

我想隐藏“结束通话”按钮,然后通过套接字通知其他参与者,这样我也可以隐藏他们的“结束通话”按钮并做其他事情。

这是我的尝试:

我的起始代码来自https://github.com/TwilioDevEd/video-quickstart-node/blob/master/public/quickstart.js#L27

我的尝试是

1. 停止对话并调用自定义函数后添加“then”

webRTCActiveConversation.on('disconnected', function (conversation) {
    console.log("Connected to Twilio. Listening for incoming Invites as '" + webRTCConversationsClient.identity + "'");

    //results to  "conversation.localMedia.stop(...).then is not a function"
    conversation.localMedia.stop().then(conversationEnded); 


    webRTCActiveConversation = null;
});

2.添加一个“结束”事件挂钩(不知何故这从未被触发):

webRTCActiveConversation.on('ended', function (conversation) {
   console.log('conversation has ended...');

   //should hide end call button then socket emit to hide the end call button on the other connected client

    webRTCActiveConversation = null;
});

3. 在断开事件挂钩下添加 DOM 操作和套接字发射(断开来自该客户端的调用,DOM 操作和套接字事件正在工作,但 Twilio 连接尚未在其他连接的客户端上断开)

    webRTCActiveConversation.on('disconnected', function (conversation) {
        console.log("disconnect call" + webRTCConversationsClient.identity + "'");

        conversation.localMedia.stop();   

        //hide end call button
        var el = document.getElementById('button-end-audio-call');
        el.className += " hide-state";

        //socket emit to hide the end call button on the other connected client
        socket.emit('notifyEndCallRequest');


        webRTCActiveConversation = null;

    });
4

1 回答 1

1

与此同时,我做了一个解决方法,我修改了我的第 3 次尝试,它奏效了。我确定这不是最好的方法,因为有一个“结束”事件挂钩,我不知道如何触发,但它解决了我的问题(两个参与者都断开了通话)。

    //when the conversation ends, stop capturing local video
    webRTCActiveConversation.on('disconnected', function (conversation) {
        console.log("disconnect call '" + webRTCConversationsClient.identity + "'");

        conversation.localMedia.stop();

        webRTCActiveConversation = null;

        //delay DOM manipulation and socket emit
        setTimeout(function(){
            var el = document.getElementById('button-end-audio-call');
            el.className += " app-state-hidden";

            //socket emit to hide the end call button on the other connected client
            socket.emit('notifyEndCallRequest');
        }, 3000);
    });

仍然希望其他人如何处理这种情况:p

于 2016-08-17T06:08:17.860 回答