private processBwPausedStreams()

in src/videodownlinkbandwidthpolicy/VideoPriorityBasedPolicy.ts [915:982]


  private processBwPausedStreams(
    remoteInfos: VideoStreamDescription[],
    chosenStreams: VideoStreamDescription[]
  ): void {
    if (!this.tileController) {
      this.logger.warn('tileController not found!');
      return;
    }
    const preferences = this.getCurrentVideoPreferences();
    if (preferences && this.shouldPauseTiles) {
      const videoTiles = this.tileController.getAllVideoTiles();
      for (const preference of preferences) {
        const videoTile = this.getVideoTileForAttendeeId(
          preference.attendeeId,
          videoTiles
        ) as DefaultVideoTile;
        const paused = videoTile?.state().paused || false;
        if (!chosenStreams.some(stream => stream.attendeeId === preference.attendeeId)) {
          // We cannot rely on the existance of video tile to indicate that the source exists in the call
          // because tiles will not be added or removed until after a full renegotiation (i.e. it will
          // be behind the state provided by the index)
          const streamExists = remoteInfos.some(
            stream => stream.attendeeId === preference.attendeeId
          );
          if (videoTile && streamExists) {
            const info = this.optimalReceiveStreams.find(
              stream => stream.attendeeId === preference.attendeeId
            );
            if (info !== undefined) {
              if (!paused) {
                this.logger.info(
                  `bwe: pausing streamId ${info.streamId} attendee ${preference.attendeeId} due to bandwidth`
                );
                this.forEachObserver(observer => {
                  observer.tileWillBePausedByDownlinkPolicy(videoTile.id());
                });
                this.tileController.pauseVideoTile(videoTile.id());
              }
              chosenStreams.push(info);
            }
            this.pausedBwAttendeeIds.add(preference.attendeeId);
          } else if (streamExists) {
            // Create a tile for this participant if one doesn't already exist and mark it as paused
            // Don't include it in the chosen streams because we don't want to subscribe for it then have to pause it.
            const newTile = this.tileController.addVideoTile();
            newTile.bindVideoStream(preference.attendeeId, false, null, 0, 0, 0, null);
            this.forEachObserver(observer => {
              observer.tileWillBePausedByDownlinkPolicy(newTile.id());
            });
            newTile.pause();
            this.logger.info(
              `bwe: Created video tile ${newTile.id()} for bw paused attendee ${
                preference.attendeeId
              }`
            );
            this.pausedBwAttendeeIds.add(preference.attendeeId);
          }
        } else if (paused && this.pausedBwAttendeeIds.has(preference.attendeeId)) {
          this.logger.info(`bwe: unpausing attendee ${preference.attendeeId} due to bandwidth`);
          this.forEachObserver(observer => {
            observer.tileWillBeUnpausedByDownlinkPolicy(videoTile.id());
          });
          this.tileController.unpauseVideoTile(videoTile.id());
          this.pausedBwAttendeeIds.delete(preference.attendeeId);
        }
      }
    }
  }