in src/audiovideocontroller/DefaultAudioVideoController.ts [367:438]
private connectWithPromises(needsToWaitForAttendeePresence: boolean): Task {
const context = this.meetingSessionContext;
// Syntactic sugar.
const timeout = (timeoutMs: number, task: Task): TimeoutTask => {
return new TimeoutTask(this.logger, task, timeoutMs);
};
// First layer.
this.monitorTask = new MonitorTask(
context,
this.configuration.connectionHealthPolicyConfiguration,
this.connectionHealthData
);
const monitor = this.monitorTask.once();
// Second layer.
const receiveAudioInput = new ReceiveAudioInputTask(context).once();
this.receiveIndexTask = new ReceiveVideoStreamIndexTask(context);
// See declaration (unpaused in actionFinishConnecting)
this.monitorTask.pauseResubscribeCheck();
this.receiveIndexTask.pauseIngestion();
const signaling = new SerialGroupTask(this.logger, 'Signaling', [
// If pre-connecting, this will be an existing task that has already been run.
this.createOrReuseSignalingTask(),
new ListenForVolumeIndicatorsTask(context),
new SendAndReceiveDataMessagesTask(context),
new JoinAndReceiveIndexTask(context),
this.receiveIndexTask,
]).once();
// Third layer.
const createPeerConnection = new CreatePeerConnectionTask(context).once(signaling);
const attachMediaInput = new AttachMediaInputTask(context).once(
createPeerConnection,
receiveAudioInput
);
// Mostly serial section -- kept as promises to allow for finer-grained breakdown.
const createSDP = new CreateSDPTask(context).once(attachMediaInput);
const setLocalDescription = new SetLocalDescriptionTask(context).once(createSDP);
const ice = new FinishGatheringICECandidatesTask(context).once(setLocalDescription);
const subscribeAck = new SubscribeAndReceiveSubscribeAckTask(context).once(ice);
this.receiveRemotePauseResumeTask = new ReceiveRemoteVideoPauseResume(context);
this.receiveRemotePauseResumeTask.once(subscribeAck);
// The ending is a delicate time: we need the connection as a whole to have a timeout,
// and for the attendee presence timer to not start ticking until after the subscribe/ack.
return new SerialGroupTask(this.logger, this.wrapTaskName('AudioVideoStart'), [
monitor,
timeout(
this.configuration.connectionTimeoutMs,
new SerialGroupTask(this.logger, 'Peer', [
// The order of these two matters. If canceled, the first one that's still running
// will contribute any special rejection, and we don't want that to be "attendee not found"!
subscribeAck,
this.receiveRemotePauseResumeTask,
needsToWaitForAttendeePresence
? new TimeoutTask(
this.logger,
new ParallelGroupTask(this.logger, 'FinalizeConnection', [
new WaitForAttendeePresenceTask(context),
new SetRemoteDescriptionTask(context),
]),
this.meetingSessionContext.meetingSessionConfiguration.attendeePresenceTimeoutMs
)
: /* istanbul ignore next */ new SetRemoteDescriptionTask(context),
])
),
]);
}