w3c / mediacapture-extensions

Extensions to Media Capture and Streams by the WebRTC Working Group
https://w3c.github.io/mediacapture-extensions/
Other
19 stars 14 forks source link

[Track Stats API] Make stats attribute nullable instead of throwing when unsupported #122

Closed henbos closed 8 months ago

henbos commented 8 months ago

if (track.stats) { ... } is a much better feature detection than

try {
  if (track.stats) {
    /* supported! */
  }
} catch (e) {
}

There really doesn't seem to be any benefit to throwing versus making the attribute nullable as far as I can tell.

henbos commented 8 months ago

The risk is that people feature detect with if (track.stats) and it works on Browser A which in version 1 had not implemented the API (thus returning undefined), and in version 2 had implemented it for a particular type of track, then that track type never threw in Browser A's versioning history. Then Browser B comes along and implements track stats for some track types, but not others, and so now throwing becomes a possibility. But because people never needed to try-catch to feature detect, we now have backwards/cross-browser compat issues where the app works in Browser A but not in Browser B.

henbos commented 8 months ago

It seems like a real possibility too that we expand which track types should be supported in the future, so app developers not having to worry about exceptions in some version and not others seems preferable, unless there is some benefit to exceptions, but I don't think there is in this case