fix(streaming): let the desktop session own the controller

The desktop view never set the global playing flag, so useGamepad kept
translating pad presses into RomM navigation behind the stream: B popped
history (prompting to end the session), the D-pad moved focus and Start
opened the user menu while an admin configured the emulator. Hold the flag
while the desktop is opening or open, as the game player does.
This commit is contained in:
Zach Clendenen
2026-09-30 16:06:12 -05:00
parent ce980b677f
commit 36cd73762d
2 changed files with 57 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ const mocks = vi.hoisted(() => ({
heartbeatTick: null as (() => Promise<void>) | null,
routeLeave: null as (() => Promise<boolean> | boolean) | null,
socketHandlers: {} as Record<string, (payload: unknown) => unknown>,
setPlaying: vi.fn(),
}));
vi.mock("vue-i18n", () => ({
@@ -49,6 +50,10 @@ vi.mock("@/services/api/streaming", () => ({
},
}));
vi.mock("@/stores/playing", () => ({
default: () => ({ setPlaying: mocks.setPlaying }),
}));
vi.mock("@/stores/streaming", () => ({
useStreamingStore: () => ({ heartbeatSession: mocks.heartbeatSession }),
}));
@@ -345,3 +350,37 @@ describe("Desktop container naming", () => {
);
});
});
describe("Desktop controller ownership", () => {
// The emulator inside the container reads the pad, so RomM's gamepad
// navigation must stay muted or B pops history out of the session.
it("mutes pad navigation while the desktop is claimed", async () => {
await openDesktop();
expect(mocks.setPlaying).toHaveBeenLastCalledWith(true);
});
it("hands the pad back once a notice ends the claim", async () => {
await openDesktop();
endSession({ platform: "ps2", container: KEY });
await flushPromises();
expect(mocks.setPlaying).toHaveBeenLastCalledWith(false);
});
it("hands the pad back when the claim is refused", async () => {
await refuseDesktop({ rom_name: null, claimed_at: null, draining: true });
expect(mocks.setPlaying).toHaveBeenLastCalledWith(false);
});
it("hands the pad back when the view unmounts", async () => {
const wrapper = await openDesktop();
wrapper.unmount();
mounted = null;
expect(mocks.setPlaying).toHaveBeenLastCalledWith(false);
});
});

View File

@@ -10,13 +10,14 @@
import { RAlert, RBtn, RSpinner } from "@v2/lib";
import { useEventListener, useIntervalFn } from "@vueuse/core";
import { isAxiosError } from "axios";
import { computed, onMounted, ref } from "vue";
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
import { onBeforeRouteLeave, useRoute, useRouter } from "vue-router";
import { ROUTES } from "@/plugins/router";
import streamingApi, {
type ContainerBusyDetail,
} from "@/services/api/streaming";
import storePlaying from "@/stores/playing";
import { type SessionTermination, useStreamingStore } from "@/stores/streaming";
import SessionEndedReason from "@/v2/components/Player/SessionEndedReason.vue";
import StreamStage from "@/v2/components/Player/StreamStage.vue";
@@ -29,6 +30,7 @@ const route = useRoute();
const router = useRouter();
const confirm = useConfirm();
const streamingStore = useStreamingStore();
const playingStore = storePlaying();
const containerName = computed(() => String(route.query.container ?? ""));
// The claim's key, which the session routes and notices name; the URL may
@@ -55,6 +57,17 @@ const claimedAt = ref("");
usePageTitle(() => t("play.desktop-title"));
// While the desktop is open (or opening) the emulator inside it owns the
// controller, as it does in a game session: the global playing flag mutes
// useGamepad's UI translation, which would otherwise turn B into
// history-back and D-pad presses into focus moves behind the stream.
const sessionActive = computed(
() => state.value === "loading" || state.value === "running",
);
watch(sessionActive, (active) => playingStore.setPlaying(active), {
immediate: true,
});
async function openDesktop(): Promise<void> {
if (!containerName.value) {
state.value = "error";
@@ -218,6 +231,10 @@ useEventListener(window, "pagehide", onPageHide);
onMounted(() => {
void openDesktop();
});
onBeforeUnmount(() => {
playingStore.setPlaying(false);
});
</script>
<template>