如何创建Twilio视频API结束的事件挂钩?

如何创建Twilio视频API结束的事件挂钩?,twilio,twilio-api,Twilio,Twilio Api,我似乎不知道如何在“断开连接的”事件之后添加“结束的”事件挂钩 我想隐藏“结束通话”按钮,然后通过套接字通知其他参与者,这样我也可以隐藏他们的“结束通话”按钮并做其他事情 以下是我的尝试: 我的起始代码是 我的尝试是 1。在停止对话并调用自定义函数后添加“then” webRTCActiveConversation.on('disconnected', function (conversation) { console.log("Connected to Twilio. Listenin

我似乎不知道如何在“断开连接的”事件之后添加“结束的”事件挂钩

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

以下是我的尝试:

我的起始代码是

我的尝试是

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。在disconnect event hook下添加DOM操纵和套接字发射(来自此客户端的Disconnects调用、DOM操纵和套接字事件正在工作,但其他连接的客户端上的Twilio连接尚未断开)


在此期间,我做了一个变通办法,修改了我的第三次尝试,成功了。我确信这不是最好的方法,因为我不知道如何触发一个“ended”事件挂钩,但它解决了我的问题(两个参与者都断开了连接)

仍对其他人如何处理此类案件抱有希望:p

    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;

    });
    //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);
    });