import { MeetingAdapter } from './MeetingAdapter' ; import { CallAdapter , CallAdapterState } from '../../CallComposite' ; import { meetingPageToCallPage } from '../state/MeetingCompositePage' ; import { VideoStreamOptions } from '@internal/react-components' ; import { AudioDeviceInfo , VideoDeviceInfo , Call , PermissionConstraints } from '@azure/communication-calling' ; import { MeetingAdapterState , MeetingState } from '..' ; import { CallState } from '@internal/calling-stateful-client' ; import { callParticipantsFromMeetingParticipants } from '../state/MeetingParticipants' ; function callStateFromMeetingState ( meetingState ) { return { id : meetingState . id , callerInfo : meetingState . callerInfo , state : meetingState . state , callEndReason : meetingState . meetingEndReason , direction : 'Incoming' , isMuted : meetingState . isMuted , isScreenSharingOn : meetingState . isScreenSharingOn , localVideoStreams : meetingState . localVideoStreams , transcription : meetingState . transcription , recording : meetingState . recording , screenShareRemoteParticipant : meetingState . screenShareRemoteParticipant , startTime : meetingState . startTime , endTime : meetingState . endTime , diagnostics : meetingState . diagnostics , remoteParticipants : callParticipantsFromMeetingParticipants ( meetingState . participants ) , remoteParticipantsEnded : callParticipantsFromMeetingParticipants ( meetingState . participantsEnded ) , dominantSpeakers : meetingState . dominantSpeakers } ; } function callAdapterStateFromMeetingAdapterState ( meetingState ) { return { isLocalPreviewMicrophoneEnabled : meetingState . isLocalPreviewMicrophoneEnabled , page : meetingPageToCallPage ( meetingState . page ) , userId : meetingState . userId , displayName : meetingState . displayName , call : meetingState . meeting ? callStateFromMeetingState ( meetingState . meeting ) : undefined , devices : meetingState . devices , isTeamsCall : meetingState . isTeamsCall , latestErrors : { } } ; } private export class MeetingBackedCallAdapter implements CallAdapter { private meetingAdapter : MeetingAdapter ; private eventStore : Map < ( state : CallAdapterState ) => void , ( state : MeetingAdapterState ) => void > = new Map ( ) ; constructor ( meetingAdapter ) { this . meetingAdapter = meetingAdapter ; } public on = ( event , listener ) : void => this . meetingAdapter . on ( event , listener ) ; public off = ( event , listener ) : void => this . meetingAdapter . off ( event , listener ) ; public onStateChange = ( handler ) : void => { const convertedHandler = ( state ) : void => { handler ( callAdapterStateFromMeetingAdapterState ( state ) ) ; } ; this . meetingAdapter . onStateChange ( convertedHandler ) ; this . eventStore . set ( handler , convertedHandler ) ; } ; public offStateChange = ( handler ) : void => { const convertedHandler = this . eventStore . get ( handler ) ; convertedHandler && this . meetingAdapter . offStateChange ( convertedHandler ) ; } ; public getState = ( ) : CallAdapterState => callAdapterStateFromMeetingAdapterState ( this . meetingAdapter . getState ( ) ) ; public dispose = ( ) : void => this . meetingAdapter . dispose ( ) ; public joinCall = ( microphoneOn ? ) : Call | undefined => { return this . meetingAdapter . joinMeeting ( microphoneOn ) ; } ; public leaveCall = async ( ) : Promise < void > => await this . meetingAdapter . leaveMeeting ( ) ; public startCall = ( participants ) : Call | undefined => { return this . meetingAdapter . startMeeting ( participants ) ; } ; public setCamera = async ( sourceId , options ? ) : Promise < void > => await this . meetingAdapter . setCamera ( sourceId , options ) ; public setMicrophone = async ( sourceId ) : Promise < void > => await this . meetingAdapter . setMicrophone ( sourceId ) ; public setSpeaker = async ( sourceId ) : Promise < void > => await this . meetingAdapter . setSpeaker ( sourceId ) ; public askDevicePermission = async ( constraints ) : Promise < void > => await this . meetingAdapter . askDevicePermission ( constraints ) ; public queryCameras = async ( ) : Promise < VideoDeviceInfo [ ] > => await this . meetingAdapter . queryCameras ( ) ; public queryMicrophones = async ( ) : Promise < AudioDeviceInfo [ ] > => await this . meetingAdapter . queryMicrophones ( ) ; public querySpeakers = async ( ) : Promise < AudioDeviceInfo [ ] > => await this . meetingAdapter . querySpeakers ( ) ; public startCamera = async ( options ? ) : Promise < void > => await this . meetingAdapter . startCamera ( options ) ; public stopCamera = async ( ) : Promise < void > => await this . meetingAdapter . stopCamera ( ) ; public mute = async ( ) : Promise < void > => await this . meetingAdapter . mute ( ) ; public unmute = async ( ) : Promise < void > => await this . meetingAdapter . unmute ( ) ; public startScreenShare = async ( ) : Promise < void > => await this . meetingAdapter . startScreenShare ( ) ; public stopScreenShare = async ( ) : Promise < void > => await this . meetingAdapter . stopScreenShare ( ) ; public removeParticipant = async ( userId ) : Promise < void > => await this . meetingAdapter . removeParticipant ( userId ) ; public createStreamView = async ( remoteUserId ? , options ? ) : Promise < void > => await this . meetingAdapter . createStreamView ( remoteUserId , options ) ; public disposeStreamView = async ( remoteUserId ? , options ? ) : Promise < void > => await this . meetingAdapter . disposeStreamView ( remoteUserId , options ) ; }