Agora Web 检查网络质量

Agora Web check network quality

我正在使用 agora 进行视频通话和流媒体服务。我需要检查网络质量并通知用户速度慢connection.For这些我写的这些功能是为了检查上下行网络quality.this是参考

https://docs.agora.io/en/All/API%20Reference/web/v2.6/interfaces/agorartc.networkqualitystats.html

    const rtcClient = this.client;
    
const checkQualityDrop = (
              quality: string,
              currentQuality: number,
            ): { newNetworkQuality: number; qualityDroppedNow: boolean } => {
              const newNetworkQuality = Number.parseInt(quality, 10);
              const qualityDroppedNow = currentQuality < 4
                && newNetworkQuality >= 4;
              return { newNetworkQuality, qualityDroppedNow };
            };
        
            rtcClient.on('network-quality', (quality) => {
              if (quality.uplinkNetworkQuality) {
                const {
                  newNetworkQuality,
                  qualityDroppedNow,
                } = checkQualityDrop(quality.uplinkNetworkQuality, this.uplinkNetworkQuality);
        
                if (qualityDroppedNow) {
                  this._log('network-drop', { type: 'uplink', newNetworkQuality });
                }
        
                this.uplinkNetworkQuality = newNetworkQuality;
              }
        
              if (quality.downlinkNetworkQuality) {
                const {
                  newNetworkQuality,
                  qualityDroppedNow,
                } = checkQualityDrop(quality.downlinkNetworkQuality, this.downlinkNetworkQuality);
        
                if (qualityDroppedNow) {
                  this._log('network-drop', { type: 'downlink', quality: newNetworkQuality });
                }
        
                this.downlinkNetworkQuality = newNetworkQuality;
              }
            });

任何大于 4 的上行链路和下行链路都应该通知用户慢速 network.But 这里它对慢速不起作用 network.Anyway 我可以重写或改进这些功能吗?

我不确定您的条件是否会在质量下降时评估为真:

const qualityDroppedNow = currentQuality < 4 && newNetworkQuality >= 4;

您正在检查之前的质量是否较低,而新的质量是否为 improved/recovered。