Skip to content

Commit

Permalink
Now using MediaStream.getVideoTracks() and MediaStreamTrack.stop() on…
Browse files Browse the repository at this point in the history
… unload, if they exist. Falling back to MediaStream.stop() as a last resort.
  • Loading branch information
jhuckaby committed Oct 31, 2015
1 parent 7825d6b commit d323a64
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion webcam.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ var Webcam = {
if (this.userMedia) {
window.addEventListener( 'beforeunload', function(event) {
if (self.stream) {
self.stream.stop();
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;
}
} );
Expand Down
Loading

0 comments on commit d323a64

Please sign in to comment.