Skip to content

Commit

Permalink
Moved stream stop handling code into reset(), and now calling reset()…
Browse files Browse the repository at this point in the history
… from within onunload listener.
  • Loading branch information
jhuckaby committed Nov 1, 2015
1 parent d323a64 commit 1934f01
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
25 changes: 12 additions & 13 deletions webcam.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,7 @@ var Webcam = {
// Make sure media stream is closed when navigating away from page
if (this.userMedia) {
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;
}
self.reset();
} );
}
},
Expand Down Expand Up @@ -187,7 +176,17 @@ var Webcam = {
this.unflip();

if (this.userMedia) {
try { this.stream.stop(); } catch (e) {;}
if (this.stream) {
if (this.stream.getVideoTracks) {
// get video track to call stop on it
var tracks = this.stream.getVideoTracks();
if (tracks && tracks[0] && tracks[0].stop) tracks[0].stop();
}
else if (this.stream.stop) {
// deprecated, may be removed in future
this.stream.stop();
}
}
delete this.stream;
delete this.video;
}
Expand Down
Loading

0 comments on commit 1934f01

Please sign in to comment.