如何创建Twilio Video API结束事件挂钩?

时间:2016-08-17 05:30:48

标签: twilio twilio-api

"断开连接" "已结束" 事件挂钩>事件。

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

以下是我的尝试:

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

我的尝试

1。添加"然后"停止对话并调用自定义功能后

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。在disconnect事件挂钩下添加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;

    });

1 个答案:

答案 0 :(得分: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