import { CallAdapterState , CallCompositePage } from '../adapter/CallAdapter' ; import { _isInCall , _isPreviewOn , _isInLobbyOrConnecting } from '@internal/calling-component-bindings' ; import { CallControlOptions } from '../components/CallControls' ; import { CallState } from '@internal/calling-stateful-client' ; const ACCESS_DENIED_TEAMS_MEETING_SUB_CODE = 5854 ; const REMOVED_FROM_CALL_SUB_CODES = [ 5000 , 5300 ] ; private export const isCameraOn = ( state ) : boolean => { if ( state . call ) { const stream = state . call . localVideoStreams . find ( ( stream ) => stream . mediaStreamType === 'Video' ) ; return ! ! stream ; } else { if ( state . devices . selectedCamera ) { const previewOn = _isPreviewOn ( state . devices ) ; return previewOn ; } } return false ; } ; private export const reduceCallControlsForMobile = ( callControlOptions ) : CallControlOptions | false => { if ( callControlOptions === false ) { return false ; } const reduceCallControlOptions = callControlOptions === true ? { } : callControlOptions || { } ; reduceCallControlOptions . displayType = 'compact' ; if ( reduceCallControlOptions . screenShareButton !== true ) { reduceCallControlOptions . screenShareButton = false ; } return reduceCallControlOptions ; } ; enum CallEndReasons { LEFT_CALL , ACCESS_DENIED , REMOVED_FROM_CALL } const getCallEndReason = ( call ) : CallEndReasons => { if ( call . callEndReason ?. subCode && call . callEndReason . subCode === ACCESS_DENIED_TEAMS_MEETING_SUB_CODE ) { return CallEndReasons . ACCESS_DENIED ; } if ( call . callEndReason ?. subCode && REMOVED_FROM_CALL_SUB_CODES . includes ( call . callEndReason . subCode ) ) { return CallEndReasons . REMOVED_FROM_CALL ; } if ( call . callEndReason ) { return CallEndReasons . LEFT_CALL ; } throw new Error ( 'No matching call end reason' ) ; } ; param Call param previousCall remarks private export const getCallCompositePage = ( call , previousCall ) : CallCompositePage => { if ( call ) { if ( _isInLobbyOrConnecting ( call ?. state ) ) { return 'lobby' ; } else if ( _isInCall ( call ?. state ) ) { return 'call' ; } else { return 'configuration' ; } } if ( previousCall ) { const reason = getCallEndReason ( previousCall ) ; switch ( reason ) { case CallEndReasons . ACCESS_DENIED : return 'accessDeniedTeamsMeeting' ; case CallEndReasons . REMOVED_FROM_CALL : return 'removedFromCall' ; case CallEndReasons . LEFT_CALL : if ( previousCall . diagnostics . network . latest . noNetwork ) { return 'joinCallFailedDueToNoNetwork' ; } return 'leftCall' ; } } return 'configuration' ; } ;