Skip to content

Commit df32388

Browse files
committed
feat(QrcodeStream): capabilities in init payload
1 parent d682432 commit df32388

File tree

2 files changed

+43
-19
lines changed

2 files changed

+43
-19
lines changed

src/components/QrcodeStream.vue

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,16 @@ export default {
152152
},
153153
154154
torch() {
155-
this.$emit("init", this.init());
155+
this.init();
156156
},
157157
158158
constraints() {
159-
this.$emit("init", this.init());
159+
this.init();
160160
}
161161
},
162162
163163
mounted() {
164-
this.$emit("init", this.init());
164+
this.init();
165165
},
166166
167167
beforeDestroy() {
@@ -171,23 +171,41 @@ export default {
171171
},
172172
173173
methods: {
174-
async init() {
175-
this.beforeResetCamera();
176-
177-
if (this.constraints === undefined) {
178-
this.cameraInstance = null;
179-
} else {
180-
this.cameraInstance = await Camera(this.constraints, this.$refs.video, {
181-
torch: this.torch
182-
});
183-
184-
// if the component is destroyed before `cameraInstance` resolves a
185-
// `beforeDestroy` hook has no chance to clear the remaining camera
186-
// stream.
187-
if (this.destroyed) {
188-
this.cameraInstance.stop();
174+
init() {
175+
const promise = (async () => {
176+
this.beforeResetCamera();
177+
178+
if (this.constraints === undefined) {
179+
this.cameraInstance = null;
180+
181+
return {
182+
capabilities: {}
183+
};
184+
} else {
185+
this.cameraInstance = await Camera(
186+
this.constraints,
187+
this.$refs.video,
188+
{
189+
torch: this.torch
190+
}
191+
);
192+
193+
const capabilities = this.cameraInstance.getCapabilities();
194+
195+
// if the component is destroyed before `cameraInstance` resolves a
196+
// `beforeDestroy` hook has no chance to clear the remaining camera
197+
// stream.
198+
if (this.destroyed) {
199+
this.cameraInstance.stop();
200+
}
201+
202+
return {
203+
capabilities
204+
};
189205
}
190-
}
206+
})();
207+
208+
this.$emit("init", promise);
191209
},
192210
193211
startScanning() {

src/misc/camera.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ class Camera {
1616
captureFrame() {
1717
return imageDataFromVideo(this.videoEl);
1818
}
19+
20+
getCapabilities() {
21+
const [track] = this.stream.getVideoTracks();
22+
23+
return track.getCapabilities();
24+
}
1925
}
2026

2127
const INSECURE_CONTEXT = window.isSecureContext !== true;

0 commit comments

Comments
 (0)