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

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

问题描述:

我似乎无法弄清楚如何添加一个“已结束”事件挂接后“已断开”事件。如何创建一个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.添加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; 

    }); 

我做了同时解决方法,我修改了我的企图三号和它的工作。我敢肯定,这是不是这样做,因为有一个最好的方式“结束”事件挂接我无法弄清楚如何触发,但它解决了我的问题(包括参加断开了该呼叫)。

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

仍然希望别人如何处理这样的情况:对