import { connection } from '@models/api' ; import { getNotificationPermission } from '@models/api/Notification' ; import { manager as audioManager } from '@models/audio' ; import { urlParameters } from '@models/url' ; import participants from '@stores/participants/Participants' ; import JitsiMeetJS , { JitsiLocalTrack } from 'lib-jitsi-meet' ; import { autorun } from 'mobx' ; declare const config ; export function createLocalMic ( ) { const promise = new Promise < JitsiLocalTrack > ( ( resolutionFunc , rejectionFunc ) => { const did = participants . local . devicePreference . audioInputDevice ; JitsiMeetJS . createLocalTracks ( { devices : [ 'audio' ] , constraints : config . rtc . audioConstraints , micDeviceId : did } ) . then ( ( tracks ) => { connection . conference . setLocalMicTrack ( tracks [ 0 ] ) ; resolutionFunc ( tracks [ 0 ] ) ; } ) . catch ( rejectionFunc ) ; } ) ; return promise ; } const DELETE_MIC_TRACK = true ; autorun ( ( ) => { const did = participants . local . devicePreference . audioInputDevice ; const muted = participants . local . muteAudio || participants . local . physics . awayFromKeyboard ; if ( participants . localId && ! muted && urlParameters . testBot === null ) { const track = connection . conference . getLocalMicTrack ( ) ; if ( track && track . getDeviceId ( ) === did ) { return ; } createLocalMic ( ) . finally ( getNotificationPermission ) ; } else { if ( DELETE_MIC_TRACK ) { connection . conference . setLocalMicTrack ( undefined ) . then ( track => { track ?. dispose ( ) ; participants . local . audioLevel = 0 ; } ) ; } else { const track = connection . conference . getLocalMicTrack ( ) ; if ( track ) { connection . conference . removeTrack ( track ) ; } participants . local . audioLevel = 0 ; } } } ) ; autorun ( ( ) => { const did = participants . local . devicePreference . audioOutputDevice ; if ( did ) { audioManager . setAudioOutput ( did ) ; } } ) ; export function createLocalCamera ( ) { const promise = new Promise < JitsiLocalTrack > ( ( resolutionFunc , rejectionFunc ) => { const did = participants . local . devicePreference . videoInputDevice ; JitsiMeetJS . createLocalTracks ( { devices : [ 'video' ] , constraints : config . rtc . videoConstraints , cameraDeviceId : did } ) . then ( ( tracks ) => { connection . conference . setLocalCameraTrack ( tracks [ 0 ] ) ; resolutionFunc ( tracks [ 0 ] ) ; } ) . catch ( rejectionFunc ) ; } ) ; return promise ; } const DELETE_TRACK = true ; autorun ( ( ) => { const did = participants . local . devicePreference . videoInputDevice ; const muted = participants . local . muteVideo || participants . local . physics . awayFromKeyboard ; if ( participants . localId && ! muted && urlParameters . testBot === null ) { const track = connection . conference . getLocalCameraTrack ( ) ; if ( track && track . getDeviceId ( ) === did ) { return ; } createLocalCamera ( ) . finally ( getNotificationPermission ) ; } else { if ( DELETE_TRACK ) { connection . conference . setLocalCameraTrack ( undefined ) . then ( track => track ?. dispose ( ) ) ; } else { const track = connection . conference . getLocalCameraTrack ( ) ; if ( track ) { connection . conference . removeTrack ( track ) ; } } } } ) ;