Skip to content

Commit

Permalink
Fix crash in spotlight mode while connecting
Browse files Browse the repository at this point in the history
Because we were hiding even the local participant during initial connection, there would be no participants, and therefore nothing to put in the spotlight. The designs don't really tell us what the connecting state should look like, so I've taken the liberty of restoring it to its former glory of showing the local participant immediately.
  • Loading branch information
robintown committed Jul 12, 2024
1 parent 45c89a2 commit a16f235
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
13 changes: 7 additions & 6 deletions src/grid/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,13 @@ export function Grid<
) as HTMLCollectionOf<HTMLElement>;
for (const slot of slots) {
const id = slot.getAttribute("data-id")!;
result.push({
...tiles.get(id)!,
...offset(slot, gridRoot),
width: slot.offsetWidth,
height: slot.offsetHeight,
});
if (slot.offsetWidth > 0 && slot.offsetHeight > 0)
result.push({
...tiles.get(id)!,
...offset(slot, gridRoot),
width: slot.offsetWidth,
height: slot.offsetHeight,
});
}
}

Expand Down
21 changes: 6 additions & 15 deletions src/state/CallViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ function findMatrixMember(
room: MatrixRoom,
id: string,
): RoomMember | undefined {
if (!id) return undefined;
if (id === "local")
return room.getMember(room.client.getUserId()!) ?? undefined;

const parts = id.split(":");
// must be at least 3 parts because we know the first part is a userId which must necessarily contain a colon
Expand Down Expand Up @@ -307,23 +308,16 @@ export class CallViewModel extends ViewModel {
]).pipe(
scan(
(prevItems, [remoteParticipants, { participant: localParticipant }]) => {
let allGhosts = true;

const newItems = new Map(
function* (this: CallViewModel): Iterable<[string, MediaItem]> {
for (const p of [localParticipant, ...remoteParticipants]) {
const member = findMatrixMember(this.matrixRoom, p.identity);
allGhosts &&= member === undefined;
// We always start with a local participant with the empty string as
// their ID before we're connected, this is fine and we'll be in
// "all ghosts" mode.
if (p.identity !== "" && member === undefined) {
const userMediaId = p === localParticipant ? "local" : p.identity;
const member = findMatrixMember(this.matrixRoom, userMediaId);
if (member === undefined)
logger.warn(
`Ruh, roh! No matrix member found for SFU participant '${p.identity}': creating g-g-g-ghost!`,
);
}

const userMediaId = p.identity;
yield [
userMediaId,
prevItems.get(userMediaId) ??
Expand All @@ -343,10 +337,7 @@ export class CallViewModel extends ViewModel {
);

for (const [id, t] of prevItems) if (!newItems.has(id)) t.destroy();

// If every item is a ghost, that probably means we're still connecting
// and shouldn't bother showing anything yet
return allGhosts ? new Map() : newItems;
return newItems;
},
new Map<string, MediaItem>(),
),
Expand Down

0 comments on commit a16f235

Please sign in to comment.