@@ -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 () {
0 commit comments