Skip to content

Commit

Permalink
feat(QrcodeStream): capabilities in init payload
Browse files Browse the repository at this point in the history
  • Loading branch information
gruhn committed May 9, 2020
1 parent d682432 commit df32388
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
56 changes: 37 additions & 19 deletions src/components/QrcodeStream.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,16 @@ export default {
},
torch() {
this.$emit("init", this.init());
this.init();
},
constraints() {
this.$emit("init", this.init());
this.init();
}
},
mounted() {
this.$emit("init", this.init());
this.init();
},
beforeDestroy() {
Expand All @@ -171,23 +171,41 @@ export default {
},
methods: {
async init() {
this.beforeResetCamera();
if (this.constraints === undefined) {
this.cameraInstance = null;
} else {
this.cameraInstance = await Camera(this.constraints, this.$refs.video, {
torch: this.torch
});
// if the component is destroyed before `cameraInstance` resolves a
// `beforeDestroy` hook has no chance to clear the remaining camera
// stream.
if (this.destroyed) {
this.cameraInstance.stop();
init() {
const promise = (async () => {
this.beforeResetCamera();
if (this.constraints === undefined) {
this.cameraInstance = null;
return {
capabilities: {}
};
} else {
this.cameraInstance = await Camera(
this.constraints,
this.$refs.video,
{
torch: this.torch
}
);
const capabilities = this.cameraInstance.getCapabilities();
// if the component is destroyed before `cameraInstance` resolves a
// `beforeDestroy` hook has no chance to clear the remaining camera
// stream.
if (this.destroyed) {
this.cameraInstance.stop();
}
return {
capabilities
};
}
}
})();
this.$emit("init", promise);
},
startScanning() {
Expand Down
6 changes: 6 additions & 0 deletions src/misc/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ class Camera {
captureFrame() {
return imageDataFromVideo(this.videoEl);
}

getCapabilities() {
const [track] = this.stream.getVideoTracks();

return track.getCapabilities();
}
}

const INSECURE_CONTEXT = window.isSecureContext !== true;
Expand Down

0 comments on commit df32388

Please sign in to comment.