in src/task/MonitorTask.ts [142:196]
private checkResubscribe(clientMetricReport: ClientMetricReport): boolean {
if (this.isResubscribeCheckPaused) {
this.context.logger.info(
'Resubscribe check is paused, setting incoming client metric report as pending'
);
this.pendingMetricsReport = clientMetricReport;
return;
} else {
this.pendingMetricsReport = undefined;
}
const metricReport = clientMetricReport.getObservableMetrics();
const availableSendBandwidth = metricReport.availableOutgoingBitrate;
const nackCountPerSecond = metricReport.nackCountReceivedPerSecond;
let needResubscribe = false;
this.context.videoDownlinkBandwidthPolicy.updateMetrics(clientMetricReport);
const resubscribeForDownlink = this.context.videoDownlinkBandwidthPolicy.wantsResubscribe();
needResubscribe = needResubscribe || resubscribeForDownlink;
if (resubscribeForDownlink) {
const videoSubscriptionIdSet = this.context.videoDownlinkBandwidthPolicy.chooseSubscriptions();
// Same logic as in `ReceiveVideoStreamIndexTask`, immediately truncating rather then truncating on subscribe
// avoids any issues with components (e.g. transceiver controller) along the way.
this.context.videosToReceive = videoSubscriptionIdSet.truncate(
this.context.videoSubscriptionLimit
);
if (videoSubscriptionIdSet.size() > this.context.videosToReceive.size()) {
this.logger.warn(
`Video receive limit exceeded. Limiting the videos to ${this.context.videosToReceive.size()}. Please consider using AllHighestVideoBandwidthPolicy or VideoPriorityBasedPolicy along with chooseRemoteVideoSources api to select the video sources to be displayed.`
);
}
this.logger.info(
`trigger resubscribe for down=${resubscribeForDownlink}; videosToReceive=[${this.context.videosToReceive.array()}]`
);
}
if (this.context.videoTileController.hasStartedLocalVideoTile()) {
this.context.videoUplinkBandwidthPolicy.updateConnectionMetric({
uplinkKbps: availableSendBandwidth / 1000,
nackCountPerSecond: nackCountPerSecond,
});
const resubscribeForUplink = this.context.videoUplinkBandwidthPolicy.wantsResubscribe();
needResubscribe = needResubscribe || resubscribeForUplink;
if (resubscribeForUplink) {
this.logger.info(
`trigger resubscribe for up=${resubscribeForUplink}; videosToReceive=[${this.context.videosToReceive.array()}]`
);
this.context.videoUplinkBandwidthPolicy.chooseEncodingParameters();
}
}
return needResubscribe;
}