w3c / mediacapture-extensions

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

MediaStreamTrack.stop() should be async #36

Open sonntag-philipp opened 3 years ago

sonntag-philipp commented 3 years ago

Hello there,

I'm currently working with the mediacapture api in different browsers. While working on the MediaStreamTracks, I've noticed that the stop method doesn't provide a way to get notified when the track is actually stopped by the underlying user agent.

This can cause issues in platforms, where a camera can only be opened once by the browser api.

My proposal for a solution would be to make the .stop() method async by returning a promise. The promise should be resolved when the user agent made sure, that the media track is stopped.

The described method in the RFC.

fippo commented 3 years ago

does that require an API change or should the user agent ensure pending closes are done before attempting to open a device?

sonntag-philipp commented 3 years ago

Yes, I think it would require an api change as the method signature of MediaStreamTrack.stop() would change to return a promise. Anyway, this wouldn't affect existing uses of the method. They could just ignore the return value.

guidou commented 3 years ago

I agree that returning a promise would be useful and allow more flexibility for implementation.

alvestrand commented 3 years ago

Changing the API does not seem like a good option, given that this is a rather old and stable spec by now. Moving it to mediacapture-extensions in order to figure out how to solve the problem.