@vestra-player/sdk 1.6.22 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/bin/vestra-plugin.mjs +34 -12
- package/dist/api-requests.d.ts +22 -0
- package/dist/api-requests.js +38 -0
- package/dist/capability-check.d.ts +48 -0
- package/dist/capability-check.js +219 -51
- package/dist/capability-rules.d.ts +21 -0
- package/dist/capability-rules.js +32 -1
- package/dist/commands.d.ts +8 -0
- package/dist/commands.js +11 -11
- package/dist/docs-tree.json.gz +0 -0
- package/dist/plugin/commands.js +43 -13
- package/dist/plugin/connection.d.ts +37 -0
- package/dist/plugin/connection.js +34 -0
- package/dist/plugin/index.js +12 -2
- package/dist/plugin/media.js +3 -1
- package/dist/plugin/packages.js +3 -1
- package/dist/plugin/passes.d.ts +38 -1
- package/dist/plugin/passes.js +89 -5
- package/dist/plugin/player/events.d.ts +9 -0
- package/dist/plugin/player/events.js +43 -0
- package/dist/plugin/player/rules.d.ts +7 -0
- package/dist/plugin/player/rules.js +11 -0
- package/dist/plugin/player.d.ts +37 -4
- package/dist/plugin/player.js +85 -12
- package/dist/plugin/resolvers.js +2 -3
- package/dist/plugin/runtime.d.ts +2 -3
- package/dist/plugin/runtime.js +8 -2
- package/dist/plugin/scope.d.ts +9 -0
- package/dist/plugin/scope.js +24 -0
- package/dist/plugin/services.js +4 -5
- package/dist/plugin/state.d.ts +3 -0
- package/dist/plugin/state.js +81 -0
- package/dist/plugin/stream.d.ts +27 -3
- package/dist/plugin/testing/core-actions.js +1 -1
- package/dist/plugin/testing/services.js +1 -1
- package/dist/plugin/types/base.d.ts +78 -2
- package/dist/plugin/types/commands.d.ts +17 -1
- package/dist/plugin/types/playback.d.ts +156 -1
- package/dist/plugin/types/plugin-wire.d.ts +589 -0
- package/dist/plugin/types/plugin-wire.js +1 -0
- package/dist/plugin/types/ui-content.d.ts +23 -4
- package/dist/plugin/types/ui-shell.d.ts +1 -0
- package/dist/plugin/types.d.ts +4 -2
- package/dist/plugin/view/base.d.ts +10 -3
- package/dist/plugin/view/base.js +30 -6
- package/dist/plugin/view/binder.js +8 -1
- package/dist/plugin/view/writer.d.ts +49 -4
- package/dist/plugin/view/writer.js +383 -17
- package/dist/plugin/wire-facade.d.ts +4 -0
- package/dist/plugin/wire-facade.js +190 -0
- package/dist/ts-plugin.d.ts +3 -0
- package/dist/ts-plugin.js +18 -6
- package/dist/wire.d.ts +233 -20
- package/llms.txt +3 -3
- package/package.json +1 -1
- package/slint/vestra/focus.slint +33 -0
package/dist/plugin/player.js
CHANGED
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
import { HostError } from "../wire.js";
|
|
6
6
|
import { Latest } from "./latest.js";
|
|
7
7
|
import { abortError, failure, quiet, sleep, uncertain } from "./errors.js";
|
|
8
|
-
import { openStream } from "./stream.js";
|
|
8
|
+
import { openStream, resolvedStream } from "./stream.js";
|
|
9
|
+
import { playerOn } from "./player/events.js";
|
|
10
|
+
import { validStep } from "./player/rules.js";
|
|
9
11
|
const raws = new WeakMap();
|
|
10
12
|
const empty = {
|
|
11
13
|
kind: "media",
|
|
@@ -144,19 +146,25 @@ function decoding(hwdec) {
|
|
|
144
146
|
return hwdec === "no" ? "software" : "hardware";
|
|
145
147
|
}
|
|
146
148
|
export const rawOf = (state) => raws.get(state);
|
|
147
|
-
/** A step-seek length the player accepts: 0.1–3600 seconds in tenths. */
|
|
148
|
-
export const validStep = (seconds) => typeof seconds === "number" &&
|
|
149
|
-
Number.isFinite(seconds) &&
|
|
150
|
-
seconds >= 0.1 &&
|
|
151
|
-
seconds <= 3600 &&
|
|
152
|
-
Math.abs(Math.round(seconds * 10) - seconds * 10) <= 1e-9;
|
|
153
149
|
export const sameStamp = (a, b) => a.generation === b.generation && a.intentVersion === b.intentVersion;
|
|
154
150
|
function sourceFailure(error) {
|
|
155
151
|
return typeof error === "string"
|
|
156
152
|
? failure(error)
|
|
157
153
|
: failure("backend", error.backend);
|
|
158
154
|
}
|
|
159
|
-
/**
|
|
155
|
+
/**
|
|
156
|
+
* One per plugin: the state store and the operation book client.
|
|
157
|
+
*
|
|
158
|
+
* The state copy (a mirror of `source.state`) follows the player's events
|
|
159
|
+
* from the plugin's start when the manifest declares `events`
|
|
160
|
+
* (`createPlugin` subscribes before the start-up read, as before 1.7.0, so
|
|
161
|
+
* a read in any later handler is current). Without `events` no event can
|
|
162
|
+
* arrive; `start` is then called by the first use of the state (a read of
|
|
163
|
+
* `plugin.player.state`, `onChange`, `isCurrent`, a media handle, a
|
|
164
|
+
* scrub, a stream, a filter, a shader or view request, a capture) and
|
|
165
|
+
* subscribes nothing. A start on demand with `events` and `playback.read`
|
|
166
|
+
* would read the state again; `createPlugin` makes it unreachable today.
|
|
167
|
+
*/
|
|
160
168
|
export class PlayerService {
|
|
161
169
|
runtime;
|
|
162
170
|
raw = empty;
|
|
@@ -168,13 +176,17 @@ export class PlayerService {
|
|
|
168
176
|
change = new Map();
|
|
169
177
|
#watchers = new Set();
|
|
170
178
|
#operation = 0;
|
|
179
|
+
/** The mirror subscribed (`start`). */
|
|
180
|
+
#started = false;
|
|
181
|
+
/** The read that followed the subscription (resolved: none was needed). */
|
|
182
|
+
#fresh = Promise.resolve();
|
|
171
183
|
output;
|
|
172
184
|
constructor(runtime) {
|
|
173
185
|
this.runtime = runtime;
|
|
174
186
|
this.state = view(empty, runtime);
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
runtime.
|
|
187
|
+
// An action outside this file that changed the source (`plugin.host.run`)
|
|
188
|
+
// asks for the state again through the connection.
|
|
189
|
+
runtime.rereads.set("source.state", () => this.refresh());
|
|
178
190
|
this.output = new Latest(async ({ volume, muted }) => {
|
|
179
191
|
if (volume !== undefined)
|
|
180
192
|
await runtime.host.playback.set("volume", volume);
|
|
@@ -187,6 +199,35 @@ export class PlayerService {
|
|
|
187
199
|
if (this.runtime.can("playback.read"))
|
|
188
200
|
await this.refresh();
|
|
189
201
|
}
|
|
202
|
+
/** Whether the mirror follows the player's events yet. */
|
|
203
|
+
get started() {
|
|
204
|
+
return this.#started;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Follow `source.state` from now on: the SDK's copy of the state (a
|
|
208
|
+
* mirror; a plugin listens through `watch` and the bindings that read
|
|
209
|
+
* `state`). Then read the state once more (with `playback.read` and
|
|
210
|
+
* `events`): a change between the start-up read and the subscription
|
|
211
|
+
* sent no event to this plugin. Resolves when that read is in.
|
|
212
|
+
* `reread: false`: subscribed before the start-up read
|
|
213
|
+
* (`createPlugin`), which then is that read.
|
|
214
|
+
*/
|
|
215
|
+
start(reread = true) {
|
|
216
|
+
if (this.#started)
|
|
217
|
+
return this.#fresh;
|
|
218
|
+
this.#started = true;
|
|
219
|
+
this.runtime.on("source.state", (data) => this.accept(data), "events", true);
|
|
220
|
+
if (reread &&
|
|
221
|
+
this.runtime.can("playback.read") &&
|
|
222
|
+
this.runtime.can("events"))
|
|
223
|
+
this.#fresh = this.refresh().then(() => { }, () => { });
|
|
224
|
+
return this.#fresh;
|
|
225
|
+
}
|
|
226
|
+
/** The state as the player has it now, for a call that needs a source. */
|
|
227
|
+
async current() {
|
|
228
|
+
await this.start();
|
|
229
|
+
return this.state;
|
|
230
|
+
}
|
|
190
231
|
/** Drop anything older than what was already delivered. */
|
|
191
232
|
accept(raw) {
|
|
192
233
|
if (raw.eventSequence < this.raw.eventSequence)
|
|
@@ -205,6 +246,7 @@ export class PlayerService {
|
|
|
205
246
|
this.runtime.changed(PLAYER, changed);
|
|
206
247
|
}
|
|
207
248
|
watch(watcher) {
|
|
249
|
+
void this.start();
|
|
208
250
|
this.#watchers.add(watcher);
|
|
209
251
|
const held = this.runtime.hold("source.state");
|
|
210
252
|
return {
|
|
@@ -304,6 +346,7 @@ class MediaHandle {
|
|
|
304
346
|
this.#ticket = ticket;
|
|
305
347
|
}
|
|
306
348
|
get current() {
|
|
349
|
+
void this.#service.start();
|
|
307
350
|
this.#service.runtime.depends(PLAYER, "stamp");
|
|
308
351
|
return this.#service.raw.stamp.generation === this.#ticket.stamp.generation;
|
|
309
352
|
}
|
|
@@ -377,13 +420,29 @@ class ScrubHandle {
|
|
|
377
420
|
#service;
|
|
378
421
|
constructor(service) {
|
|
379
422
|
this.#service = service;
|
|
423
|
+
// A scrub follows the source. When it is the first thing to need the
|
|
424
|
+
// state (the mirror starts now), the gesture starts from the state read
|
|
425
|
+
// right after subscribing, not from the copy of start-up.
|
|
426
|
+
const late = !service.started;
|
|
427
|
+
const fresh = service.start();
|
|
428
|
+
let ready = !late;
|
|
380
429
|
this.#allowed = { ...service.raw.stamp };
|
|
430
|
+
if (late)
|
|
431
|
+
void fresh.then(() => {
|
|
432
|
+
ready = true;
|
|
433
|
+
if (this.#active && !this.#pending)
|
|
434
|
+
this.#allowed = { ...service.raw.stamp };
|
|
435
|
+
});
|
|
381
436
|
this.#watch = service.watch((raw) => {
|
|
437
|
+
if (!ready)
|
|
438
|
+
return;
|
|
382
439
|
if (!sameStamp(raw.stamp, this.#allowed) &&
|
|
383
440
|
!(this.#pending && sameStamp(raw.stamp, this.#pending)))
|
|
384
441
|
this.end();
|
|
385
442
|
});
|
|
386
443
|
this.#queue = new Latest(async ({ seconds, keyframes }) => {
|
|
444
|
+
if (late)
|
|
445
|
+
await fresh;
|
|
387
446
|
if (!this.#active)
|
|
388
447
|
throw superseded;
|
|
389
448
|
const started = Date.now();
|
|
@@ -495,10 +554,22 @@ function provideSequence(scope, provider) {
|
|
|
495
554
|
return scope.add(handle);
|
|
496
555
|
}
|
|
497
556
|
export const playerOf = (runtime) => runtime.service("player", () => new PlayerService(runtime));
|
|
557
|
+
/**
|
|
558
|
+
* The player's source as a stream needs it (`stream.ts`, L1): a stream
|
|
559
|
+
* follows the source, so its state copy starts following the events.
|
|
560
|
+
*/
|
|
561
|
+
export function streamSource(runtime) {
|
|
562
|
+
const service = playerOf(runtime);
|
|
563
|
+
void service.start();
|
|
564
|
+
return service;
|
|
565
|
+
}
|
|
566
|
+
/** A file resolver's stream (`resolvers.ts`), over {@link streamSource}. */
|
|
567
|
+
export const resolvedPlayerStream = (scope, stream, signal) => resolvedStream(scope, streamSource(scope.runtime), stream, signal);
|
|
498
568
|
export function player(scope) {
|
|
499
569
|
const service = () => playerOf(scope.runtime);
|
|
500
570
|
return {
|
|
501
571
|
get state() {
|
|
572
|
+
void service().start();
|
|
502
573
|
scope.runtime.reading("source.state");
|
|
503
574
|
scope.runtime.depends(PLAYER);
|
|
504
575
|
return service().state;
|
|
@@ -513,7 +584,9 @@ export function player(scope) {
|
|
|
513
584
|
});
|
|
514
585
|
},
|
|
515
586
|
refresh: () => service().refresh(),
|
|
587
|
+
on: (event, listener) => playerOn(scope, event, listener),
|
|
516
588
|
isCurrent(state) {
|
|
589
|
+
void service().start();
|
|
517
590
|
const raw = raws.get(state);
|
|
518
591
|
scope.runtime.depends(PLAYER, "stamp");
|
|
519
592
|
return !!raw && sameStamp(raw.stamp, service().raw.stamp);
|
|
@@ -546,7 +619,7 @@ export function player(scope) {
|
|
|
546
619
|
}
|
|
547
620
|
return media;
|
|
548
621
|
},
|
|
549
|
-
openStream: (options) => openStream(scope,
|
|
622
|
+
openStream: (options) => openStream(scope, streamSource(scope.runtime), options),
|
|
550
623
|
setPaused: (paused, options) => service().control({ kind: "control", control: { kind: "pause", paused } }, options),
|
|
551
624
|
seek: (seconds, options) => service().control({ kind: "control", control: { kind: "seek", seconds } }, options),
|
|
552
625
|
setRate: (rate, options) => service().control({ kind: "control", control: { kind: "rate", rate } }, options),
|
package/dist/plugin/resolvers.js
CHANGED
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
* this plugin generates, for `player.open`.
|
|
4
4
|
*/
|
|
5
5
|
import { failure, quiet } from "./errors.js";
|
|
6
|
-
import {
|
|
7
|
-
import { resolvedStream } from "./stream.js";
|
|
6
|
+
import { resolvedPlayerStream } from "./player.js";
|
|
8
7
|
import { windowOf } from "./window.js";
|
|
9
8
|
const isFiles = (options) => "extensions" in options;
|
|
10
9
|
const sameTypes = (a, b) => a.length === b.length && a.every((type, i) => type === b[i]);
|
|
@@ -111,7 +110,7 @@ export const resolvers = (scope) => ({
|
|
|
111
110
|
const stream = await options.resolve(url, signal);
|
|
112
111
|
if (stream?.kind !== "stream")
|
|
113
112
|
throw failure("invalid", 'a file resolver returns { kind: "stream", width, height, frame }');
|
|
114
|
-
return
|
|
113
|
+
return resolvedPlayerStream(scope, stream, signal);
|
|
115
114
|
})
|
|
116
115
|
: runtime.host.sourceResolvers.register({ id: options.id, schemes: options.schemes, hosts: options.hosts }, ({ url, signal }) => options.resolve(url, signal));
|
|
117
116
|
let disposed = false;
|
package/dist/plugin/runtime.d.ts
CHANGED
|
@@ -7,9 +7,8 @@
|
|
|
7
7
|
import { Connection } from "./connection.ts";
|
|
8
8
|
import type { PluginManifest, RuntimeOptions } from "./connection.ts";
|
|
9
9
|
import { Passes } from "./passes.ts";
|
|
10
|
-
import type { Change, Deps, PassCounts } from "./passes.ts";
|
|
10
|
+
import type { BindingHandle, Change, Deps, PassCounts } from "./passes.ts";
|
|
11
11
|
import type { Transport } from "../wire.ts";
|
|
12
|
-
import type { Disposable } from "./types.ts";
|
|
13
12
|
export { WAKE_EVENTS } from "./connection.ts";
|
|
14
13
|
/** Per-plugin services: the connection, and the update passes over it. */
|
|
15
14
|
export declare class Runtime extends Connection {
|
|
@@ -19,7 +18,7 @@ export declare class Runtime extends Connection {
|
|
|
19
18
|
readonly counts: PassCounts;
|
|
20
19
|
constructor(transport: Transport, manifest: PluginManifest, directory: string, dataDirectory?: string, app?: unknown, options?: RuntimeOptions);
|
|
21
20
|
/** {@link Passes.bind} */
|
|
22
|
-
bind(evaluate: () => void):
|
|
21
|
+
bind(evaluate: () => void, slot?: number): BindingHandle;
|
|
23
22
|
/** {@link Passes.reading} */
|
|
24
23
|
reading(event: string): void;
|
|
25
24
|
/** {@link Passes.depends} */
|
package/dist/plugin/runtime.js
CHANGED
|
@@ -19,10 +19,16 @@ export class Runtime extends Connection {
|
|
|
19
19
|
super(transport, manifest, directory, dataDirectory, app, options);
|
|
20
20
|
this.passes = new Passes(this);
|
|
21
21
|
this.counts = this.passes.counts;
|
|
22
|
+
const passes = this.passes;
|
|
23
|
+
this.signals = {
|
|
24
|
+
read: (key, field) => passes.depends(key, field),
|
|
25
|
+
changed: (key, fields) => passes.changed(key, fields),
|
|
26
|
+
invalidate: () => passes.invalidate(),
|
|
27
|
+
};
|
|
22
28
|
}
|
|
23
29
|
/** {@link Passes.bind} */
|
|
24
|
-
bind(evaluate) {
|
|
25
|
-
return this.passes.bind(evaluate);
|
|
30
|
+
bind(evaluate, slot) {
|
|
31
|
+
return this.passes.bind(evaluate, slot);
|
|
26
32
|
}
|
|
27
33
|
/** {@link Passes.reading} */
|
|
28
34
|
reading(event) {
|
package/dist/plugin/scope.d.ts
CHANGED
|
@@ -46,6 +46,7 @@ export declare class ScopeImpl implements Plugin {
|
|
|
46
46
|
readonly appearance: import("./types.ts").Appearance;
|
|
47
47
|
readonly settings: import("./types.ts").Settings;
|
|
48
48
|
readonly i18n: import("./types.ts").I18n;
|
|
49
|
+
readonly wire: import("./types.ts").Wire;
|
|
49
50
|
get app(): import("./types.ts").App;
|
|
50
51
|
scope(): Scope;
|
|
51
52
|
add<T extends Disposable>(item: T): T;
|
|
@@ -64,6 +65,14 @@ export declare class ScopeImpl implements Plugin {
|
|
|
64
65
|
* anyway, and a full pass follows within `SAFETY_PASS_MS`.
|
|
65
66
|
*/
|
|
66
67
|
runOn(change: Change, handler: (...args: never[]) => unknown, ...args: unknown[]): void;
|
|
68
|
+
/**
|
|
69
|
+
* Run a listener that pushes its own values (`player.on`, SDK 1.7.0)
|
|
70
|
+
* like `run`, except that no full pass follows it: what it writes to
|
|
71
|
+
* `plugin.state` runs the passes for its readers, and for anything else
|
|
72
|
+
* the plugin calls `update()`. Its reads are not counted as a binding's.
|
|
73
|
+
*/
|
|
74
|
+
runQuiet(handler: (...args: never[]) => unknown, ...args: unknown[]): void;
|
|
67
75
|
update(): void;
|
|
76
|
+
state<T extends object>(initial: T): T;
|
|
68
77
|
dispose(): Promise<void>;
|
|
69
78
|
}
|
package/dist/plugin/scope.js
CHANGED
|
@@ -22,6 +22,8 @@ import { packages } from "./packages.js";
|
|
|
22
22
|
import { osd } from "./osd.js";
|
|
23
23
|
import { mainWindow } from "./window.js";
|
|
24
24
|
import { bindingsApi } from "./bindings.js";
|
|
25
|
+
import { trackedState } from "./state.js";
|
|
26
|
+
import { wire } from "./wire-facade.js";
|
|
25
27
|
import { clipboard, host, power, rendering, secrets, storage, system, tools, videoUpscaling, } from "./services.js";
|
|
26
28
|
export class ScopeImpl {
|
|
27
29
|
runtime;
|
|
@@ -83,6 +85,7 @@ export class ScopeImpl {
|
|
|
83
85
|
appearance = appearance(this);
|
|
84
86
|
settings = settings(this);
|
|
85
87
|
i18n = i18n(this);
|
|
88
|
+
wire = wire(this);
|
|
86
89
|
get app() {
|
|
87
90
|
return this.runtime.app;
|
|
88
91
|
}
|
|
@@ -180,9 +183,30 @@ export class ScopeImpl {
|
|
|
180
183
|
if (full)
|
|
181
184
|
this.update();
|
|
182
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Run a listener that pushes its own values (`player.on`, SDK 1.7.0)
|
|
188
|
+
* like `run`, except that no full pass follows it: what it writes to
|
|
189
|
+
* `plugin.state` runs the passes for its readers, and for anything else
|
|
190
|
+
* the plugin calls `update()`. Its reads are not counted as a binding's.
|
|
191
|
+
*/
|
|
192
|
+
runQuiet(handler, ...args) {
|
|
193
|
+
if (this.disposed)
|
|
194
|
+
return;
|
|
195
|
+
try {
|
|
196
|
+
const { value } = this.runtime.observe(() => handler(...args));
|
|
197
|
+
if (value instanceof Promise)
|
|
198
|
+
value.catch((error) => this.report(error));
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
this.report(error);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
183
204
|
update() {
|
|
184
205
|
this.runtime.invalidate();
|
|
185
206
|
}
|
|
207
|
+
state(initial) {
|
|
208
|
+
return trackedState(this, initial);
|
|
209
|
+
}
|
|
186
210
|
async dispose() {
|
|
187
211
|
if (this.#disposed)
|
|
188
212
|
return;
|
package/dist/plugin/services.js
CHANGED
|
@@ -9,7 +9,7 @@ import { mkdir, open, rename, rm, stat } from "node:fs/promises";
|
|
|
9
9
|
import { join, resolve } from "node:path";
|
|
10
10
|
import { failure } from "./errors.js";
|
|
11
11
|
import { systemServices } from "./local.js";
|
|
12
|
-
import {
|
|
12
|
+
import { validStep } from "./player/rules.js";
|
|
13
13
|
const MAX_OUTPUT = 16 * 1024 * 1024;
|
|
14
14
|
export const clipboard = (scope) => ({
|
|
15
15
|
readText: () => scope.runtime.host.clipboard.readText(),
|
|
@@ -45,11 +45,10 @@ export const host = (scope) => ({
|
|
|
45
45
|
throw failure("invalid", "seconds must be 0.1–3600 in tenths");
|
|
46
46
|
}
|
|
47
47
|
await scope.runtime.host.host.run(action, seconds);
|
|
48
|
-
// Like the player's own controls: `player.state` shows the result
|
|
48
|
+
// Like the player's own controls: `player.state` shows the result (the
|
|
49
|
+
// player's state copy registered how to read it again).
|
|
49
50
|
if (scope.runtime.can("playback.read"))
|
|
50
|
-
await
|
|
51
|
-
.refresh()
|
|
52
|
-
.catch(() => { });
|
|
51
|
+
await scope.runtime.reread("source.state");
|
|
53
52
|
},
|
|
54
53
|
});
|
|
55
54
|
export const power = (scope) => ({
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `plugin.state(initial)` (L2, the framework; refactor plan §3.5, SDK
|
|
3
|
+
* 1.7.0): plugin-owned state the update passes follow like the SDK's own
|
|
4
|
+
* state copies. A read of a field inside what a pass evaluates records
|
|
5
|
+
* `(store, field)` through `Runtime.depends`, the mechanism
|
|
6
|
+
* `plugin.player.state` uses; a write of a field that changes it
|
|
7
|
+
* (`Object.is`) reports `Runtime.changed(store, [field])`, so the next pass
|
|
8
|
+
* is a precise one that evaluates only that field's readers. One level:
|
|
9
|
+
* the value of a field is compared by identity, nothing inside it is
|
|
10
|
+
* tracked. It belongs to the calling scope: once that scope is disposed
|
|
11
|
+
* the object is a plain one, read and written without tracking.
|
|
12
|
+
*/
|
|
13
|
+
import { failure } from "./errors.js";
|
|
14
|
+
/** Each store's key in the passes' field tracking (`state:1`, `state:2`…). */
|
|
15
|
+
let stores = 0;
|
|
16
|
+
/** A plain object: its prototype is `Object.prototype` or `null`. */
|
|
17
|
+
function plain(value) {
|
|
18
|
+
if (value === null || typeof value !== "object")
|
|
19
|
+
return false;
|
|
20
|
+
const proto = Object.getPrototypeOf(value);
|
|
21
|
+
return proto === Object.prototype || proto === null;
|
|
22
|
+
}
|
|
23
|
+
/** `Scope.state`: a tracked copy of `initial`'s own fields. */
|
|
24
|
+
export function trackedState(scope, initial) {
|
|
25
|
+
if (!plain(initial))
|
|
26
|
+
throw failure("invalid", "state takes a plain object of fields and their first values");
|
|
27
|
+
const runtime = scope.runtime;
|
|
28
|
+
const key = `state:${++stores}`;
|
|
29
|
+
const target = { ...initial };
|
|
30
|
+
const live = () => !scope.disposed;
|
|
31
|
+
const depends = (field) => {
|
|
32
|
+
if (live())
|
|
33
|
+
runtime.depends(key, field);
|
|
34
|
+
};
|
|
35
|
+
const changed = (field) => {
|
|
36
|
+
if (live())
|
|
37
|
+
runtime.changed(key, [field]);
|
|
38
|
+
};
|
|
39
|
+
return new Proxy(target, {
|
|
40
|
+
get(store, field, receiver) {
|
|
41
|
+
if (typeof field === "string")
|
|
42
|
+
depends(field);
|
|
43
|
+
return Reflect.get(store, field, receiver);
|
|
44
|
+
},
|
|
45
|
+
has(store, field) {
|
|
46
|
+
if (typeof field === "string")
|
|
47
|
+
depends(field);
|
|
48
|
+
return Reflect.has(store, field);
|
|
49
|
+
},
|
|
50
|
+
ownKeys(store) {
|
|
51
|
+
// The list of fields: any change of the store counts.
|
|
52
|
+
depends();
|
|
53
|
+
return Reflect.ownKeys(store);
|
|
54
|
+
},
|
|
55
|
+
set(store, field, value) {
|
|
56
|
+
const had = Object.hasOwn(store, field);
|
|
57
|
+
const before = store[field];
|
|
58
|
+
store[field] = value;
|
|
59
|
+
if (typeof field === "string" && (!had || !Object.is(before, value)))
|
|
60
|
+
changed(field);
|
|
61
|
+
return true;
|
|
62
|
+
},
|
|
63
|
+
deleteProperty(store, field) {
|
|
64
|
+
const had = Object.hasOwn(store, field);
|
|
65
|
+
delete store[field];
|
|
66
|
+
if (typeof field === "string" && had)
|
|
67
|
+
changed(field);
|
|
68
|
+
return true;
|
|
69
|
+
},
|
|
70
|
+
defineProperty(store, field, descriptor) {
|
|
71
|
+
const had = Object.hasOwn(store, field);
|
|
72
|
+
const before = store[field];
|
|
73
|
+
const done = Reflect.defineProperty(store, field, descriptor);
|
|
74
|
+
if (done &&
|
|
75
|
+
typeof field === "string" &&
|
|
76
|
+
(!had || !Object.is(before, store[field])))
|
|
77
|
+
changed(field);
|
|
78
|
+
return done;
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
package/dist/plugin/stream.d.ts
CHANGED
|
@@ -1,8 +1,32 @@
|
|
|
1
|
-
import type { PlayerService } from "./player.ts";
|
|
2
1
|
import type { ScopeImpl } from "./scope.ts";
|
|
3
2
|
import type { ResolvedProducer } from "../source-resolvers.ts";
|
|
3
|
+
import type { SourceIntent, SourceState, SourceTicket } from "../source.ts";
|
|
4
|
+
import type { Wire } from "../wire.ts";
|
|
4
5
|
import type { ResolvedStream, Stream, StreamOptions } from "./types.ts";
|
|
5
|
-
|
|
6
|
+
/**
|
|
7
|
+
* The player's source as a stream uses it: submit and close it, read it
|
|
8
|
+
* again. `player.ts` passes its state copy (`PlayerService`), which follows
|
|
9
|
+
* the source while a stream exists; this file depends only on this shape,
|
|
10
|
+
* not on the copy (refactor plan §2.1).
|
|
11
|
+
*/
|
|
12
|
+
export interface StreamSource {
|
|
13
|
+
readonly runtime: {
|
|
14
|
+
readonly host: Wire;
|
|
15
|
+
can(capability: string): boolean;
|
|
16
|
+
};
|
|
17
|
+
/** The newest source state seen. */
|
|
18
|
+
readonly raw: SourceState;
|
|
19
|
+
/** The same, as the plugin sees it (`error` in the player's words). */
|
|
20
|
+
readonly state: {
|
|
21
|
+
readonly error: string | null;
|
|
22
|
+
};
|
|
23
|
+
refresh(): Promise<unknown>;
|
|
24
|
+
submit(intent: SourceIntent, options?: {
|
|
25
|
+
accepted?: (ticket: SourceTicket) => void;
|
|
26
|
+
}): Promise<SourceTicket>;
|
|
27
|
+
closeIfCurrent(generation: number): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
export declare function openStream(scope: ScopeImpl, service: StreamSource, options: StreamOptions): Promise<Stream>;
|
|
6
30
|
/**
|
|
7
31
|
* A file resolver's stream (`ResolvedStream`): prepared and prerolled while
|
|
8
32
|
* the open waits, then handed to the host as the answer. Once the host
|
|
@@ -11,4 +35,4 @@ export declare function openStream(scope: ScopeImpl, service: PlayerService, opt
|
|
|
11
35
|
* during activation (the open was replaced or closed, the plugin stopped),
|
|
12
36
|
* the producer is released and `started` is never called.
|
|
13
37
|
*/
|
|
14
|
-
export declare function resolvedStream(scope: ScopeImpl, service:
|
|
38
|
+
export declare function resolvedStream(scope: ScopeImpl, service: StreamSource, stream: ResolvedStream, signal: AbortSignal): Promise<ResolvedProducer>;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Internal to the SDK; not exported from `@vestra-player/sdk/testing`.
|
|
8
8
|
*/
|
|
9
9
|
import { HostError } from "../../wire.js";
|
|
10
|
-
import { validStep } from "../player.js";
|
|
10
|
+
import { validStep } from "../player/rules.js";
|
|
11
11
|
import { hostText } from "./i18n.js";
|
|
12
12
|
import { sourceIntent, audioCondition } from "./media.js";
|
|
13
13
|
export function coreFacts(host, _inner) {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { statSync } from "node:fs";
|
|
10
10
|
import { HostError } from "../../wire.js";
|
|
11
11
|
import { SESSION_STORAGE_LIMITS } from "../services.js";
|
|
12
|
-
import { validStep } from "../player.js";
|
|
12
|
+
import { validStep } from "../player/rules.js";
|
|
13
13
|
import { runCore, windowFacts } from "./core-actions.js";
|
|
14
14
|
import { shownText, declaredText, shownValues, hostText } from "./i18n.js";
|
|
15
15
|
import { resetWrites, writeProperty, initialValues, seeImages, kebab, } from "./layout.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Command } from "./commands.ts";
|
|
1
|
+
import type { Command, CommandOptions } from "./commands.ts";
|
|
2
2
|
import type { PackageCandidate, PluginInfo } from "./packages.ts";
|
|
3
3
|
import type { Conditional, Media, Stream } from "./playback.ts";
|
|
4
4
|
import type {
|
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
} from "./services.ts";
|
|
9
9
|
import type { ExportJob, Snapshot } from "./snapshots.ts";
|
|
10
10
|
import type { Resolver } from "./sources.ts";
|
|
11
|
-
import type { PropValue } from "./ui-content.ts";
|
|
11
|
+
import type { PropValue, View } from "./ui-content.ts";
|
|
12
12
|
import type { Panel, Window } from "./ui-layout.ts";
|
|
13
13
|
import type { Bindings, Commands, Host, When } from "./commands.ts";
|
|
14
14
|
import type { Packages } from "./packages.ts";
|
|
@@ -22,6 +22,7 @@ import type { Ui } from "./ui-content.ts";
|
|
|
22
22
|
import type { Drops, Windows } from "./ui-layout.ts";
|
|
23
23
|
import type { Appearance, I18n } from "./ui-locale.ts";
|
|
24
24
|
import type { Dialogs, Osd, Panels, Settings } from "./ui-shell.ts";
|
|
25
|
+
import type { Wire } from "./plugin-wire.ts";
|
|
25
26
|
/**
|
|
26
27
|
* Anything that owns player-side or local resources: every handle the API
|
|
27
28
|
* returns (commands, windows, panels, filters, snapshots, listeners…).
|
|
@@ -352,6 +353,16 @@ export interface Scope extends Disposable {
|
|
|
352
353
|
readonly i18n: I18n;
|
|
353
354
|
/** Pages in the player's options window (`ui.settings`). */
|
|
354
355
|
readonly settings: Settings;
|
|
356
|
+
/**
|
|
357
|
+
* Direct messages to the player: requests by method name, raw events,
|
|
358
|
+
* direct property writes, bare command registrations (SDK 1.7.0).
|
|
359
|
+
* Experimental: the wire protocol is not semver; this member changes
|
|
360
|
+
* with versions. See {@link Wire}.
|
|
361
|
+
*
|
|
362
|
+
* @experimental
|
|
363
|
+
* @since 1.7.0
|
|
364
|
+
*/
|
|
365
|
+
readonly wire: Wire;
|
|
355
366
|
/**
|
|
356
367
|
* A child scope; disposing it releases only what was created through it.
|
|
357
368
|
* The child is itself owned by this scope.
|
|
@@ -513,6 +524,71 @@ export interface Scope extends Disposable {
|
|
|
513
524
|
* @since 1.0.0
|
|
514
525
|
*/
|
|
515
526
|
update(): void;
|
|
527
|
+
/**
|
|
528
|
+
* Plugin-owned state that bound values follow by themselves: reading a
|
|
529
|
+
* field in a `bind` function or a command's state function records it,
|
|
530
|
+
* and writing that field re-evaluates exactly those readers.
|
|
531
|
+
*
|
|
532
|
+
* @remarks
|
|
533
|
+
* Returns an object of the same shape as `initial` (a copy of its own
|
|
534
|
+
* fields; `initial` itself is not tracked). A read inside a
|
|
535
|
+
* {@link View.bind} function or a {@link CommandOptions} field given as a
|
|
536
|
+
* function is recorded like a read of `plugin.player.state`; anywhere
|
|
537
|
+
* else (a handler, an `onChange` listener, a timer) it is a plain read,
|
|
538
|
+
* and writing there is how a handler updates what is bound. A write of a
|
|
539
|
+
* field (or a new field, or `delete`) schedules one
|
|
540
|
+
* update pass for the microtask turn, however many fields change, and that
|
|
541
|
+
* pass evaluates only the readers of what changed, not every binding and
|
|
542
|
+
* command as {@link Scope.update} does. Writing a value equal to the
|
|
543
|
+
* current one (`Object.is`) changes nothing.
|
|
544
|
+
*
|
|
545
|
+
* Tracking is one level deep: a field holding an object or array is
|
|
546
|
+
* compared by identity, so changing something inside it is not seen.
|
|
547
|
+
* Replace the object instead (`st.list = [...st.list, item]`). Do not
|
|
548
|
+
* write a field from a `bind` function that reads it: each write runs the
|
|
549
|
+
* function again; the SDK stops such a loop after 100 passes in a row and
|
|
550
|
+
* reports it to {@link Scope.onError} once (`limit`). The limit counts
|
|
551
|
+
* passes, not loops: a chain of bindings that is not a loop but deeper
|
|
552
|
+
* than 100 (each writing a field the next one reads) is cut the same
|
|
553
|
+
* way: what the dropped pass would have evaluated waits for the next full
|
|
554
|
+
* pass (after a handler, or {@link Scope.update}). Keep derived values in
|
|
555
|
+
* one function instead of chaining fields.
|
|
556
|
+
*
|
|
557
|
+
* The object is a `Proxy`: spread, `Object.keys` and `JSON.stringify` give
|
|
558
|
+
* its values; `structuredClone` does not take it (clone `{ ...st }`). It
|
|
559
|
+
* belongs to this scope: once the scope is disposed it is a plain object,
|
|
560
|
+
* whose reads and writes still work but are no longer recorded and
|
|
561
|
+
* schedule no pass (as other handles of a disposed scope go quiet).
|
|
562
|
+
* `update()` stays for state the SDK cannot see.
|
|
563
|
+
*
|
|
564
|
+
* @param initial - The fields and their first values: a plain object.
|
|
565
|
+
* @returns The tracked object.
|
|
566
|
+
*
|
|
567
|
+
* @throws `invalid` (throws) `initial` is not a plain object (`null`, an
|
|
568
|
+
* array, a class instance).
|
|
569
|
+
*
|
|
570
|
+
* @capability None.
|
|
571
|
+
*
|
|
572
|
+
* @example Show a check's answer without a manual update
|
|
573
|
+
* A panel shows whether the current file has video once an asynchronous
|
|
574
|
+
* check answers. The answer is written to a tracked field; only the
|
|
575
|
+
* `bind` function that reads it runs again and sends the new value, with
|
|
576
|
+
* no `plugin.update()` and no pass over every other binding.
|
|
577
|
+
* ```ts
|
|
578
|
+
* declare const bar: Panel;
|
|
579
|
+
* declare function hasVideo(path: string): Promise<boolean>;
|
|
580
|
+
* // ---cut---
|
|
581
|
+
* const st = plugin.state({ video: null as boolean | null });
|
|
582
|
+
* bar.bind(() => ({ keyframes: st.video === true })); // reads st.video
|
|
583
|
+
* plugin.player.onChange((state) => {
|
|
584
|
+
* if (state.source === null) return;
|
|
585
|
+
* void hasVideo(state.source).then((video) => (st.video = video)); // re-runs the bind above
|
|
586
|
+
* });
|
|
587
|
+
* ```
|
|
588
|
+
*
|
|
589
|
+
* @since 1.7.0
|
|
590
|
+
*/
|
|
591
|
+
state<T extends object>(initial: T): T;
|
|
516
592
|
}
|
|
517
593
|
/**
|
|
518
594
|
* The object the player passes to a plugin's `activate`: the root
|
|
@@ -31,6 +31,12 @@ export interface CommandState {
|
|
|
31
31
|
* `plugin.player.state` that changed (see {@link Scope.update}); only
|
|
32
32
|
* changes are sent to the player.
|
|
33
33
|
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* Only a command with at least one function field takes part in the update
|
|
36
|
+
* passes (SDK 1.7.0): a command whose fields are all values or
|
|
37
|
+
* `plugin.when` conditions is registered once and evaluated again only
|
|
38
|
+
* when {@link Command.set} changes it.
|
|
39
|
+
*
|
|
34
40
|
* @example Mix a computed state with a fixed one
|
|
35
41
|
* The Loop item carries a check mark while a loop is set and is always
|
|
36
42
|
* enabled. A function is evaluated again in every full update pass (after
|
|
@@ -614,7 +620,8 @@ export interface CommandOptions {
|
|
|
614
620
|
* `busy`, `reason`) is bound: functions given to {@link Commands.add} or
|
|
615
621
|
* {@link Command.set} are evaluated again in every full update pass (after
|
|
616
622
|
* a player state change only if they read a changed field of
|
|
617
|
-
* `plugin.player.state`) and only changes reach the
|
|
623
|
+
* `plugin.player.state` or {@link Scope.state}) and only changes reach the
|
|
624
|
+
* player; a command without functions is left out of the passes. Its title, path, bindings and button cannot
|
|
618
625
|
* change in place; dispose the command (or a child {@link Scope}) and add it
|
|
619
626
|
* again. Disposing it, its scope or stopping the plugin removes the menu
|
|
620
627
|
* item, its keys and its bar button.
|
|
@@ -648,6 +655,15 @@ export interface Command extends Disposable {
|
|
|
648
655
|
/**
|
|
649
656
|
* Replace some state fields (values or functions). Last write wins.
|
|
650
657
|
*
|
|
658
|
+
* @remarks
|
|
659
|
+
* Only this command is evaluated again (SDK 1.7.0; before, `set` ran a
|
|
660
|
+
* full update pass over every binding and command of the plugin). Several
|
|
661
|
+
* calls within one microtask send one update. A function field makes the
|
|
662
|
+
* command take part in the update passes from then on. A binding that
|
|
663
|
+
* reads a plugin variable changed together with `set` outside a handler
|
|
664
|
+
* the SDK runs (a timer) is not refreshed by it: call {@link Scope.update}
|
|
665
|
+
* or keep that variable in {@link Scope.state}.
|
|
666
|
+
*
|
|
651
667
|
* @example Show a command as busy while it works
|
|
652
668
|
* The Export item shows as busy with "Exporting…" as its reason while the
|
|
653
669
|
* export runs, then returns to normal. `set` replaces only the fields it
|