import { CallingHandlers } from '@internal/calling-component-bindings' ; import { CommonProperties , toFlatCommunicationIdentifier } from '@internal/acs-ui-common' ; import { ReactElement } from 'react' ; import memoizeOne from 'memoize-one' ; import { CallAdapter } from '..' ; import { useAdapter } from '../adapter/CallAdapterProvider' ; import { isCameraOn } from '../utils' ; private export const useHandlers = < PropsT > ( _component ) : Pick < CallingHandlers , CommonProperties < CallingHandlers , PropsT > > => { return createCompositeHandlers ( useAdapter ( ) ) ; } ; const createCompositeHandlers = memoizeOne ( ( adapter ) : CallingHandlers => ( { onCreateLocalStreamView : async ( options ) => { await adapter . createStreamView ( undefined , options ) ; } , onCreateRemoteStreamView : async ( userId , options ) => { await adapter . createStreamView ( userId , options ) ; } , onHangUp : async ( ) => { await adapter . leaveCall ( ) ; } , onRemoveParticipant : async ( userId ) => { await adapter . removeParticipant ( userId ) ; } , onSelectCamera : async ( deviceInfo , options ) => { await adapter . setCamera ( deviceInfo , options ) ; } , onSelectMicrophone : async ( deviceInfo ) => { await adapter . setMicrophone ( deviceInfo ) ; } , onSelectSpeaker : async ( deviceInfo ) => { await adapter . setSpeaker ( deviceInfo ) ; } , onStartCall : ( participants ) => { const rawIds = participants . map ( ( participant ) => toFlatCommunicationIdentifier ( participant ) ) ; return adapter . startCall ( rawIds ) ; } , onStartScreenShare : async ( ) => { await adapter . startScreenShare ( ) ; } , onStopScreenShare : async ( ) => { await adapter . stopScreenShare ( ) ; } , onToggleCamera : async ( options ) => { isCameraOn ( adapter . getState ( ) ) ? await adapter . stopCamera ( ) : await adapter . startCamera ( options ) ; } , onToggleMicrophone : async ( ) => { return adapter . getState ( ) . call ?. isMuted ? await adapter . unmute ( ) : await adapter . mute ( ) ; } , onToggleScreenShare : async ( ) => { return adapter . getState ( ) . call ?. isScreenSharingOn ? await adapter . stopScreenShare ( ) : await adapter . startScreenShare ( ) ; } , onStartLocalVideo : async ( ) => { if ( adapter . getState ( ) . call ) { return adapter . startCamera ( ) ; } } , onDisposeLocalStreamView : async ( ) => { return adapter . disposeStreamView ( ) ; } , onDisposeRemoteStreamView : async ( userId ) => { return adapter . disposeStreamView ( userId ) ; } } ) ) ;