Skip to content

Instantly share code, notes, and snippets.

@bnb
Last active September 30, 2023 03:11
Show Gist options
  • Save bnb/9a0cb998cd526904c4347664e273679f to your computer and use it in GitHub Desktop.
Save bnb/9a0cb998cd526904c4347664e273679f to your computer and use it in GitHub Desktop.

Go to:

https://webrtc.github.io/samples/src/content/peerconnection/pc1/

Start the video and the call.

The RTCPeerConnections are under the variables pc1 and pc2. In the console, run:

const stats1 = await pc1.getStats()
const stats2 = await pc2.getStats()

And then you should be able to get data from that as is described here, though I've not quite been able to get that data out yet: https://developer.mozilla.org/en-US/docs/Web/API/RTCStatsReport

Two examples with stats being displayed:

Replace the dumpStats function in https://webrtc.github.io/samples/src/content/peerconnection/constraints/ with the following to get JSON output in the console and in the webpage:

function dumpStats(results) {
  let statsObject = {}

  results.forEach(res => {
    statsObject.type = res.type;
    statsObject.id = res.id;
    statsObject.timestamp = res.timestamp;
    Object.keys(res).forEach(k => {
      if (k !== 'timestamp' && k !== 'type' && k !== 'id') {
          statsObject[k] = res[k]
      }
    });
  });
  console.log(statsObject)
  return JSON.stringify(statsObject);
}

How to extract PeerConnection:

// @returns Array<RTCPeerConnection>
function getPeerConnectionObjects(room) {
  return [...room._signaling._peerConnectionManager._peerConnections.values()].map(pc => pc._peerConnection._peerConnection);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment