我似乎无法弄清楚如何在“断开连接”事件之后添加“结束”事件挂钩。
我想隐藏“结束通话”按钮,然后通过套接字通知其他参与者,这样我也可以隐藏他们的“结束通话”按钮并做其他事情。
这是我的尝试:
我的起始代码来自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;
});