feat(spotlight): flip between cameras as well as screenshares during a share (#67)
CI / Build embedded bundle (push) Successful in 3m19s
CI / Publish to Gitea npm registry (push) Successful in 1m23s

During a screenshare the spotlight carousel holds the shares first, then the host-pinned camera, then every other remote camera that is on (join order). The share stays the default view; the view falls back to the first share when the visible camera turns off or leaves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit was merged in pull request #68.
This commit is contained in:
2026-11-09 01:10:33 -05:00
co-authored by Claude Opus 5.5
parent 576c80a989
commit f793523e03
7 changed files with 367 additions and 15 deletions
+87
View File
@@ -214,3 +214,90 @@ test("SpotlightTile displays ringing media", async () => {
act(() => pickupState$.next("timeout"));
screen.getByText("Call ended");
});
test("[lotus #67] falls back to the share when the visible camera goes away", async () => {
// A controllable IntersectionObserver so the tile's visibleId follows
// navigation the way it does in a browser.
let report: ((entries: IntersectionObserverEntry[]) => void) | undefined;
const RealIO = global.IntersectionObserver;
global.IntersectionObserver = class {
public constructor(
cb: (entries: IntersectionObserverEntry[]) => void,
options?: IntersectionObserverInit,
) {
// Only the carousel's own observer (rooted on the tile); LiveKit's
// video elements create observers of their own.
if (options?.root) report = cb;
}
public observe(): void {}
public unobserve(): void {}
public disconnect(): void {}
} as unknown as typeof IntersectionObserver;
try {
const share = mockRemoteScreenShare(
mockRtcMembership("@alice:example.org", "AAAA"),
{},
mockRemoteParticipant({}),
);
const camera = mockRemoteMedia(
mockRtcMembership("@carol:example.org", "CCCC"),
{ rawDisplayName: "Carol", getMxcAvatarUrl: () => "mxc://carol" },
mockRemoteParticipant({}),
);
// The mocks all use the id "remote"; the carousel keys on ids.
Object.assign(camera, { id: "remote-camera" });
const media$ = new BehaviorSubject([share, camera]);
const user = userEvent.setup();
const { container } = render(
<TooltipProvider>
<SpotlightTile
vm={
new SpotlightTileViewModel(
media$,
constant(false),
constant("solid"),
)
}
targetWidth={300}
targetHeight={200}
expanded={false}
onToggleExpanded={vi.fn()}
showIndicators
showNameTags
showRingingStatus
focusable
/>
</TooltipProvider>,
);
const dots = (): HTMLElement[] =>
screen.getAllByTestId("screenshare-indicator");
expect(dots().map((d) => d.dataset.kind)).toEqual(["screen share", "user"]);
expect(dots()[0].dataset.visible).toBe("true");
// Flip to Carol's camera; the browser would report it as intersecting.
await user.click(screen.getByRole("button", { name: "Next" }));
const carolItem = container.querySelector(`[data-id="${camera.id}"]`)!;
act(() =>
report!([
{
isIntersecting: true,
target: carolItem,
} as unknown as IntersectionObserverEntry,
]),
);
expect(dots()[1].dataset.visible).toBe("true");
expect(isInaccessible(screen.getByText("Carol"))).toBe(false);
// Carol turns her camera off: she drops out and the share is shown again.
act(() => media$.next([share]));
expect(dots()).toHaveLength(1);
expect(dots()[0].dataset.visible).toBe("true");
expect(
isInaccessible(container.querySelector(`[data-id="${share.id}"]`)!),
).toBe(false);
} finally {
global.IntersectionObserver = RealIO;
}
});