import { useContext , useEffect , useState } from 'react' ; import { DataMessage } from 'amazon-chime-sdk-js' ; import ChimeSdkWrapper from '../chime/ChimeSdkWrapper' ; import getChimeContext from '../context/getChimeContext' ; import getUIStateContext from '../context/getUIStateContext' ; import ClassMode from '../enums/ClassMode' ; import MessageTopic from '../enums/MessageTopic' ; export default function useFocusMode ( ) { const chime = useContext ( getChimeContext ( ) ) ; const [ focusMode , setFocusMode ] = useState ( false ) ; const [ state ] = useContext ( getUIStateContext ( ) ) ; useEffect ( ( ) => { const callback = ( message ) => { if ( state . classMode === ClassMode . Teacher ) { return ; } const { focus } = message . json ( ) ; chime ?. audioVideo ?. realtimeSetCanUnmuteLocalAudio ( ! focus ) ; if ( focus ) { chime ?. audioVideo ?. realtimeMuteLocalAudio ( ) ; } setFocusMode ( ! ! focus ) ; } ; const focusMessageUpdateCallback = { topic : MessageTopic . Focus , callback } ; chime ?. subscribeToMessageUpdate ( focusMessageUpdateCallback ) ; return ( ) => { chime ?. unsubscribeFromMessageUpdate ( focusMessageUpdateCallback ) ; } ; } , [ ] ) ; return focusMode ; }