fix(display): define the display-server messages once, in src/shared
The display controller and the viewer routes each described the heartbeat their own way and disagreed about one thing: the display sent null for "nothing to report", and the route accepted only a missing field. Every heartbeat from a screen showing a native image was refused with a 400. The roster therefore marked working screens Offline 90 s after they opened, and never recorded offlineReady or cachedAssetCount. src/shared/display-protocol.ts now defines every message between a display and the server: - viewer session request and response; - heartbeat request and response; - channel state; - the realtime display payload. Both halves import it. Its rules: a nullable field accepts null explicitly, an absent field means "not reported", and an unknown field is ignored, so a newer display is never refused by an older server. - The routes parse with the shared parsers, and a refusal names the field with Signage's sanitized code. - The server's channel state extends the wire type, so a field the display relies on cannot drift without a compile error. - The display builds its heartbeat as the shared type, and reads its registration with the shared parser instead of casting it. - Test stubs that described server responses more loosely than the server sends them (no viewerName, no stale, partial media) now match the real responses and are typed as the protocol. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
7483d7cbbe
commit
776540ff78
@@ -43,6 +43,7 @@ const SELECTION = {
|
||||
},
|
||||
revision: 1,
|
||||
slotId: "slot-trivia",
|
||||
stale: false,
|
||||
startedAtMs: 0,
|
||||
withdrawn: false,
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
type DisplayChannelStateView,
|
||||
type DisplayController,
|
||||
} from "../../src/display/controller.js";
|
||||
import type { ViewerSessionResponse } from "../../src/shared/display-protocol.js";
|
||||
import { createFakeHost, jsonResponse } from "./support/fake-host.js";
|
||||
|
||||
/**
|
||||
@@ -114,12 +115,14 @@ function state(overrides: Partial<DisplayChannelStateView> = {}): DisplayChannel
|
||||
};
|
||||
}
|
||||
|
||||
const SESSION = {
|
||||
/** Typed as the shared protocol message, so a stub cannot drift from what the server sends. */
|
||||
const SESSION: ViewerSessionResponse = {
|
||||
channelId: "chan-1",
|
||||
channelKey: "default",
|
||||
groupId: "group-1",
|
||||
heartbeatIntervalMs: 12_000,
|
||||
viewerId: "11111111-1111-4111-8111-111111111111",
|
||||
viewerName: "Foyer",
|
||||
};
|
||||
|
||||
describe("display controller", () => {
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
createDisplayController,
|
||||
type DisplayChannelStateView,
|
||||
} from "../../src/display/controller.js";
|
||||
import type { DisplaySelection, ViewerSessionResponse } from "../../src/shared/display-protocol.js";
|
||||
import { createFakeHost, jsonResponse } from "./support/fake-host.js";
|
||||
|
||||
/**
|
||||
@@ -309,14 +310,26 @@ describe("a display that loses its network", () => {
|
||||
}
|
||||
}
|
||||
|
||||
function nativeSelection(id: string, slotId: string): SceneSelection {
|
||||
/** A native selection exactly as the server sends one in channel state. */
|
||||
function nativeSelection(id: string, slotId: string): DisplaySelection {
|
||||
return {
|
||||
...selection({ id, slotId }),
|
||||
media: {
|
||||
display: { url: `https://cdn.invalid/${id}?sig=a` },
|
||||
thumbnail: { url: `https://cdn.invalid/${id}-t?sig=a` },
|
||||
display: {
|
||||
expiresAtMs: 900_000,
|
||||
height: 1080,
|
||||
url: `https://cdn.invalid/${id}?sig=a`,
|
||||
width: 1920,
|
||||
},
|
||||
thumbnail: {
|
||||
expiresAtMs: 900_000,
|
||||
height: 270,
|
||||
url: `https://cdn.invalid/${id}-t?sig=a`,
|
||||
width: 480,
|
||||
},
|
||||
},
|
||||
} as SceneSelection;
|
||||
stale: false,
|
||||
};
|
||||
}
|
||||
|
||||
function state(currentId: string): DisplayChannelStateView {
|
||||
@@ -373,7 +386,8 @@ describe("a display that loses its network", () => {
|
||||
groupId: "group-1",
|
||||
heartbeatIntervalMs: 12_000,
|
||||
viewerId: "11111111-1111-4111-8111-111111111111",
|
||||
}),
|
||||
viewerName: "Foyer",
|
||||
} satisfies ViewerSessionResponse),
|
||||
},
|
||||
{
|
||||
method: "GET",
|
||||
|
||||
Reference in New Issue
Block a user