Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTCRtpSender.addTrack() incorrectly requires a stream #4071

Open
hills opened this issue Mar 17, 2023 · 1 comment
Open

RTCRtpSender.addTrack() incorrectly requires a stream #4071

hills opened this issue Mar 17, 2023 · 1 comment

Comments

@hills
Copy link

hills commented Mar 17, 2023

The compiler's definition of this function requires one or more streams, and differs from MDN and W3C references which specify zero or more.

Code using addTrack(track) without a stream behaved as I expected, matching the docs in Chromium 113.0.5659.0.

I drafted a patch below, but this is untested as I don't have a build process or CLA. (For the avoidance of any doubt, I declare this patch in the public domain)

I was unable to find a way to override this in my project's @externs, the only workaround I came up with is to abandon all checking on this function entirely. I'd be interested if there's a better workaround:

pc['addTrack'](track);    /* workaround */

/** @type {!MediaStreamTrack} */
let track;

const pc = new RTCPeerConnection({iceServers: []});
pc.addTrack(track);
$ java -jar closure-compiler-v20230103.jar -O ADVANCED ms.js
ms.js:5:0: WARNING - [JSC_WRONG_ARGUMENT_COUNT] Function RTCPeerConnection.prototype.addTrack: called with 1 argument(s). Function requires at least 2 argument(s).
  5| pc.addTrack(track);
     ^^^^^^^^^^^^^^^^^^

0 error(s), 1 warning(s), 100.0% typed
(new RTCPeerConnection({iceServers:[]})).addTrack(void 0);
diff --git a/externs/browser/w3c_rtc.js b/externs/browser/w3c_rtc.js
index 4b0955cb4..9eff061ad 100644
--- a/externs/browser/w3c_rtc.js
+++ b/externs/browser/w3c_rtc.js
@@ -3440,11 +3440,10 @@ RTCPeerConnection.prototype.removeStream = function(stream) {};

 /**
  * @param {!MediaStreamTrack} track
- * @param {!MediaStream} stream
- * @param {...MediaStream} var_args Additional streams.
+ * @param {...MediaStream} var_args Optional streams.
  * @return {!RTCRtpSender}
  */
-RTCPeerConnection.prototype.addTrack = function(track, stream, var_args) {};
+RTCPeerConnection.prototype.addTrack = function(track, var_args) {};

 /**
  * @param {!MediaStreamTrack|string} trackOrKind
@mhausner
Copy link
Contributor

Please file a PR. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants