Merge branch 'livekit' into voip-team/rebased-multiSFU

This commit is contained in:
Robin
2025-10-22 23:28:26 -04:00
4 changed files with 130 additions and 13 deletions

View File

@@ -110,10 +110,11 @@ export class TileStore {
*/
export class TileStoreBuilder {
private spotlight: SpotlightTileData | null = null;
private readonly prevSpotlightSpeaker =
private readonly prevSpotlightSpeaker: UserMediaViewModel | null =
this.prevSpotlight?.media.length === 1 &&
"speaking" in this.prevSpotlight.media[0] &&
this.prevSpotlight.media[0];
"speaking$" in this.prevSpotlight.media[0]
? this.prevSpotlight.media[0]
: null;
private readonly prevGridByMedia: Map<
MediaViewModel,
@@ -193,8 +194,9 @@ export class TileStoreBuilder {
if (
media === this.prevSpotlightSpeaker &&
this.spotlight.media.length === 1 &&
"speaking" in this.spotlight.media[0] &&
this.prevSpotlightSpeaker !== this.spotlight.media[0]
"speaking$" in this.spotlight.media[0] &&
this.prevSpotlightSpeaker !==
(this.spotlight.media[0] satisfies UserMediaViewModel)
) {
const prev = this.prevGridByMedia.get(this.spotlight.media[0]);
if (prev !== undefined) {
@@ -252,6 +254,33 @@ export class TileStoreBuilder {
this.numGridEntries++;
}
/**
* Sets up a PiP tile for the given media. This is a special kind of grid tile
* that is expected to stand on its own and switch between speakers, so this
* method will more eagerly try to reuse an existing tile, replacing its
* media, than registerGridTile would.
*/
public registerPipTile(media: UserMediaViewModel): void {
if (DEBUG_ENABLED)
logger.debug(
`[TileStore, ${this.generation}] register PiP tile: ${media.member?.rawDisplayName ?? "[👻]"}`,
);
// If there is a single grid tile that we can reuse
if (this.prevGrid.length === 1) {
const entry = this.prevGrid[0];
this.stationaryGridEntries[0] = entry;
// Do the media swap
entry.media = media;
this.prevGridByMedia.delete(entry.media);
this.prevGridByMedia.set(media, [entry, 0]);
} else {
this.visibleGridEntries.push(new GridTileData(media));
}
this.numGridEntries++;
}
/**
* Constructs a new collection of all registered tiles, transferring ownership
* of the tiles to the new collection. Any tiles present in the previous