fix(streaming): enter only the launch of the claim this tab holds

A tab that missed its launch-failed keeps its container, so a second tab's re-claim of that container would otherwise hand it the other tab's room.
This commit is contained in:
Zach Clendenen
2026-09-18 12:58:08 -05:00
parent be68050f3f
commit 65ea8da612
3 changed files with 34 additions and 9 deletions

View File

@@ -35,6 +35,7 @@ export type LaunchingSession = LaunchingSessionSchema;
export interface LaunchReady {
platform: string;
container: string;
claimed_at: string;
host: string;
/** null when no resume was asked for; false means the state could not be
* pushed and the session started fresh. */
@@ -45,6 +46,7 @@ export interface LaunchReady {
export interface LaunchFailed {
platform: string;
container: string;
claimed_at: string;
detail: string;
}
@@ -52,6 +54,7 @@ export interface LaunchFailed {
export interface LaunchPhase {
platform: string;
container: string;
claimed_at: string;
phase: string | null;
}
export type AdminStreamingSession = AdminSessionSchema;

View File

@@ -397,14 +397,17 @@ function endSession(notice: Record<string, unknown>): void {
handler({ ended_by: "admin", reason: null, ...notice });
}
async function launchReady(): Promise<void> {
async function launchReady(
payload: Record<string, unknown> = {},
): Promise<void> {
const handler = mocks.socketHandlers["streaming:launch-ready"];
expect(handler).toBeTypeOf("function");
await handler({
platform: "gba",
container: CLAIM.container,
...CLAIM,
host: "http://webstation-dev:8080",
resume: null,
...payload,
});
}
@@ -634,6 +637,19 @@ describe("Stream launch recovery", () => {
wrapper.unmount();
});
it("keeps waiting when the launch-ready is for a claim that replaced its own", async () => {
// Tab A missed its launch-failed, and tab B re-claimed the same container.
const wrapper = await launch({ picker: false });
await vmOf(wrapper).onPlay();
await launchReady({ claimed_at: "2026-09-17T10:05:00" });
await flushPromises();
expect(vmOf(wrapper).playerState).toBe("loading");
expect(vmOf(wrapper).containerHost).toBe("");
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.

View File

@@ -643,18 +643,24 @@ const stopSessionPoll = sessionPoll.pause;
// and pushes what happened. A launch can take minutes on a title the broker
// has to unpack, and these are the only progress the player sees.
//
// The room is per-user, so a second tab streaming something else receives
// these too. The container is what identifies a launch: a pool can serve one
// platform from more than one, and the claim's 202 said which we got.
// The room is per-user, so a second tab receives these too. The container and
// the stamp the claim's 202 answered with identify a launch, since a re-claim
// of the same container shares its key.
// Which container the claim won, so a launch push can be told from another
// tab's. Null until the 202 lands, which is before any push can arrive.
const claimedContainer = ref<string | null>(null);
// The stamp the 202 answered with, which every release and heartbeat sends
// back so a claim that replaced this one is never the one they reach.
// The stamp the 202 answered with. Releases, heartbeats and launch pushes all
// carry it, so a claim that replaced this one is never taken for it.
const claimedAt = ref<string | null>(null);
function isOurLaunch(payload: { container?: string }): boolean {
return payload.container === claimedContainer.value;
function isOurLaunch(payload: {
container: string;
claimed_at: string;
}): boolean {
return (
payload.container === claimedContainer.value &&
payload.claimed_at === claimedAt.value
);
}
useSocketEvent<LaunchPhase>("streaming:launch-phase", (payload) => {