Skip to content
This repository was archived by the owner on Feb 19, 2024. It is now read-only.

Commit 02bee78

Browse files
authored
Merge pull request #37 from hullalex-tek/master
Call stop in beforeDestroy lifecycle hook
2 parents 98c8f4e + d4f4794 commit 02bee78

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/webcam.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ export default {
5959
mounted() {
6060
this.setupMedia();
6161
},
62+
beforeDestroy(){
63+
this.stop();
64+
},
6265
methods: {
6366
legacyGetUserMediaSupport() {
6467
return constraints => {
@@ -182,7 +185,14 @@ export default {
182185
183186
navigator.mediaDevices
184187
.getUserMedia(constraints)
185-
.then(stream => this.loadCameras())
188+
.then(stream => {
189+
//Make sure to stop this MediaStream
190+
let tracks = stream.getTracks();
191+
tracks.forEach(track => {
192+
track.stop();
193+
});
194+
this.loadCameras();
195+
})
186196
.catch(error => this.$emit("error", error));
187197
},
188198
/**

0 commit comments

Comments
 (0)