mirror of
https://github.com/screentinker/screentinker.git
synced 2026-08-19 08:33:56 -06:00
* Make a BrightSign say what it is running, and what it is plugged into
A panel on a wall could not answer three questions an operator asks first:
which version am I, which page am I running, and which screen is that. All
three had answers already travelling over the socket; nothing was reading them.
VERSION. device_info.app_version was the literal '1.1.0-web' for every web
player, BrightSign included — the same string as PLAYER_VERSION, which already
travels separately as client_version. So the column carried no information at
all: a panel provisioned this morning and one running a year-old host reported
identically. app_version is now the ON-DEVICE host package, the artifact OTA
replaces and the only one here that can be stale, and PLAYER_VERSION is stamped
at serve time from VERSION rather than being a constant nobody bumped for the
whole 1.x line. No '-web' suffix: client_version is only compared for equality
today, but X.Y.Z-web is a semver PRERELEASE that sorts BELOW X.Y.Z, and this
project has been bitten by exactly that before.
The host version arrives asynchronously and can land after the page registers,
so register sends what it has and the heartbeat corrects the record — which also
catches the version changing under a live page, which is what a self-update is.
THE CARD SHOWED FOR NOBODY. The Info tab's version card sat inside the block
gated on android_version && !startsWith('Web/'). A BrightSign registers as
"Web/<ua>", so the panel that most needed a version never displayed one.
THE PAD THAT COULD NOT BE CLICKED. System View was gated on tier === 2. tier is
an Android device-owner concept, NOT NULL DEFAULT 0, written only by the APK —
so a BrightSign or Tizen panel sat at 0 forever and rendered HOME, BACK, POWER,
the D-pad and OK permanently pointer-events:none, for keys those players
genuinely handle. Greying an Android gate over a working control is the "button
that cannot work" the capability system exists to prevent, inverted. Only
Recents (KEYCODE_APP_SWITCH) and Settings are truly Android-only; those are now
the only things hidden.
THE PACKAGE POINTED AT THE WRONG SERVER. autorun.zip carried the committed
default, so a player self-updating from alpha or a self-hosted box was handed a
config pointing at screentinker.com — which surfaces as a pairing bug, miles
from the packaging code that caused it. It is now stamped with the URL it was
fetched from. The bytes therefore vary per origin, so the cache is keyed by
origin and BOTH routes derive it identically: the manifest checksum and the
served bytes must come from one buffer or every player downloads, fails
verification and retries forever.
EDID. getEdidIdentity() answers seven questions and cannot answer any others —
manufacturer, EDID version, physical size, gamma and the mode lists exist only
in the raw block, which getEdid() returns as 2048 bytes. The player ships those
on the register (identity, not a reading: it changes when someone swaps the
screen) and the SERVER parses them. That split is the point: a new field becomes
a server deploy instead of a bridge update behind a 4h CDN plus an OTA for the
host. Verified against real hardware — an XT245 with a CX101 decodes to RTK /
0x1010 / serial 1 / 2020w26 / 22x13cm, preferred 1920x1200@62, matching the
player's own DWS field for field. The odd-looking 62 is right: 168.5MHz over
2200 x 1245 is 61.5Hz, and rounding it to a nicer 60 would contradict the panel.
Also corrects two comments that had outgrown their reasoning: the BrightSign
capability baseline still explained its exclusions with "a canvas cannot read
the video plane", which native capture made obsolete, and player-parity.md
claimed the bridge is "always current" when a zone-wide Cloudflare Browser Cache
TTL had been rewriting its no-cache to max-age=14400 for months.
Every new guard is mutation-tested — the fix was reverted in the source and each
test confirmed to fail. 1676 -> 1714 tests, all green.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014kfhrUPit5MCqxeTQyqr56
* Run the ScreenTinker server on the player it serves
A BrightSign XT245 now downloads, installs and runs the server itself, with
the display showing what it is doing until it is up.
WHY IT NEEDED A NEW SHAPE
BrightSignOS cannot open a large autorun.zip. The 73MB build failed at boot
with "ZipArchive error at line 91", and the OS renamed it autorun.zip_invalid
- which is how a device that had already unpacked once came back up with no
autorun at all. The identical package cut to 32KB and five files boots fine;
paths (182 chars) and depth (8) are unremarkable, so the limit is in the
boot-time reader, not the archive. BrightSign's own notes acknowledge package
size as a problem and point at webpack; that route needs the dynamic requires
in scripts/ removed first, so instead autorun.zip carries only what starts the
process and the payload arrives over HTTP into a Node that has no such limit.
The payload can also be updated without re-provisioning the device.
WHY roNodeJs AND NOT THE WIDGET
The first version ran the server inside an roHtmlWidget with nodejs_enabled.
That is a Node context inside an Electron renderer, and it is not Node. Four
separate boot failures came out of it, each invisible to a local test because
a local test runs on real Node:
- shebangs are not stripped, so any `#!/usr/bin/env node` file dies with
"Failed to construct 'ContextifyScript': Invalid or unexpected token".
Note it names no token - "#" is not one. An ESM file compiled as CJS says
"Unexpected token 'export'" instead, which is how the two are told apart.
- require() of an ESM-only package is unsupported, which plain Node 24
handles. uuid 14 is ESM-only and 21 files import it.
- setInterval is the DOM's and returns a NUMBER, so setInterval(...).unref()
throws. Two call sites were unguarded; sixteen more were written
defensively and had been silently not unreffing.
- worker_threads cannot create a thread at all.
BrightSign's dev-cookbook is explicit: roNodeJs "for long running processes
like ... running a web server", roHtmlWidget "for browser-based apps". Their
cra-template examples do exactly this - server in roNodeJs, widget pointed at
localhost. It also fixes the lifecycle problem that was the original argument
against a server on this hardware: in a widget the server dies with the page,
taking an open SQLite WAL with it.
The shims for the first three are kept in the packager for now rather than
removed in the same change that moves the container, so that if something
breaks it is the move and not four simultaneous removals.
CHANGES THAT ARE NOT BRIGHTSIGN-SPECIFIC
db/database.js, routes/status.js fs.copyFileSync does not merely copy
bytes: it fchmods the destination to match the source. exFAT has no
permission bits, so the pre-migration snapshot failed with EPERM and the
failure path called process.exit(1) - which inside a widget also killed
the page, leaving a black screen and no diagnostic. The guard was right;
the copy was wrong. lib/fsutil.js copies without touching mode.
db/wal-checkpointer.js the module already degraded correctly when its
worker died or could not be respawned, but the FIRST spawn was not
wrapped, so a host that cannot make threads lost the whole server rather
than falling back to inline autocheckpoint.
db/sqlite-compat.js a better-sqlite3 facade over node:sqlite. With it the
bundle contains no native code at all, which is what lets an x86_64
laptop build a package for an aarch64 player. 1719/1719 tests pass on
Node 24 through this shim.
The packager refuses to build if a source file is untracked (git ls-files
decides what ships, and lib/fsutil.js reached a player without shipping
alongside the code that required it), if any .node binary is present, if a
shebang survives, or if a database, upload, cert or .env is staged - the first
build of this package swept up a real 33MB database and 105MB of uploads.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014kfhrUPit5MCqxeTQyqr56
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Dan Walters <dan.walters@bytetinker.net>
223 lines
10 KiB
JavaScript
223 lines
10 KiB
JavaScript
'use strict';
|
|
|
|
/*
|
|
* The EDID parser, checked against a REAL panel.
|
|
*
|
|
* The fixture below is assembled byte by byte to match what the XT245's own DWS reported for the
|
|
* CX101 attached to it — manufacturer RTK, product 0x1010, serial 1, made 2020 week 26, 22x13 cm,
|
|
* gamma 2.20, and a preferred mode whose modeline is
|
|
*
|
|
* "1920x1200x62p 168.50 1920 2008 2052 2200 1200 1204 1209 1245"
|
|
*
|
|
* That last one matters: the DWS calls it 62p, which looks like a typo for 60 until you divide the
|
|
* pixel clock by the totals — 168.5MHz / (2200 x 1245) = 61.5Hz. A parser that "helpfully" rounds
|
|
* to 60 would disagree with the player's own diagnostics about the panel in front of it, which is
|
|
* the one thing an operator would use this screen to check.
|
|
*/
|
|
|
|
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { parseEdid } = require('../lib/edid');
|
|
|
|
function buildCx101() {
|
|
const b = Buffer.alloc(128);
|
|
Buffer.from([0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00]).copy(b, 0);
|
|
|
|
// 'RTK' — five bits per letter, big-endian, A=1.
|
|
b.writeUInt16BE(((18 & 0x1f) << 10) | ((20 & 0x1f) << 5) | (11 & 0x1f), 8);
|
|
b.writeUInt16LE(0x1010, 10); // product
|
|
b.writeUInt32LE(1, 12); // serial
|
|
b[16] = 26; // week
|
|
b[17] = 2020 - 1990; // year
|
|
b[18] = 1; b[19] = 3; // EDID 1.3
|
|
b[20] = 0x80; // digital
|
|
b[21] = 22; b[22] = 13; // cm
|
|
b[23] = 220 - 100; // gamma 2.20
|
|
|
|
// Established: 640x480@60 (0x20) + 800x600@60 (0x01) in byte 35, 1024x768@60 (0x08) in byte 36.
|
|
b[35] = 0x20 | 0x01;
|
|
b[36] = 0x08;
|
|
|
|
// Standard timings. 1920x1200@60 = 16:10, and 1280x720@60 = 16:9.
|
|
b[38] = 1920 / 8 - 31; b[39] = (0 << 6) | (60 - 60);
|
|
b[40] = 1280 / 8 - 31; b[41] = (3 << 6) | (60 - 60);
|
|
for (let i = 42; i <= 52; i += 2) { b[i] = 0x01; b[i + 1] = 0x01; }
|
|
|
|
// DTD 1 — the preferred mode, from the modeline above.
|
|
const d = b.slice(54, 72);
|
|
d.writeUInt16LE(16850, 0); // 168.50 MHz in 10kHz units
|
|
const hActive = 1920, hBlank = 2200 - 1920, vActive = 1200, vBlank = 1245 - 1200;
|
|
d[2] = hActive & 0xff; d[3] = hBlank & 0xff;
|
|
d[4] = ((hActive >> 8) << 4) | (hBlank >> 8);
|
|
d[5] = vActive & 0xff; d[6] = vBlank & 0xff;
|
|
d[7] = ((vActive >> 8) << 4) | (vBlank >> 8);
|
|
d[12] = 476 & 0xff; d[13] = 268 & 0xff;
|
|
d[14] = ((476 >> 8) << 4) | (268 >> 8);
|
|
d[17] = 0x1e; // digital separate, +h +v
|
|
|
|
// Descriptor 2 — monitor name.
|
|
b[72] = 0; b[73] = 0; b[74] = 0; b[75] = 0xfc; b[76] = 0;
|
|
Buffer.from('CX101\n').copy(b, 77);
|
|
for (let i = 77 + 6; i < 90; i++) b[i] = 0x20;
|
|
|
|
b[126] = 0; // no extension blocks
|
|
b[127] = (256 - (b.slice(0, 127).reduce((a, x) => (a + x) & 0xff, 0) % 256)) & 0xff;
|
|
return b;
|
|
}
|
|
|
|
const CX101 = buildCx101();
|
|
|
|
test('the identity fields match what the player DWS reports for this panel', () => {
|
|
const e = parseEdid(CX101);
|
|
assert.ok(e, 'a well-formed EDID must parse');
|
|
assert.equal(e.manufacturer, 'RTK');
|
|
assert.equal(e.productHex, '0x1010');
|
|
assert.equal(e.serialNumber, 1);
|
|
assert.equal(e.weekOfManufacture, 26);
|
|
assert.equal(e.yearOfManufacture, 2020);
|
|
assert.equal(e.edidVersion, '1.3');
|
|
assert.equal(e.digital, true);
|
|
assert.equal(e.widthCm, 22);
|
|
assert.equal(e.heightCm, 13);
|
|
assert.equal(e.gamma, 2.2);
|
|
assert.equal(e.monitorName, 'CX101');
|
|
assert.equal(e.checksumValid, true);
|
|
});
|
|
|
|
test('the preferred mode is 62p, exactly as the DWS modeline computes', () => {
|
|
// 168.5MHz / (2200 x 1245) = 61.5Hz. Rounding to a "nicer" 60 would contradict the player.
|
|
const e = parseEdid(CX101);
|
|
assert.equal(e.preferredMode, '1920x1200@62');
|
|
const dtd = e.detailedTimings[0];
|
|
assert.equal(dtd.pixelClockKhz, 168500);
|
|
assert.equal(dtd.width, 1920);
|
|
assert.equal(dtd.height, 1200);
|
|
assert.equal(dtd.interlaced, false);
|
|
});
|
|
|
|
test('established and standard timing lists come back', () => {
|
|
const e = parseEdid(CX101);
|
|
for (const m of ['640x480@60', '800x600@60', '1024x768@60']) {
|
|
assert.ok(e.establishedTimings.includes(m), `expected ${m} in ${e.establishedTimings}`);
|
|
}
|
|
const labels = e.standardTimings.map((s) => s.label);
|
|
assert.deepEqual(labels, ['1920x1200@60', '1280x720@60'],
|
|
'unused 0x01 0x01 slots must be skipped, not reported as modes');
|
|
});
|
|
|
|
test('a bad panel degrades to "we do not know", never to a thrown page', () => {
|
|
// This runs on bytes a display supplied. The device page must survive a monitor that lies.
|
|
assert.equal(parseEdid(null), null);
|
|
assert.equal(parseEdid(Buffer.alloc(0)), null);
|
|
assert.equal(parseEdid(Buffer.alloc(128)), null, 'all zeroes has no EDID header');
|
|
assert.equal(parseEdid(Buffer.alloc(64, 0xff)), null, 'too short to be a base block');
|
|
assert.equal(parseEdid('not an edid at all'), null);
|
|
});
|
|
|
|
test('a corrupt checksum is REPORTED, not rejected', () => {
|
|
// A panel with a bad checksum still answers most questions correctly, and an installer chasing a
|
|
// flaky cable wants to see the fields AND be told the block is suspect. Dropping it wholesale
|
|
// would hide the very evidence they need.
|
|
const bad = Buffer.from(CX101);
|
|
bad[127] = (bad[127] + 1) & 0xff;
|
|
const e = parseEdid(bad);
|
|
assert.ok(e, 'a bad checksum must still parse');
|
|
assert.equal(e.checksumValid, false);
|
|
assert.equal(e.monitorName, 'CX101');
|
|
});
|
|
|
|
test('the wire formats the bridge might send all land in the same place', () => {
|
|
// getEdid() has not been observed on hardware yet, so accept the plausible shapes rather than
|
|
// betting on one: a Buffer, a byte array, a Uint8Array, base64, or hex.
|
|
const expected = parseEdid(CX101);
|
|
const shapes = {
|
|
array: Array.from(CX101),
|
|
uint8: new Uint8Array(CX101),
|
|
base64: CX101.toString('base64'),
|
|
hex: CX101.toString('hex'),
|
|
};
|
|
for (const [name, value] of Object.entries(shapes)) {
|
|
const got = parseEdid(value);
|
|
assert.ok(got, `${name} should parse`);
|
|
assert.equal(got.monitorName, expected.monitorName, `${name} lost the monitor name`);
|
|
assert.equal(got.productHex, expected.productHex, `${name} lost the product id`);
|
|
}
|
|
});
|
|
|
|
test('a CEA extension contributes the colorimetry flags the DWS shows', () => {
|
|
// "BT2020 RGB supported / BT2020 YCbCr supported" comes from the CEA colorimetry data block, not
|
|
// the base block — which is why getEdidIdentity()'s flags and the raw bytes must agree.
|
|
const ext = Buffer.alloc(128);
|
|
ext[0] = 0x02; ext[1] = 3; ext[2] = 8; ext[3] = 0x00;
|
|
ext[4] = (7 << 5) | 3; // extended tag, length 3
|
|
ext[5] = 0x05; // colorimetry data block
|
|
ext[6] = 0x80 | 0x40; // BT2020 RGB + YCC
|
|
ext[7] = 0x00;
|
|
const two = Buffer.concat([Buffer.from(CX101), ext]);
|
|
two[126] = 1;
|
|
two[127] = (256 - (two.slice(0, 127).reduce((a, x) => (a + x) & 0xff, 0) % 256)) & 0xff;
|
|
|
|
const e = parseEdid(two);
|
|
assert.equal(e.extensionBlocks, 1);
|
|
assert.equal(e.cea.bt2020Rgb, true);
|
|
assert.equal(e.cea.bt2020Ycc, true);
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------------------------
|
|
// The path from panel to page
|
|
//
|
|
// Four hops, none of which can be executed here: the bridge reads getEdid() on a widget, the page
|
|
// sends it on register, applyHardwareIdentity stores it, the device route parses it on read. Each
|
|
// is pinned against its own source, because a break anywhere is silent — the card simply does not
|
|
// appear, which looks exactly like a panel that never reported an EDID.
|
|
// ---------------------------------------------------------------------------------------------
|
|
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const ROOT = path.join(__dirname, '..', '..');
|
|
const read = (...p) => fs.readFileSync(path.join(ROOT, ...p), 'utf8');
|
|
|
|
test('the bridge collects the RAW block, not just the identity object', () => {
|
|
const bridge = read('brightsign', 'st-bridge.js');
|
|
assert.match(bridge, /typeof vo\.getEdid === 'function'/,
|
|
'getEdidIdentity() cannot answer manufacturer, gamma or the mode lists — the raw block must be read');
|
|
assert.match(bridge, /edid: function \(\) \{ return edidRaw; \}/, 'and exposed to the page');
|
|
assert.match(bridge, /function toBase64/, 'normalised, because the return shape is undocumented');
|
|
});
|
|
|
|
test('EDID rides the REGISTER, not the heartbeat', () => {
|
|
// It changes when someone swaps the screen. ~350 characters of unchanging base64 every 15
|
|
// seconds, forever, across a fleet, to say the same thing each time.
|
|
const player = read('server', 'player', 'index.html');
|
|
assert.match(player, /data\.bs_edid = BS\.edid\(\) \|\| null/);
|
|
const hb = player.slice(player.indexOf('function startHeartbeat'), player.indexOf('function stopHeartbeat'));
|
|
assert.ok(!hb.includes('bs_edid'), 'the heartbeat must not carry it');
|
|
assert.match(player, /maybeReportEdid/, 'but a late-arriving probe must still be reported');
|
|
});
|
|
|
|
test('a device that reports no EDID does not erase the one already stored', () => {
|
|
// The probe is async and the first register usually predates it, so nulls are NORMAL. A plain
|
|
// assignment would blank the column on every reconnect and the card would flicker in and out.
|
|
const sock = read('server', 'ws', 'deviceSocket.js');
|
|
assert.match(sock, /hardware_edid\s*=\s*COALESCE\(\?, hardware_edid\)/);
|
|
});
|
|
|
|
test('the blob is stored raw and parsed on READ', () => {
|
|
// The whole argument for server-side parsing: a new field is a server deploy, not a fleet
|
|
// re-collection. Storing a parsed snapshot instead would freeze today's field list into the DB.
|
|
const route = read('server', 'routes', 'devices.js');
|
|
assert.match(route, /parseEdid\(device\.hardware_edid\)/);
|
|
assert.match(route, /capabilities, edid,/, 'and shipped to the dashboard');
|
|
const db = read('server', 'db', 'database.js');
|
|
assert.match(db, /ADD COLUMN hardware_edid TEXT/, 'the migration must exist');
|
|
});
|
|
|
|
test('the card renders only when there is something to show', () => {
|
|
const view = read('frontend', 'js', 'views', 'device-detail.js');
|
|
assert.match(view, /\$\{device\.edid \? `/, 'no EDID must mean no card, not an empty one');
|
|
for (const k of ['device.info.edid', 'device.info.edid_preferred', 'device.info.edid_made']) {
|
|
assert.ok(view.includes(k), `${k} must be rendered`);
|
|
assert.ok(read('frontend', 'js', 'i18n', 'en.js').includes(`'${k}'`), `${k} must be defined in en.js`);
|
|
}
|
|
});
|