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.

Community
  • 1
  • 1
Don Diego
  • 1,309
  • 3
  • 23
  • 46
  • Post some code. Especially your call of `getStats()` – KRONWALLED Jul 08 '16 at 09:53
  • 2
    `getStats()` needs a `mediaStreamTrack` as parameter, if i recall. – Samuel Méndez Jul 08 '16 at 09:59
  • Updated question! P.s: what if I call `peer.getStats(null, function(...) )` ? – Don Diego Jul 08 '16 at 10:16
  • 1
    That should. The track is only a filter, and can be left out with `null`. – jib Jul 08 '16 at 13:18
  • I would close this as a duplicate of [this question](http://stackoverflow.com/questions/29800010/can-someone-comprehensively-explain-the-webrtc-stats-api/29840886), except you seem to want it to work in Chrome specifically, is that right? – jib Jul 08 '16 at 13:19
  • 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't – Don Diego Jul 11 '16 at 15:12

1 Answers1

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

mido
  • 24,198
  • 15
  • 92
  • 117
  • 2
    Yes Firefox implements it to [spec](https://w3c.github.io/webrtc-stats), Chrome does not. See [this question](https://github.com/webrtc/adapter/issues/5). - Yes, adapter.js helps on calling convention, but note it does not rename Chrome-specific stats keys [yet](https://github.com/webrtc/adapter/issues/5). – jib Jul 08 '16 at 13:21