33
44/* eslint-disable max-classes-per-file */
55/* eslint-disable no-restricted-syntax */
6- /* eslint-disable @typescript-eslint/no-explicit-any */
76/* eslint-disable no-await-in-loop */
87
98import { videoPixelFormatToEnum } from '@signalapp/ringrtc' ;
@@ -38,13 +37,12 @@ type GumTrackConstraintSet = {
3837
3938export class GumVideoCapturer {
4039 private defaultCaptureOptions : GumVideoCaptureOptions ;
41- private localPreview ?: RefObject < HTMLVideoElement > ;
40+ private localPreview ?: HTMLVideoElement ;
4241 private captureOptions ?: GumVideoCaptureOptions ;
4342 private sender ?: VideoFrameSender ;
4443 private mediaStream ?: MediaStream ;
4544 private spawnedSenderRunning = false ;
4645 private preferredDeviceId ?: string ;
47- private updateLocalPreviewIntervalId ?: any ;
4846
4947 constructor ( defaultCaptureOptions : GumVideoCaptureOptions ) {
5048 this . defaultCaptureOptions = defaultCaptureOptions ;
@@ -54,27 +52,15 @@ export class GumVideoCapturer {
5452 return this . captureOptions !== undefined ;
5553 }
5654
57- setLocalPreview ( localPreview : RefObject < HTMLVideoElement > | undefined ) : void {
58- const oldLocalPreview = this . localPreview ?. current ;
55+ setLocalPreview ( localPreview : HTMLVideoElement | undefined ) : void {
56+ const oldLocalPreview = this . localPreview ;
5957 if ( oldLocalPreview ) {
6058 oldLocalPreview . srcObject = null ;
6159 }
6260
6361 this . localPreview = localPreview ;
6462
6563 this . updateLocalPreviewSourceObject ( ) ;
66-
67- // This is a dumb hack around the fact that sometimes the
68- // this.localPreview.current is updated without a call
69- // to setLocalPreview, in which case the local preview
70- // won't be rendered.
71- if ( this . updateLocalPreviewIntervalId !== undefined ) {
72- clearInterval ( this . updateLocalPreviewIntervalId ) ;
73- }
74- this . updateLocalPreviewIntervalId = setInterval (
75- this . updateLocalPreviewSourceObject . bind ( this ) ,
76- 1000
77- ) ;
7864 }
7965
8066 async enableCapture ( options ?: GumVideoCaptureOptions ) : Promise < void > {
@@ -98,11 +84,6 @@ export class GumVideoCapturer {
9884 disable ( ) : void {
9985 this . stopCapturing ( ) ;
10086 this . stopSending ( ) ;
101-
102- if ( this . updateLocalPreviewIntervalId !== undefined ) {
103- clearInterval ( this . updateLocalPreviewIntervalId ) ;
104- }
105- this . updateLocalPreviewIntervalId = undefined ;
10687 }
10788
10889 async setPreferredDevice ( deviceId : string ) : Promise < void > {
@@ -361,11 +342,9 @@ export class GumVideoCapturer {
361342 }
362343
363344 private updateLocalPreviewSourceObject ( ) : void {
364- if ( ! this . localPreview ) {
365- return ;
366- }
367- const localPreview = this . localPreview . current ;
345+ const { localPreview } = this ;
368346 if ( ! localPreview ) {
347+ log . warn ( 'No local preview to update' ) ;
369348 return ;
370349 }
371350
@@ -376,6 +355,7 @@ export class GumVideoCapturer {
376355 }
377356
378357 if ( mediaStream && this . captureOptions ) {
358+ log . warn ( 'Enabling local preview' ) ;
379359 localPreview . srcObject = mediaStream ;
380360 if ( localPreview . width === 0 ) {
381361 localPreview . width = this . captureOptions . maxWidth ;
@@ -384,6 +364,7 @@ export class GumVideoCapturer {
384364 localPreview . height = this . captureOptions . maxHeight ;
385365 }
386366 } else {
367+ log . warn ( 'Disabling local preview' ) ;
387368 localPreview . srcObject = null ;
388369 }
389370 }
@@ -400,7 +381,7 @@ export class CanvasVideoRenderer {
400381 private buffer : Uint8Array ;
401382 private imageData ?: ImageData ;
402383 private source ?: VideoFrameSource ;
403- private rafId ?: any ;
384+ private rafId ?: ReturnType < typeof requestAnimationFrame > ;
404385
405386 constructor ( ) {
406387 this . buffer = new Uint8Array ( MAX_VIDEO_CAPTURE_BUFFER_SIZE ) ;
0 commit comments