WebRTC: use of getStats()
Asked Answered
C

1

7

I'm trying to get stats of a webRTC app to measure audio/video streaming bandwidth. I checked this question and I found it very useful; however, when I try to use it I get

TypeError: Not enough arguments to RTCPeerConnection.getStats.

I think that is because of in 2016 something in webRTC is changed and now there are mediaStreamTracks; however I built the project without mediaStreamTracks and I don't know how to change this function to get it to work.

Do you have any ideas? Thanks for your support!

UPDATE:

My call is

peer.pc.onaddstream = function(event) {
      peer.remoteVideoEl.setAttribute("id", event.stream.id);
      attachMediaStream(peer.remoteVideoEl, event.stream);
      remoteVideosContainer.appendChild(peer.remoteVideoEl);
      getStats(peer.pc);
};

and getStats() is identical to this link at chapter n.7.

Cudweed answered 8/7, 2016 at 9:19 Comment(6)
Post some code. Especially your call of getStats()Roby
getStats() needs a mediaStreamTrack as parameter, if i recall.Expertise
Updated question! P.s: what if I call peer.getStats(null, function(...) ) ?Cudweed
That should. The track is only a filter, and can be left out with null.Azaria
I would close this as a duplicate of this question, except you seem to want it to work in Chrome specifically, is that right?Azaria
I think it would be ok, could you please just add tags "bandwidth" and "mediastream", or "statistics" to the original question? I'm new and I can'tCudweed
L
6

been sometime since I used WebRTC, problem then was, chrome and firefox implemented it differently( believe they still do it differently)

Firefox:

webrtc stats tab is about:webrtc

peerConnection.getStats(null).then(function(stats){...  // returns a promise

Chrome:

webrtc stats tab is chrome://webrtc-internals/

peerConnection.getStats(function(stats){ // pass a callback function

one way to circumvent these cross browser issues is using adapter.js

Laughable answered 8/7, 2016 at 12:57 Comment(1)
Yes Firefox implements it to spec, Chrome does not. See this question. - Yes, adapter.js helps on calling convention, but note it does not rename Chrome-specific stats keys yet.Azaria

© 2022 - 2024 — McMap. All rights reserved.