1
- import { RefObject , useEffect , useRef , useState } from 'react' ;
1
+ import type { RefObject } from 'react' ;
2
+ import { useEffect , useRef , useState } from 'react' ;
2
3
3
- import { Image , readCanvas , writeCanvas } from '../../src' ;
4
- import { convertColor } from '../../src/operations/convertColor' ;
5
- import { useCameraContext } from '../contexts/cameraContext' ;
4
+ import type { Image } from '../../src/index.js' ;
5
+ import { readCanvas , writeCanvas } from '../../src/index.js' ;
6
+ import { convertColor } from '../../src/operations/convertColor.js' ;
7
+ import { useCameraContext } from '../contexts/cameraContext.js' ;
6
8
7
- import ErrorAlert from './ErrorAlert' ;
8
- import SnapshotImage from './SnapshotImage' ;
9
- import UnavailableCamera from './UnavailableCamera' ;
9
+ import ErrorAlert from './ErrorAlert.js ' ;
10
+ import SnapshotImage from './SnapshotImage.js ' ;
11
+ import UnavailableCamera from './UnavailableCamera.js ' ;
10
12
11
13
export type TransformFunction =
12
14
| ( ( image : Image ) => Image )
13
15
| ( ( image : Image , snapshot : Image | null ) => Image ) ;
14
16
15
17
interface CameraTransformProps {
16
18
transform : TransformFunction ;
17
- canvasInputRef : RefObject < HTMLCanvasElement > ;
19
+ canvasInputRef : RefObject < HTMLCanvasElement | null > ;
18
20
snapshotUrl : string ;
19
21
snapshotImageRef : RefObject < Image | null > ;
20
22
}
@@ -36,7 +38,7 @@ export default function CameraTransform(props: CameraTransformProps) {
36
38
const video = videoRef . current as HTMLVideoElement ;
37
39
let nextFrameRequest : number ;
38
40
video . srcObject = selectedCamera . stream ;
39
- video . onloadedmetadata = ( ) => {
41
+ video . addEventListener ( 'loadedmetadata' , ( ) => {
40
42
video
41
43
. play ( )
42
44
. then ( ( ) => {
@@ -60,16 +62,16 @@ export default function CameraTransform(props: CameraTransformProps) {
60
62
result = convertColor ( result , 'RGBA' ) ;
61
63
}
62
64
writeCanvas ( result , canvasOutput ) ;
63
- } catch ( err ) {
64
- setError ( err . stack ) ;
65
- console . error ( err ) ;
65
+ } catch ( error_ ) {
66
+ setError ( error_ . stack ) ;
67
+ console . error ( error_ ) ;
66
68
}
67
69
nextFrameRequest = requestAnimationFrame ( nextFrame ) ;
68
70
}
69
71
nextFrameRequest = requestAnimationFrame ( nextFrame ) ;
70
72
} )
71
- . catch ( ( err : unknown ) => console . error ( err ) ) ;
72
- } ;
73
+ . catch ( ( error_ : unknown ) => console . error ( error_ ) ) ;
74
+ } ) ;
73
75
74
76
return ( ) => {
75
77
if ( nextFrameRequest ) {
0 commit comments