本文档主要介绍如何感知当前网络的好与坏。
当我们在使用微信视频通话的时候,如果遇到网络环境较差的情况(例如在进入电梯以后),微信会在视频通话的界面上提示“您当前的网络质量较差”。本文档主要介绍如何通过 TRTC 完成同样的交互。

调用指引
TRTC 提供了一个叫做 onNetworkQuality 的回调事件,它会每隔两秒钟向您汇报当前的网络质量,其参数包括 localQuality 和 remoteQuality 两个部分:
localQuality :代表您当前的网络质量,分为 7 个等级,分别是 TRTCQuality_Unknown、TRTCQuality_Excellent、TRTCQuality_Good、TRTCQuality_Poor、TRTCQuality_Bad、TRTCQuality_Vbad 和 TRTCQuality_Down。
remoteQuality:代表远端用户的网络质量,这是一个数组,数组中的每个元素代表一个远端用户的网络质量。
Quality | 名称 | 说明 |
0 | 未感知到。 | |
1 | 当前网络非常好。 | |
2 | 当前网络比较好。 | |
3 | 当前网络一般。 | |
4 | 当前网络较差,可能会出现明显的卡顿和通话延迟。 | |
5 | 当前网络很差,TRTC 只能勉强保持连接,但无法保证通讯质量。 | |
6 | 当前网络不满足 TRTC 的最低要求,无法进行正常的音视频通话。 |
import TRTCCloud, { TRTCQuality } from 'trtc-electron-sdk';const rtcCloud = new TRTCCloud();function onNetworkQuality(localQuality, remoteQuality) {switch(localQuality.quality) {case TRTCQuality.TRTCQuality_Unknown:console.log('SDK has not yet sensed the current network quality.');break;case TRTCQuality.TRTCQuality_Excellent:console.log('The current network is very good.');break;case TRTCQuality.TRTCQuality_Good:console.log('The current network is good.');break;case TRTCQuality.TRTCQuality_Poor:console.log('The current network quality barely meets the demand.');break;case TRTCQuality.TRTCQuality_Bad:console.log('The current network is poor, and there may be significant freezes and call delays.');break;case TRTCQuality.TRTCQuality_Vbad:console.log('The current network is very poor, the communication quality cannot be guaranteed.');break;case TRTCQuality.TRTCQuality_Down:console.log('The current network does not meet the minimum requirements.');break;default:break;}for (let i = 0; i < remoteQuality.length; i++) {console.log(`remote user: ${remoteQuality[i].userId}, quality: ${remoteQuality[i].quality}`);}}rtcCloud.on('onNetworkQuality', onNetworkQuality);