@@ -15,6 +15,8 @@ const props = withDefaults(defineProps<{
15
15
})
16
16
17
17
enum CameraSignalStatus {
18
+ NotGranted ,
19
+ NotSupported ,
18
20
Waiting ,
19
21
Ready ,
20
22
}
@@ -102,6 +104,11 @@ function disconnectCamera() {
102
104
103
105
async function connectCamera() {
104
106
try {
107
+ if (! (navigator && ' mediaDevices' in navigator && ' getUserMedia' in navigator .mediaDevices && typeof navigator .mediaDevices .getUserMedia === ' function' )) {
108
+ cameraSignalStatus .value = CameraSignalStatus .NotSupported
109
+ return
110
+ }
111
+
105
112
cameraSignalStatus .value = CameraSignalStatus .Waiting
106
113
107
114
stream = await navigator .mediaDevices .getUserMedia ({
@@ -117,6 +124,11 @@ async function connectCamera() {
117
124
video .value ! .play ()
118
125
}
119
126
catch (e ) {
127
+ if ((e as Error ).name === ' NotAllowedError' || (e as Error ).name === ' NotFoundError' ) {
128
+ cameraSignalStatus .value = CameraSignalStatus .NotGranted
129
+ return
130
+ }
131
+
120
132
error .value = e
121
133
}
122
134
}
@@ -169,6 +181,11 @@ function pluse(index: number) {
169
181
}
170
182
171
183
async function scanFrame() {
184
+ if (cameraSignalStatus .value === CameraSignalStatus .NotGranted
185
+ || cameraSignalStatus .value === CameraSignalStatus .NotSupported ) {
186
+ return
187
+ }
188
+
172
189
shutterCount .value += 1
173
190
const canvas = document .createElement (' canvas' )
174
191
canvas .width = video .value ! .videoWidth
@@ -339,11 +356,25 @@ function now() {
339
356
</div >
340
357
<div
341
358
v-if =" cameraSignalStatus === CameraSignalStatus.Waiting"
342
- top =" 50%" left =" [calc( 50%-4.5ch) ]" text =" neutral-500" absolute flex flex-col items-center gap-2 font-mono
359
+ top =" 50%" left =" 50%" translate-x = " [-50% ]" text =" neutral-500" absolute flex flex-col items-center gap-2 font-mono
343
360
>
344
361
<div i-carbon:circle-dash animate-spin animate-duration-5000 text-3xl />
345
362
<p >No Signal</p >
346
363
</div >
364
+ <div
365
+ v-else-if =" cameraSignalStatus === CameraSignalStatus.NotGranted"
366
+ top =" 50%" left =" 50%" translate-x =" [-50%]" text =" neutral-500" absolute flex flex-col items-center gap-2 font-mono
367
+ >
368
+ <div i-carbon:error-outline text-3xl />
369
+ <p >Not Granted</p >
370
+ </div >
371
+ <div
372
+ v-else-if =" cameraSignalStatus === CameraSignalStatus.NotSupported"
373
+ top =" 50%" left =" 50%" translate-x =" [-50%]" text =" neutral-500" absolute flex flex-col items-center gap-2 font-mono
374
+ >
375
+ <div i-carbon:circle-dash text-3xl />
376
+ <p >Not Supported</p >
377
+ </div >
347
378
<p absolute right-1 top-1 border =" ~ gray:50 rounded-md" bg-black:75 px2 py1 text-white font-mono shadow >
348
379
{{ fps.toFixed(0) }} hz | {{ currentValidBytesSpeedFormatted }} <span text-neutral-400 >({{ currentBytesFormatted }})</span >
349
380
</p >
0 commit comments