如何在浏览器的 Twilio 库中捕获错误? [英] How do I trap errors in the Twilio library in the browser?

查看:21
本文介绍了如何在浏览器的 Twilio 库中捕获错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Twilio Video SDK 来构建视频聊天网站.核心功能正在运行,但我一直在浏览器控制台中看到零星错误,如下所示:

I'm using the Twilio Video SDK to build a video chat site. The core functionality is working, but I keep seeing sporadic errors in the browser console, like these:

- (node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
- ICE Connection Monitor detected inactivity
- An ICE restart has been scheduled
- Attempting to restart ICE
- ICE failed, add a STUN server and see about:webrtc for more details

有些似乎是警告,有些是错误.我如何捕获这些错误以便我可以适当地更新 UI?我想我想在这里使用 EventEmitter 逻辑:https://media.twiliocdn.com/sdk/js/video/releases/2.5.1/docs/global.html#EventListener__anchor

Some appear to be warnings, some are errors. How do I trap those errors so I can update the UI appropriately? I think I would want to use the EventEmitter logic here: https://media.twiliocdn.com/sdk/js/video/releases/2.5.1/docs/global.html#EventListener__anchor

我的问题:

  • 这是正确的方法吗?
  • 如果是这样,我如何在浏览器端 javascript 中实现它,特别是require('events')"?一块?
  • 为什么我在网上找不到好的 Twilio 文档?我知道它在某个地方,但我一直不得不通过代码反复试验,或者打开支持票,这对支持团队来说很慢而且不公平.我错过了什么?

推荐答案

我怀疑我是唯一对此感到困惑的人,所以这是我能够弄清楚的(希望这对其他人有所帮助).这是我大量编辑的代码:

I doubt I'm the only one confused by this, so here's what I have been able to figure out (hopefully this helps someone else). Here is my heavily redacted code:

Twilio.Video.connect(token, { 
    options
}).then(room => {
    room.on('reconnecting', error => {console.log("Room reconnecting: " + error );});
}, error => {
    console.log('Unable to connect to Room: ' + error.message);
});

根据文档:https://media.twiliocdn.com/sdk/js/video/releases/2.6.0/docs/Room.html,房间类继承了EventEmitter,所以不需要单独创建EventEmitter对象,要求('事件');"不需要碎片.文档还列出了您可以收听的事件,尽管似乎存在一些差距.例如,Participant 类发出 'trackSubscribed' 事件,但它不在文档中.

According to the docs: https://media.twiliocdn.com/sdk/js/video/releases/2.6.0/docs/Room.html, the room class extends EventEmitter, so you don't need to create a separate EventEmitter object, and the "require('events');" pieces is not needed. The docs also list the events that you can listen for, although there seem to be some gaps. For example, the Participant class emits the 'trackSubscribed' event, but it's not in the documentation.

对于我看到的错误,我需要注意 Room 'reconnecting' 事件.如果成功,它会发出 'reconnected' 事件,所以我需要看看我是否得到一个而不是另一个,这表明我可能需要手动解决一个问题.

For the errors that I'm seeing, it appears that the Room 'reconnecting' event is what I need to pay attention to. If it's successful, it emits the 'reconnected' event, so I need to see if I get one and not the other, which would indicate a problem that I might need to manually address.

这篇关于如何在浏览器的 Twilio 库中捕获错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆