Cross-platform getStats() without adapter.js ?

267 views
Skip to first unread message

davidsw...@gmail.com

unread,
Feb 28, 2019, 2:57:06 AM2/28/19
to discuss-webrtc
Is there a simple way to detect which browser's getStats() is present? I believe Chrome's takes a callback as its only parameter, Firefox takes a selector and returns a Promise (and that Apple browsers don't provide getStats).

I realize adapter.js has shims, but we have a long-time commitment to a non-adapter.js library for WebRtc, so I can't easily add adapter.js to our project without potential namespace collisions.

I haven't been able to find in adapter.js how it detects the difference, nor have I been able to find a way to distinguish them except by 1) catching exceptions after calling them, or 2) relying on DetectRtc to tell me which browser it is.

Philipp Hancke

unread,
Feb 28, 2019, 3:14:51 AM2/28/19
to discuss...@googlegroups.com
Am Do., 28. Feb. 2019 um 08:57 Uhr schrieb <davidsw...@gmail.com>:
Is there a simple way to detect which browser's getStats() is present? I believe Chrome's takes a callback as its only parameter,

Chrome has supported spec-stats for a while (since M56). Note that this is is mostly the simple pc.getStats().then(...)
RTCRtpSender.getStats is more recent. shimSenderReceiverGetStats is a standalone function in adapter which also shims pc.getStats(track) which you might be able to cherry-pick.

Firefox takes a selector and returns a Promise

Correct.

(and that Apple browsers don't provide getStats).

No, even though in the stable safari version a bunch of reports are missing.


I realize adapter.js has shims, but we have a long-time commitment to a non-adapter.js library for WebRtc, so I can't easily add adapter.js to our project without potential namespace collisions.

I haven't been able to find in adapter.js how it detects the difference, nor have I been able to find a way to distinguish them except by 1) catching exceptions after calling them, or 2) relying on DetectRtc to tell me which browser it is.

see export function shimPeerConnection(window) in src/js/chrome/chrome_shim.js (which might move into a separate function soon)
The detection of support for spec-style getStats is a bit... funky. When its supported RTCPeerConnection.prototypegetStats.length will be 0 due to webidl overloading things.
 
--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/e8fc9f6d-8252-497f-9bbf-cb70ddd28a33%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

davidsw...@gmail.com

unread,
Feb 28, 2019, 5:26:00 PM2/28/19
to discuss-webrtc
Thanks, Philipp. However, I'm facing more fundamental problems...

I'm following the code sample at https://stackoverflow.com/a/29360179 to get stats about the peer (not about tracks, yet)

   pc.getStats().then(function(stats) { ... })
   
When I try this on Chrome72/stable/Win010, "stats" is assigned an empty object when the ICE state becomes "completed", according to JSON.stringify and Object.keys.

When I try on FF65/stable/Win10, "stats" is null when the ICE state becomes "closed"...The state is never shown to be "completed".

Btw, I believe getStats is supposed to be available for these ICE states: ["completed", "failed", "disconnected", "closed"]

davidsw...@gmail.com

unread,
Feb 28, 2019, 11:40:26 PM2/28/19
to discuss-webrtc
I tried adapting the chrome shim, attached as adapterjs-snippets.js.txt. The log stmt at the end is the first stmt to appear in my Chrome console, but it doesn't change the behavior -- the stats argument remains an empty object (Chrome72/Win10) or null (FF65/Win10). Btw, it didn't work on Edge, either.

I also tried using the sample code from the spec at https://www.w3.org/TR/webrtc/#x8-8-getstats-example This is attached as fGatherStats.js.txt. This didn't work on Chrome or FF because one of the "report" values that should be an object would instead be undefined. Which value was undefined differed across the browsers.

Because the stats API is used widely, I'm sure I'm missing something simple. FWIW, I don't have any browser extensions that are related to WebRtc or media.
adapterjs-snippets.js.txt
fGatherStats.js.txt

davidsw...@gmail.com

unread,
Mar 5, 2019, 10:45:56 PM3/5/19
to discuss-webrtc
For those who try to make use of this thread in the future, FYI, the 4 year-old stackoverflow answer I was following turns out to be outdated. I've added a follow-up answer: https://stackoverflow.com/questions/27230542/how-do-i-get-information-about-the-type-of-connection-of-a-webrtc-peerconnection/55015191#55015191
Reply all
Reply to author
Forward
0 new messages