2016-08-17 112 views
1

我似乎無法弄清楚如何添加一個「已結束」事件掛接後「已斷開」事件。如何創建一個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; 

    }); 

回答

1

我做了同時解決方法,我修改了我的企圖三號和它的工作。我敢肯定,這是不是這樣做,因爲有一個最好的方式「結束」事件掛接我無法弄清楚如何觸發,但它解決了我的問題(包括參加斷開了該呼叫)。

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

仍然希望別人如何處理這樣的情況:對