import AudioVideoControllerState from '../audiovideocontroller/AudioVideoControllerState' ; import MeetingSessionStatusCode from '../meetingsession/MeetingSessionStatusCode' ; import RealtimeAttendeePositionInFrame from '../realtimecontroller/RealtimeAttendeePositionInFrame' ; import BaseTask from './BaseTask' ; export default class WaitForAttendeePresenceTask extends BaseTask { protected taskName = 'WaitForAttendeePresenceTask' ; private cancelPromise : undefined | ( ( error : Error ) => void ) ; constructor ( private context ) { super ( context . logger ) ; } cancel ( ) { if ( this . cancelPromise ) { const error = new Error ( `canceling ${ this . name ( ) } due to the meeting status code: ${ MeetingSessionStatusCode . NoAttendeePresent }` ) ; this . cancelPromise ( error ) ; delete this . cancelPromise ; } } async run ( ) { const attendeeId = this . context . meetingSessionConfiguration . credentials . attendeeId ; return new Promise < void > ( ( resolve , reject ) => { const handler = ( presentAttendeeId , present , _externalUserId , _dropped , _pos ) : void => { if ( attendeeId === presentAttendeeId && present ) { this . context . realtimeController . realtimeUnsubscribeToAttendeeIdPresence ( handler ) ; resolve ( ) ; delete this . cancelPromise ; } } ; this . cancelPromise = ( error ) => { this . context . realtimeController . realtimeUnsubscribeToAttendeeIdPresence ( handler ) ; reject ( error ) ; } ; this . context . realtimeController . realtimeSubscribeToAttendeeIdPresence ( handler ) ; } ) ; } }