Skip to content

Commit 7a852a2

Browse files
gershamclaude
andcommitted
Teach the SDK startup order and where preview pixels come from
The applications reference now opens with the canonical startup: waitUntilActive(), then ready(), with no SDK call (log included) while inert, input queued until activation, and emitConfirmed where a receipt matters. SKILL.md points at it. It replaces the old wording that implied ready() could run before activation. playlists.md says preview draws local <media_id> files or fetches project media when logged in, and how placeholders are reported. Bundles CLI b99b48a, which fetches project media for file previews. Counts: repository 105 files, 2,975,031 -> 2,979,853 bytes; plugins/screenrig 49 files, 1,906,477 -> 1,909,548 bytes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent eede9ad commit 7a852a2

8 files changed

Lines changed: 196 additions & 118 deletions

File tree

‎components.lock.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"state": "resolved",
44
"cli": {
55
"repository": "screenrig/cli",
6-
"commit": "ec1bfeb03fe41a957372ab3261ef1a712de2d5a2",
6+
"commit": "b99b48a266a4569da30d3b2ef77a017f57b2959b",
77
"artifact": {
88
"file": "screenrig-cli.tgz",
9-
"sha256": "c4c2d917c4e242c46924ec7588320909122c945e9c5a23698347acebce9317d9"
9+
"sha256": "222c04cfe816cef4d89cdbfdcce4b293bdbcf25e80bc41440dac6b04aecb6d59"
1010
}
1111
}
1212
}

‎plugins/screenrig/cli/dist/bin.js‎

Lines changed: 102 additions & 102 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎plugins/screenrig/skills/screenrig/SKILL.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,10 @@ rotation, billing and a scheduled-agent recipe are in
411411

412412
For screen controls, reload, screenshots, comments, events and feedback, use
413413
[operations](references/operations.md). For app uploads, page completion and K/V,
414-
use [applications](references/applications.md). The [command inventory](references/commands.md)
414+
use [applications](references/applications.md). App code must
415+
`await screenrig.waitUntilActive()` before `await screenrig.ready()` and make
416+
no SDK call, `log()` included, while `readyState` is not `active`; see
417+
[SDK startup](references/applications.md#start-the-sdk-in-this-order). The [command inventory](references/commands.md)
415418
provides a compact reference for supported operations.
416419

417420
## Resolve issues and ask for support

‎plugins/screenrig/skills/screenrig/references/applications.md‎

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,37 @@ the archive first. The packer injects the screenRIG browser SDK at
1616
reaches `window.screenrig` at runtime with no build step and no dependency to
1717
install.
1818

19+
#### Start the SDK in this order
20+
21+
`window.screenrig` starts `inert` and turns `active` only when the Player's
22+
handshake and context arrive; a page that is not on screen yet stays inert.
23+
While inert, `ready()`, `log()`, `emit()`, `emitConfirmed()`, `nextPage()` and
24+
`kv` throw or reject with code `inert`. Every app starts like this:
25+
26+
```javascript
27+
const sr = window.screenrig;
28+
async function start() {
29+
render(); // draw the UI; it must also work outside screenRIG
30+
if (!sr) return;
31+
for (;;) {
32+
try { await sr.waitUntilActive(60000); break; }
33+
catch (err) { if (err.code !== "activation_timeout") return; }
34+
}
35+
await sr.ready();
36+
// Only from here: emit, emitConfirmed, log, kv, nextPage.
37+
}
38+
start();
39+
```
40+
41+
- Call `ready()` only after `waitUntilActive()` resolves, never before.
42+
- Check `sr.readyState === "active"` before every SDK call made from an event
43+
handler, timer or `catch`. Never call `log()` in a handler that can run while
44+
inert: it throws too, and that throw stops the rest of startup, so no event
45+
is ever sent.
46+
- Queue input that arrives before activation and send it after `ready()`. Use
47+
`emitConfirmed(code)` when a receipt matters and handle its rejection; plain
48+
`emit(code)` is a send attempt.
49+
1950
Released apps run under a strict Content-Security-Policy (`script-src 'self';
2051
style-src 'self'`), so inline code in the served HTML never runs. The packer
2152
moves inline `<style>` blocks and inline `<script>` blocks into generated files
@@ -110,12 +141,11 @@ For an interactive kiosk, use application mode with a `max_ms` long enough
110141
for the intended visit. A duration page advances at its deadline even while a
111142
visitor is using the app; pointer activity does not extend that deadline.
112143
Call `nextPage()` after completion or a deliberate idle reset, and explain the
113-
bounded fallback in the experience. `await window.screenrig.ready()` completes
114-
the bridge handshake; it does not prove the candidate page is active. Use
115-
`await window.screenrig.waitUntilActive()` before starting a visitor idle clock
116-
or sending active-page events. Use `await window.screenrig.emitConfirmed(code)`
117-
when the UI promises that an event was accepted, and handle its rejection;
118-
plain `emit(code)` is a send attempt. The receipt resolves only after the
144+
bounded fallback in the experience. Start the visitor idle clock and send
145+
events only after the [startup sequence](#start-the-sdk-in-this-order)
146+
(`waitUntilActive()`, then `ready()`) finishes. Use
147+
`await window.screenrig.emitConfirmed(code)` when the UI promises that an event
148+
was accepted, and handle its rejection. The receipt resolves only after the
119149
backend accepted the event; do not retry automatically after a timeout, since
120150
the event may already be recorded. Choose a shorter duration only for a
121151
preview that is supposed to rotate regardless of input.

‎plugins/screenrig/skills/screenrig/references/playlists.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ screenrig playlist preview lobby.json --output preview --contact-sheet
1010
screenrig screen publish scr_LOBBY lobby.json
1111
```
1212

13+
Preview draws each image and video from a local `<media_id>.png` (or `.jpg`,
14+
`.webp`, `.gif`, `.mp4`, `.webm`) beside the playlist, in the working directory
15+
or in `--output`, and otherwise fetches it from the project when the CLI is
16+
logged in. A grey box labelled with a media ID is a placeholder, not the page:
17+
`data.placeholders` and the `preview_media_placeholder` warning name each one.
18+
1319
Inspect the document and preview before publishing. `playlist init` accepts local
1420
image/video/audio files, ready `med_` IDs, pinned `rel_` application releases, and HTTPS
1521
iframe URLs in playback order, including mixed inputs:

‎skills/screenrig/SKILL.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,10 @@ rotation, billing and a scheduled-agent recipe are in
411411

412412
For screen controls, reload, screenshots, comments, events and feedback, use
413413
[operations](references/operations.md). For app uploads, page completion and K/V,
414-
use [applications](references/applications.md). The [command inventory](references/commands.md)
414+
use [applications](references/applications.md). App code must
415+
`await screenrig.waitUntilActive()` before `await screenrig.ready()` and make
416+
no SDK call, `log()` included, while `readyState` is not `active`; see
417+
[SDK startup](references/applications.md#start-the-sdk-in-this-order). The [command inventory](references/commands.md)
415418
provides a compact reference for supported operations.
416419

417420
## Resolve issues and ask for support

‎skills/screenrig/references/applications.md‎

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,37 @@ the archive first. The packer injects the screenRIG browser SDK at
1616
reaches `window.screenrig` at runtime with no build step and no dependency to
1717
install.
1818

19+
#### Start the SDK in this order
20+
21+
`window.screenrig` starts `inert` and turns `active` only when the Player's
22+
handshake and context arrive; a page that is not on screen yet stays inert.
23+
While inert, `ready()`, `log()`, `emit()`, `emitConfirmed()`, `nextPage()` and
24+
`kv` throw or reject with code `inert`. Every app starts like this:
25+
26+
```javascript
27+
const sr = window.screenrig;
28+
async function start() {
29+
render(); // draw the UI; it must also work outside screenRIG
30+
if (!sr) return;
31+
for (;;) {
32+
try { await sr.waitUntilActive(60000); break; }
33+
catch (err) { if (err.code !== "activation_timeout") return; }
34+
}
35+
await sr.ready();
36+
// Only from here: emit, emitConfirmed, log, kv, nextPage.
37+
}
38+
start();
39+
```
40+
41+
- Call `ready()` only after `waitUntilActive()` resolves, never before.
42+
- Check `sr.readyState === "active"` before every SDK call made from an event
43+
handler, timer or `catch`. Never call `log()` in a handler that can run while
44+
inert: it throws too, and that throw stops the rest of startup, so no event
45+
is ever sent.
46+
- Queue input that arrives before activation and send it after `ready()`. Use
47+
`emitConfirmed(code)` when a receipt matters and handle its rejection; plain
48+
`emit(code)` is a send attempt.
49+
1950
Released apps run under a strict Content-Security-Policy (`script-src 'self';
2051
style-src 'self'`), so inline code in the served HTML never runs. The packer
2152
moves inline `<style>` blocks and inline `<script>` blocks into generated files
@@ -110,12 +141,11 @@ For an interactive kiosk, use application mode with a `max_ms` long enough
110141
for the intended visit. A duration page advances at its deadline even while a
111142
visitor is using the app; pointer activity does not extend that deadline.
112143
Call `nextPage()` after completion or a deliberate idle reset, and explain the
113-
bounded fallback in the experience. `await window.screenrig.ready()` completes
114-
the bridge handshake; it does not prove the candidate page is active. Use
115-
`await window.screenrig.waitUntilActive()` before starting a visitor idle clock
116-
or sending active-page events. Use `await window.screenrig.emitConfirmed(code)`
117-
when the UI promises that an event was accepted, and handle its rejection;
118-
plain `emit(code)` is a send attempt. The receipt resolves only after the
144+
bounded fallback in the experience. Start the visitor idle clock and send
145+
events only after the [startup sequence](#start-the-sdk-in-this-order)
146+
(`waitUntilActive()`, then `ready()`) finishes. Use
147+
`await window.screenrig.emitConfirmed(code)` when the UI promises that an event
148+
was accepted, and handle its rejection. The receipt resolves only after the
119149
backend accepted the event; do not retry automatically after a timeout, since
120150
the event may already be recorded. Choose a shorter duration only for a
121151
preview that is supposed to rotate regardless of input.

‎skills/screenrig/references/playlists.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ screenrig playlist preview lobby.json --output preview --contact-sheet
1010
screenrig screen publish scr_LOBBY lobby.json
1111
```
1212

13+
Preview draws each image and video from a local `<media_id>.png` (or `.jpg`,
14+
`.webp`, `.gif`, `.mp4`, `.webm`) beside the playlist, in the working directory
15+
or in `--output`, and otherwise fetches it from the project when the CLI is
16+
logged in. A grey box labelled with a media ID is a placeholder, not the page:
17+
`data.placeholders` and the `preview_media_placeholder` warning name each one.
18+
1319
Inspect the document and preview before publishing. `playlist init` accepts local
1420
image/video/audio files, ready `med_` IDs, pinned `rel_` application releases, and HTTPS
1521
iframe URLs in playback order, including mixed inputs:

0 commit comments

Comments
 (0)