feat(observer): add observer mode and disconnect recovery
This commit is contained in:
@@ -74,3 +74,33 @@ test("player assets are local, Russian, accessible, and responsive", () => {
|
||||
assert.match(icons, /id="key"/);
|
||||
assert.match(icons, /id="maze"/);
|
||||
});
|
||||
|
||||
test("observer view fits large screens and bounds zoom", () => {
|
||||
assert.equal(player.observerFitScale(1024, 600, 128, 64), .96);
|
||||
assert.equal(player.clampObserverZoom(.01), .25);
|
||||
assert.equal(player.clampObserverZoom(20), 6);
|
||||
const html = fs.readFileSync(path.join(project, "web/index.html"), "utf8");
|
||||
const css = fs.readFileSync(path.join(project, "web/player.css"), "utf8");
|
||||
const script = fs.readFileSync(path.join(project, "web/player.js"), "utf8");
|
||||
assert.match(html, /Режим наблюдателя · только чтение/);
|
||||
assert.match(html, /Нужен экран побольше/);
|
||||
assert.match(html, /Зрительный зал открывается от 1024 × 768/);
|
||||
assert.match(css, /@media \(max-width: 1023px\), \(max-height: 767px\)/);
|
||||
assert.match(css, /\.observer-stage \{[^}]*overflow: hidden/);
|
||||
assert.match(script, /snapshot\.role === "observer"/);
|
||||
assert.match(script, /state\.session\.role === "observer" \? "observer" : "match"/);
|
||||
assert.match(script, /!player\.connected \? "нет связи"/);
|
||||
assert.match(script, /addEventListener\("wheel"/);
|
||||
assert.match(script, /addEventListener\("pointermove"/);
|
||||
});
|
||||
|
||||
test("observer protocol exposes no mutation control path", () => {
|
||||
const html = fs.readFileSync(path.join(project, "web/index.html"), "utf8");
|
||||
const observerSection = html.match(/<section class="screen observer-screen"[\s\S]*?<\/section>/)[0];
|
||||
assert.doesNotMatch(observerSection, /data-direction|drop-key|start-match/);
|
||||
const observer = {v: 1, type: "view", seq: 30, payload: {role: "observer", phase: "active", result: "none", width: 2, height: 2, players: [{cell: 0, key: null, exited: 0, connected: 1}, {cell: 3, key: 1, exited: 0, connected: 1}], chunk: 0, chunks: 1, cells: [[0, 6], [1, 12], [2, 3], [3, 9]], objects: []}};
|
||||
const snapshot = new player.SnapshotAssembler().accept(observer);
|
||||
assert.equal(snapshot.role, "observer");
|
||||
assert.deepEqual(snapshot.players.map(item => item.cell), [0, 3]);
|
||||
assert.equal("self" in snapshot, false);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user