import { useContext , useEffect , useState } from 'react' ; import ChimeSdkWrapper from '../chime/ChimeSdkWrapper' ; import getChimeContext from '../context/getChimeContext' ; import RosterType from '../types/RosterType' ; import RosterAttendeeType from '../types/RosterAttendeeType' ; export default function useAttendee ( attendeeId ) { const chime = useContext ( getChimeContext ( ) ) ; const [ attendee , setAttendee ] = useState < RosterAttendeeType > ( chime ?. roster [ attendeeId ] || { } ) ; useEffect ( ( ) => { let previousRosterAttendee = null ; const callback = ( newRoster ) => { const rosterAttendee = newRoster [ attendeeId ] ? ( { ... newRoster [ attendeeId ] } as RosterAttendeeType ) : null ; if ( rosterAttendee ) { if ( ! previousRosterAttendee || previousRosterAttendee . name !== rosterAttendee . name || previousRosterAttendee . muted !== rosterAttendee . muted ) { setAttendee ( rosterAttendee ) ; } } previousRosterAttendee = rosterAttendee ; } ; chime ?. subscribeToRosterUpdate ( callback ) ; return ( ) => { chime ?. unsubscribeFromRosterUpdate ( callback ) ; } ; } , [ ] ) ; return attendee ; }