Skip to content

Commit

Permalink
Avoid freezing when stopping media stram tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Nobbe committed Mar 14, 2021
1 parent 938f13f commit c3376d1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,21 @@ class CameraPhoto {
stopCamera () {
return new Promise((resolve, reject) => {
if (this.stream) {
// Clear video.srcObject before stopping tracks
this.videoElement.srcObject = null;

this.stream.getTracks().forEach(function (track) {
// Delete a track before stopping it
this.stream.removeTrack(track);

// Stop track
track.stop();
});

this.videoElement.src = '';
this.stream = null;
this._setSettings(null);

resolve();
}
reject(Error('no stream to stop!'));
Expand Down

0 comments on commit c3376d1

Please sign in to comment.