jhuckaby / webcamjs

HTML5 Webcam Image Capture Library with Flash Fallback
MIT License
2.5k stars 1.11k forks source link

'MediaStream.stop()' is deprecated #110

Closed heldrida closed 8 years ago

heldrida commented 9 years ago

'MediaStream.stop()' is deprecated and will be removed in M47, around November 2015. Please use 'MediaStream.active' instead.

jhuckaby commented 9 years ago

Thanks for letting me know. I'll get this taken care of soon.

jaaksarv commented 8 years ago

Any news on this? Nov 2015 coming tomorrow:)

jhuckaby commented 8 years ago

Happy Halloween! Sorry I neglected this issue until now. I have been terribly busy. Beginning researching on it...

Hmmm, so according to MDN, MediaStream.active is a read-only property, so it cannot be used as a direct replacement for MediaStream.stop(). Reference:

https://developer.mozilla.org/en-US/docs/Web/API/MediaStream

I believe what I need to do instead is get the list of video MediaStreamTrack objects via getVideoTracks(), grab the first track from that array, then call MediaStreamTrack.stop() on that.

This is all theoretical because none of this stuff is implemented yet, but I think I can code it defensively, something like this:

window.addEventListener( 'beforeunload', function(event) {
    if (self.stream) {
        if (self.stream.getVideoTracks) {
            // get video track to call stop on it
            var tracks = self.stream.getVideoTracks();
            if (tracks && tracks[0] && tracks[0].stop) tracks[0].stop();
        }
        else if (self.stream.stop) {
            // deprecated, may be removed in future
            self.stream.stop();
        }
        self.stream = null;
    }
} );

This seems to work in Firefox 41 and Chrome 46.

Committed: https://github.com/jhuckaby/webcamjs/commit/d323a64d10acf2965ad456de41d3be5fed042c24

Will let this bake for a while in case there are any problems. It'll be folded into 1.0.5 whenever that comes out :)

Thanks for reporting this!

- Joe

jaaksarv commented 8 years ago

Will try it out. Thank you Joe

janja-janja commented 8 years ago

Hi @jhuckaby , thanks for that addition, but the warning is still being logged when Webcam.reset() method is hit. Tried reseting using videoTracks, the warning goes but the webcam light stays on.

jhuckaby commented 8 years ago

Oops, I am sorry @yoda-yoda, I forgot about reset(). This has been fixed. Commit: https://github.com/jhuckaby/webcamjs/commit/1934f01d6ad9078bcd8aacca548405c7e4e856cf

Here is a test page which works correctly for me in both Firefox and Chrome -- the webcam light turns off when I click Reset:

http://pixlcore.com/demos/webcamjs/demos/reset.html

Thanks!

janja-janja commented 8 years ago

:clap: Working now. Thanks @jhuckaby