fix(streaming): end a launch whose claim ended before the 202 landed

Until the 202 names the claim, a session-ended notice cannot be matched to it, so notices that arrive in flight are held and the one naming the claim is replayed.
This commit is contained in:
Zach Clendenen committed 2026-09-18 13:29:15 -05:00
1 parent 78922d1a5d
commit 30ac6633f4
2 files changed
+36 -3

No files matched your search

@@ -489,6 +489,26 @@ describe("Stream session-ended notices", () => {
expect(vmOf(wrapper).endedDialogOpen).toBe(false);
});
it("ends the launch when its own claim ended before the 202 landed", async () => {
let claimed = (_: typeof CLAIM) => {};
mocks.claimSession.mockReturnValue(
new Promise<typeof CLAIM>((resolve) => {
claimed = resolve;
}),
);
const wrapper = await launch({ picker: false });
const playing = vmOf(wrapper).onPlay();
await flushPromises();
endSession({ platform: "gba", container: CLAIM.container });
claimed(CLAIM);
await playing;
await flushPromises();
expect(vmOf(wrapper).playerState).toBe("exited");
expect(vmOf(wrapper).endedDialogOpen).toBe(true);
});
it("keeps launching when the container's last claim ends before the 202", async () => {
let claimed = (_: typeof CLAIM) => {};
mocks.claimSession.mockReturnValue(
+16 -3
View File
@@ -592,13 +592,24 @@ const SESSION_POLL_MS = 30_000;
useSocketEvent<SessionTermination>("streaming:session-ended", (notice) => {
// The room carries every claim the account holds, and an admin's desktop is
// never the game on screen.
if (notice.desktop || !isOurClaim(notice)) return;
void handleSessionStatus({
if (notice.desktop) return;
if (!claimedAt.value) {
if (playerState.value === "loading") earlyNotices.push(notice);
return;
}
if (isOurClaim(notice)) void endFromNotice(notice);
});
// Notices that beat the 202, held until it says which claim is ours.
const earlyNotices: SessionTermination[] = [];
async function endFromNotice(notice: SessionTermination): Promise<void> {
await handleSessionStatus({
status: "ended",
platform: notice.platform ?? "",
termination: notice,
});
});
}
let sessionPollInFlight = false;
async function pollSessionStatus(): Promise<void> {
@@ -858,6 +869,8 @@ async function onPlay(cardImport?: MemoryCardImport): Promise<void> {
claimedContainer.value = launching.container;
claimedAt.value = launching.claimed_at;
holdsClaim.value = true;
const endedEarly = earlyNotices.splice(0).find(isOurClaim);
if (endedEarly) await endFromNotice(endedEarly);
await flourish;
}
} catch (err: unknown) {