angular - twilio 视频室未获得参与者断开连接事件
问题描述
我正在尝试使用 twilio api 实现视频聊天,但在处理远程参与者事件时遇到了一些问题。
我正在按照您在博客上使用 angular 9 执行此操作的示例进行操作,但我已对其进行了一些修改(并且可能已损坏)以匹配更多我的想法。
我遇到的问题是,如果远程参与者没有正确离开房间,而是关闭了浏览器,我没有收到participantDisconnect
事件(或者至少我没有等待足够的时间),这使得远程摄像头保持冻结在屏幕上。
我正在使用“twilio-video”:“2.5.1”
这是代码
async connectToRoom() {
let tracks = await Promise.all([createLocalAudioTrack(), this.camera.videoTrack]);
let roomInfo = await this.videoChatService.joinEvent(this.eventId);
this.activeRoom = await this.videoChatService.connectToRoom(roomInfo, tracks);
this.participants = this.activeRoom.participants;
this.participants.forEach(participant => this.registerParticipantEvents(participant));
this.activeRoom
.on('disconnected',
(room: Room) => room.localParticipant.tracks.forEach(publication => this.detachLocalTrack(publication.track)))
.on('participantConnected',
(participant: RemoteParticipant) => this.add(participant))
.on('participantDisconnected',
(participant: RemoteParticipant) => this.remove(participant))
.on('dominantSpeakerChanged',
(dominantSpeaker: RemoteParticipant) => this.loudest(dominantSpeaker));
}
也许我错过了一些我应该听的 Track 事件?
为了提供更多信息,我使用同一台计算机,但本地/远程参与者使用不同的浏览器
提前非常感谢!
解决方案
在我们的实现中(在您的评论中也提到过),我们使用了如下所示的卸载事件来了解视频通话是否由于窗口关闭而断开。
window.addEventListener('beforeunload', leaveRoomIfJoined);
// Leave Room.
function leaveRoomIfJoined() {
if (activeRoom) {
activeRoom.disconnect();
}
}
activeRoom对象在参与者加入房间时被保留。下面代码中的“roomJoined”函数将房间(或 activeRoom)捕获为参数。
Video.connect(tokenTwilio, connectOptions).then(roomJoined, function(error) {
log('Could not connect to Twilio: ' + error.message);
});
推荐阅读
- c++ - 我如何在我的 QFrame 中画一个点,我想使用 qt 来做到这一点?
- javascript - 使用 setTimeout 在 React 中限制窗口滚动事件
- python - 向 Django 管理员 GUI 添加第二个属性/类别列
- python - 如何使用班级计算“杂货清单”上的项目?
- ruby-on-rails - 无法使用 devise 和 JWT 注册用户
- javascript - 无法使用 Django 在 Javascript 中编辑表单
- swift - 更改 RootViewController 并删除所有视图控制器
- sql - 在 Typeorm 中填充查询
- google-docs - Google Docs 链接预览功能显示不正确的缩略图图像
- github - 仅向 github 存储库添加权限