@@ -9,7 +9,7 @@ type TethrManagerEvents = {
9
9
}
10
10
export class TethrManager extends EventEmitter < TethrManagerEvents > {
11
11
#ptpusbCameras: Map < USBDevice , TethrPTPUSB > = new Map ( )
12
- #webcamCameras: Map < string , TethrWebcam > = new Map ( )
12
+ #webcam: TethrWebcam | null = null
13
13
14
14
constructor ( ) {
15
15
super ( )
@@ -70,34 +70,21 @@ export class TethrManager extends EventEmitter<TethrManagerEvents> {
70
70
async #refreshPairedWebcam( ) : Promise < TethrWebcam | null > {
71
71
const devices = await this . enumerateWebcamDeviceInfo ( )
72
72
73
- let camera : TethrWebcam | null = null
74
-
75
- const prevCameras = this . #webcamCameras
76
-
77
- this . #webcamCameras = new Map ( )
78
-
79
- for ( const device of devices ) {
80
- if ( device . kind !== 'videoinput' || device . deviceId === '' ) {
81
- continue
82
- }
83
-
84
- const prevCamera = prevCameras . get ( device . deviceId )
73
+ const videoDevices = devices . filter (
74
+ device => device . kind === 'videoinput' && device . deviceId !== ''
75
+ )
85
76
86
- if ( prevCamera ) {
87
- this . #webcamCameras. set ( device . deviceId , prevCamera )
88
- } else {
89
- camera = new TethrWebcam ( device )
90
- this . #webcamCameras. set ( device . deviceId , camera )
91
- }
77
+ if ( ! this . #webcam && videoDevices . length > 0 ) {
78
+ this . #webcam = new TethrWebcam ( )
92
79
}
93
80
94
- return camera ?? [ ... this . #webcamCameras . values ( ) ] [ 0 ] ?? null
81
+ return this . #webcam
95
82
}
96
83
97
84
#emitPairedCameras( ) {
98
85
const cameras = [
99
86
...this . #ptpusbCameras. values ( ) ,
100
- ...this . #webcamCameras . values ( ) ,
87
+ ...( this . #webcam ? [ this . #webcam ] : [ ] ) ,
101
88
]
102
89
103
90
this . emit ( 'pairedCameraChange' , cameras )
0 commit comments