import { ConsoleLogger , DefaultVideoTransformDevice , LogLevel , MeetingSession } from "amazon-chime-sdk-js" ; import { VirtualBackground , VirtualBackgroundSegmentationType } from "../frame/VirtualBackground" ; export class VideoInputDeviceSetting { private meetingSession : MeetingSession ; private virtualBackgroundProcessor : VirtualBackground | null = null ; private videoTransformDevice : DefaultVideoTransformDevice | null = null ; private deviceMediaStream : MediaStream | null = null ; private currentVideoDevice : string = "" ; private stateChanging : boolean = false ; videoInput : MediaStream | string | null = null ; videoInputEnable : boolean = true ; virtualBackgroundEnable : boolean = true ; virtualForeGroundEnable : boolean = false ; virtualBackgroundSegmentationType : VirtualBackgroundSegmentationType = "None" ; previewVideoElement : HTMLVideoElement | null = null ; constructor ( meetingSession ) { this . meetingSession = meetingSession ; } private setVideoInputCommon = async ( device , enable , vbgEnable , vfgEnable ) => { console . log ( "setVideoInput" , device , enable , vbgEnable , vfgEnable ) ; if ( device === null || enable === false ) { console . log ( "[DeviceSetting] VideoInput is null or disabled." ) ; await this . meetingSession . audioVideo . chooseVideoInputDevice ( null ) ; return ; } if ( vbgEnable === false && vfgEnable === false ) { console . log ( "[DeviceSetting] VideoInput doesn't use virtual background. 11" ) ; await this . meetingSession . audioVideo . chooseVideoInputDevice ( device ) ; console . log ( "[DeviceSetting] VideoInput doesn't use virtual background. 2" ) ; return ; } if ( this . virtualBackgroundProcessor === null ) { console . log ( "[DeviceSetting] VirtualBackgroundProcessor is null. New one is created." ) ; this . virtualBackgroundProcessor = new VirtualBackground ( ) ; } else { console . log ( "[DeviceSetting] Existing VirtualBackgroundProcessor is used." ) ; } let newTransformDeviceCreated = false ; if ( this . videoTransformDevice === null ) { console . log ( "[DeviceSetting] VideoTransformDevice is null. New one is created." ) ; this . videoTransformDevice = new DefaultVideoTransformDevice ( new ConsoleLogger ( "MeetingLogs" , LogLevel . OFF ) , device , [ this . virtualBackgroundProcessor ] ) ; newTransformDeviceCreated = true ; this . videoInput = device ; } else { console . log ( "[DeviceSetting] Existing VideoTransformDevice is used." ) ; } if ( device !== this . videoInput || newTransformDeviceCreated === false ) { this . videoTransformDevice = await this . videoTransformDevice . chooseNewInnerDevice ( device ) ; this . videoInput = device ; } await this . meetingSession . audioVideo . chooseVideoInputDevice ( this . videoTransformDevice ) ; } ; private applyAttributes = ( ) => { this . virtualBackgroundProcessor ?. setVirtualBackgroundType ( this . virtualBackgroundSegmentationType ) ; } ; setVideoInput = async ( val ) => { this . videoInput = val ; await this . setVideoInputCommon ( this . videoInput , this . videoInputEnable , this . virtualBackgroundEnable , this . virtualForeGroundEnable ) ; await this . applyAttributes ( ) ; } ; setVideoInputEnable = async ( val ) => { this . videoInputEnable = val ; await this . setVideoInputCommon ( this . videoInput , this . videoInputEnable , this . virtualBackgroundEnable , this . virtualForeGroundEnable ) ; await this . applyAttributes ( ) ; } ; setVirtualBackgrounEnable = async ( val ) => { this . virtualBackgroundEnable = val ; await this . setVideoInputCommon ( this . videoInput , this . videoInputEnable , this . virtualBackgroundEnable , this . virtualForeGroundEnable ) ; await this . applyAttributes ( ) ; } ; setVirtualForegrounEnable = async ( val ) => { this . virtualForeGroundEnable = val ; await this . setVideoInputCommon ( this . videoInput , this . videoInputEnable , this . virtualBackgroundEnable , this . virtualForeGroundEnable ) ; await this . applyAttributes ( ) ; } ; setVirtualBackgroundSegmentationType = async ( val ) => { this . virtualBackgroundSegmentationType = val ; this . applyAttributes ( ) ; } ; setBackgroundImagePath = async ( path ) => { if ( this . virtualBackgroundProcessor ) { this . virtualBackgroundProcessor . setBackgroundImage ( path ) ; } } ; setPreviewVideoElement = ( val ) => { this . previewVideoElement = val ; } ; startPreview = ( ) => { if ( this . previewVideoElement ) { try { this . meetingSession . audioVideo . startVideoPreviewForVideoInput ( this . previewVideoElement ) ; } catch ( e ) { console . log ( "PREVIEW EXCEPTION:" , e ) ; } } else { console . log ( "[DeviceSetting] Preview VideoElement is not set for start." ) ; } } ; stopPreview = ( ) => { if ( this . previewVideoElement ) { this . meetingSession . audioVideo . stopVideoPreviewForVideoInput ( this . previewVideoElement ) ; } else { console . log ( "[DeviceSetting] Preview VideoElement is not set for stop." ) ; } } ; startLocalVideoTile = ( ) => { this . meetingSession . audioVideo . startLocalVideoTile ( ) ; } ; stopLocalVideoTile = ( ) => { this . meetingSession . audioVideo . stopLocalVideoTile ( ) ; } ; setJBFSize = ( width , height ) => { } ; getJBFSize = ( ) => { } ; setLightWrappingEnable = ( val ) => { if ( this . virtualBackgroundProcessor ) { this . virtualBackgroundProcessor . GMTfjs . googleMeetLightWrappingEnable = val ; this . virtualBackgroundProcessor . GMTflite . googleMeetLightWrappingEnable = val ; } } ; getLightWrappingEnable = ( ) => { return this . virtualBackgroundProcessor ?. GMTfjs . googleMeetLightWrappingEnable ; } ; }