javascript – WebRTC:如何计算RTC对等连接的用户带宽/网络延迟

前端之家收集整理的这篇文章主要介绍了javascript – WebRTC:如何计算RTC对等连接的用户带宽/网络延迟前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

所以,我正在开发一个利用WebRTC在同行之间提供视频/音频通信的应用程序.

我想向用户提供一些关于他们的网络连接/带宽/延迟等的反馈,以便在带宽等可怕的情况下建议可能的解决方案.

WebRTC有一个getStats() API,提供了许多关键信息.当Peer Connection处于活动状态时,getStats()会给我以下对象…

{
    "googLibjingleSession_5531731670954573009":{
        "id":"googLibjingleSession_5531731670954573009","timestamp":"2016-02-02T11:14:43.467Z","type":"googLibjingleSession","googInitiator":"true"
    },"googTrack_SCEHhCOl":{
        "id":"googTrack_SCEHhCOl","type":"googTrack","googTrackId":"SCEHhCOl"
    },"ssrc_360347109_recv":{
        "id":"ssrc_360347109_recv","type":"ssrc","googDecodingCTN":"757","packetsLost":"0","googSecondaryDecodedRate":"0","googDecodingPLC":"3","packetsReceived":"373","googExpandRate":"0.00579834","googJitterReceived":"0","googDecodingCNG":"0","ssrc":"360347109","googPreferredJitterBufferMs":"20","googSpeechExpandRate":"0.00140381","googTrackId":"SCEHhCOl","transportId":"Channel-audio-1","googDecodingPLCCNG":"10","googCodecName":"opus","googDecodingNormal":"744","audioOutputLevel":"6271","googAccelerateRate":"0","bytesReceived":"21796","googCurrentDelayMs":"64","googDecodingCTSG":"0","googCaptureStartNtpTimeMs":"-1","googPreemptiveExpandRate":"0.00292969","googJitterBufferMs":"42"
    }
}

有了这些信息,我希望能够计算出用户……

a)带宽(理想情况下音频和视频分开但直接带宽就足够了)

b)网络延迟

提前致谢…

注意:我已经看过this wrapper但是我希望能够自己做到这一点(当然有一点你的帮助:D)因为这个包装器的示例代码使用了“bytesSent”属性,我不知道似乎从getStats()回来了?

我也知道GitHub上有WebRTC test可用,但同样,我应该能够实现我想要的而不依赖于第三方“插件”等.

最佳答案
据我所知,这些RTCStatReports的属性差异很大.例如,您提到的bytesSent属性并不总是可用,您可能需要这样做:

// chrome
if (res.googCodecName == 'VP8' && res.bytesSent) {
  // res.bytesSent - bytes sent so far (video)
}

// firefox
if (res.mediaType == 'video' && res.bytesSent) ...

看看wrapper you posted的来源了解更多.您还可以查看my fork(如果包装器不再起作用,那就是我上次看的情况).

原文链接:https://www.f2er.com/jquery/427757.html

猜你在找的jQuery相关文章