【发布时间】:2019-12-03 01:12:04
【问题描述】:
在我的 twillio 应用程序中,尝试从房间断开连接时出现随机错误。
这是我在退出时尝试执行的代码:
this.log('Leaving room...');
try {
this.activeRoom ? this.activeRoom.disconnect().catch(console.log) : console.log('No active room to disconnect / check disconnect logic');
} catch (error) {
console.log(error)
}
这会产生以下错误:
我并不关心错误本身,而是我无法捕捉到错误这一事实。 如您所见,try/catch 块和 .catch() 都已添加,但我仍然收到此错误。
UPDATE_1
通过 api 挖掘后,我发现并实现了这个:
this.activeRoom.on('disconnected', function(room, error) {
if (error) {
console.log('Unexpectedly disconnected:', error);
}
myRoom.localParticipant.tracks.forEach(function(track) {
track.stop();
track.detach();
});
});
但是这个错误仍然出现在我身上。
UPDATE_2
【问题讨论】:
-
this.activeRoom.on('error',(err)=>{})试试这个。这可能行不通,但我认为您需要改为捕获事件。 -
这不起作用:(
标签: javascript reactjs twilio twilio-api