diff --git a/frontend/src/v2/views/Player/Stream.test.ts b/frontend/src/v2/views/Player/Stream.test.ts index aaa415669..9109555f1 100644 --- a/frontend/src/v2/views/Player/Stream.test.ts +++ b/frontend/src/v2/views/Player/Stream.test.ts @@ -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((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( diff --git a/frontend/src/v2/views/Player/Stream.vue b/frontend/src/v2/views/Player/Stream.vue index 35e652ad7..65193f1dd 100644 --- a/frontend/src/v2/views/Player/Stream.vue +++ b/frontend/src/v2/views/Player/Stream.vue @@ -592,13 +592,24 @@ const SESSION_POLL_MS = 30_000; useSocketEvent("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 { + await handleSessionStatus({ status: "ended", platform: notice.platform ?? "", termination: notice, }); -}); +} let sessionPollInFlight = false; async function pollSessionStatus(): Promise { @@ -858,6 +869,8 @@ async function onPlay(cardImport?: MemoryCardImport): Promise { 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) {