fix(streaming): enter a running game off the poll only on the claimed container

The status poll names no container, so it can answer with another tab's session on the same platform, and a loading tab that missed launch-ready would adopt that room as its own and later save and end it on unload.
This commit is contained in:
Zach Clendenen
2026-09-18 11:40:14 -05:00
parent 2cc00f2c4b
commit b7daab85a4
2 changed files with 22 additions and 2 deletions

View File

@@ -616,6 +616,25 @@ describe("Stream launch recovery", () => {
wrapper.unmount();
});
it("keeps waiting when the poll finds a game on another container", async () => {
// The unnamed poll reports any session the player holds on the platform,
// which can be another tab's.
const wrapper = await launch({ picker: false });
await vmOf(wrapper).onPlay();
mocks.fetchSessionStatus.mockResolvedValue({
status: "active",
platform: "gba",
host: "http://webstation-dev-2:8080/room/y",
container: "WEBSTATION-DEV-2",
});
await pollStatus();
expect(vmOf(wrapper).playerState).toBe("loading");
expect(vmOf(wrapper).containerHost).toBe("");
wrapper.unmount();
});
it("keeps waiting while the launch has no room yet", async () => {
const wrapper = await launch({ picker: false });
await vmOf(wrapper).onPlay();

View File

@@ -566,8 +566,9 @@ async function handleSessionStatus(
// the room the launch recorded, which is the way back in.
async function enterRunningSession(status: SessionStatus): Promise<void> {
if (playerState.value !== "loading" || !status.host) return;
// The 202 named it, except for a tab that came back without one.
claimedContainer.value ??= status.container ?? null;
// The poll names no container, so it can answer with another tab's session.
if (!claimedContainer.value || status.container !== claimedContainer.value)
return;
launchPhase.value = null;
containerHost.value = status.host;
playerState.value = "playing";