Don't use .clone() on tracks to render them in demos #3009
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@fippo made me aware of an incorrect use of the WebRTC APIs in our multistream demos, and namely the fact we were using
clone()
onMediaStreamTrack
instances (both local and remote) to render them. The motivation for using.clone()
was that, especially for remote streams, we can now have more than one audio and/or video track in the same stream, and so relying on the "original" stream wouldn't allow them to be playable in<audio>
or<video>
elements. That said, while the principle is correct, the way we were "solving" this wasn't, as explained in this issue where the bug was reported.As such, this PR changes all the
.clone()
instances, to pass the track directly in theMediaStream
constructor instead. This means that, wherever we had something like this:we do this instead:
This is a PR and not a direct commit just to give people the chance to test all demos and ensure they still work as expected. I tried a few, especially those involving multiple streams, and they all seemed to be fine, but you may want to test this yourselves as well and provide feedback before I merge (which will be soon).