@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
|
@@ -55,6 +55,11 @@ export function stopReason(value) {
|
|
|
55
55
|
? value
|
|
56
56
|
: undefined;
|
|
57
57
|
}
|
|
58
|
+
const SILENT = {
|
|
59
|
+
read: () => { },
|
|
60
|
+
changed: () => { },
|
|
61
|
+
invalidate: () => { },
|
|
62
|
+
};
|
|
58
63
|
/**
|
|
59
64
|
* Per-plugin connection to the player. Scopes reach it through `Runtime`;
|
|
60
65
|
* the flat RPC clients stay private here so protocol fields never reach
|
|
@@ -81,7 +86,21 @@ export class Connection {
|
|
|
81
86
|
#warnedEvents = false;
|
|
82
87
|
views = new Map();
|
|
83
88
|
commands = new Map();
|
|
89
|
+
/**
|
|
90
|
+
* Command unregistrations in flight, by id: a command registered again
|
|
91
|
+
* with the id (`commands.add` or `plugin.wire.commands.register`) waits
|
|
92
|
+
* for its removal, or the player would refuse it with `conflict`.
|
|
93
|
+
*/
|
|
94
|
+
removals = new Map();
|
|
84
95
|
services = new Map();
|
|
96
|
+
/**
|
|
97
|
+
* How to read a state copy again, by the event that keeps it current: a
|
|
98
|
+
* mirror registers itself (`source.state` → the player's), an action that
|
|
99
|
+
* changed that state elsewhere asks for it (`reread`).
|
|
100
|
+
*/
|
|
101
|
+
rereads = new Map();
|
|
102
|
+
/** The framework's ears ({@link StateSignals}); silent until `Runtime` sets them. */
|
|
103
|
+
signals = SILENT;
|
|
85
104
|
/**
|
|
86
105
|
* Set when the player stops the plugin (`PluginInstance.dispose`), before
|
|
87
106
|
* the root scope is disposed: `DisposeInfo` and `plugin.stopReason`.
|
|
@@ -134,6 +153,12 @@ export class Connection {
|
|
|
134
153
|
can(capability) {
|
|
135
154
|
return this.manifest.capabilities.includes(capability);
|
|
136
155
|
}
|
|
156
|
+
/** Read the state copy kept by `event` again, if one exists; never rejects. */
|
|
157
|
+
async reread(event) {
|
|
158
|
+
await this.rereads
|
|
159
|
+
.get(event)?.()
|
|
160
|
+
.catch(() => { });
|
|
161
|
+
}
|
|
137
162
|
/** Lazily created singletons shared by every scope of this plugin. */
|
|
138
163
|
service(name, create) {
|
|
139
164
|
if (!this.services.has(name))
|
|
@@ -363,6 +388,15 @@ export class Connection {
|
|
|
363
388
|
result.set(event, allWhys(group));
|
|
364
389
|
return result;
|
|
365
390
|
}
|
|
391
|
+
/**
|
|
392
|
+
* One request by its method name, as given (`plugin.wire.request`, SDK
|
|
393
|
+
* 1.7.0): nothing added, nothing checked here, the player checks the
|
|
394
|
+
* capability. Every other part of the SDK uses the typed clients
|
|
395
|
+
* (`host`); `scripts/check-layers.mjs` keeps it so.
|
|
396
|
+
*/
|
|
397
|
+
request(method, params) {
|
|
398
|
+
return this.#transport.request(method, params);
|
|
399
|
+
}
|
|
366
400
|
/** Raw transport events the host pushes without a subscription. */
|
|
367
401
|
raw(event, listener) {
|
|
368
402
|
const off = this.#transport.on(event, listener);
|
package/dist/plugin/index.js
CHANGED
|
@@ -11,13 +11,23 @@ app,
|
|
|
11
11
|
/** `TestHost` sets `strictDeclarations`; the player's runner does not. */
|
|
12
12
|
options) {
|
|
13
13
|
const runtime = new Runtime(transport, manifest, directory, dataDirectory, app, options);
|
|
14
|
-
// Player, window and timeline state are synchronous for plugins: read them
|
|
14
|
+
// Player, window and timeline state are synchronous for plugins: read them
|
|
15
|
+
// first. With `events` the copy of the player's state follows the events
|
|
16
|
+
// from the start, subscribed before the read, as before 1.7.0: a read in
|
|
17
|
+
// any later handler is current. Without `events` nothing can be
|
|
18
|
+
// subscribed, and the copy starts on its first use. Window and timeline
|
|
19
|
+
// subscribe on their first use.
|
|
20
|
+
const player = playerOf(runtime);
|
|
21
|
+
if (runtime.can("events"))
|
|
22
|
+
void player.start(false);
|
|
15
23
|
await Promise.all([
|
|
16
|
-
|
|
24
|
+
player.init(),
|
|
17
25
|
windowOf(runtime).init(),
|
|
18
26
|
timelineOf(runtime).init(),
|
|
19
27
|
]);
|
|
20
28
|
const root = new ScopeImpl(runtime);
|
|
29
|
+
// A runaway of the update passes goes to the plugin's error handlers.
|
|
30
|
+
runtime.passes.report = (error) => root.report(error);
|
|
21
31
|
// Failures the plugin did not ask about: a property the player could not
|
|
22
32
|
// show when it rebuilt a panel or the Options window (an image removed
|
|
23
33
|
// since), a callback whose arguments it could not convert, a detached
|
package/dist/plugin/media.js
CHANGED
|
@@ -253,7 +253,9 @@ export function mediaCapture(scope) {
|
|
|
253
253
|
const runtime = scope.runtime;
|
|
254
254
|
const service = serviceOf(runtime);
|
|
255
255
|
const player = playerOf(runtime);
|
|
256
|
-
|
|
256
|
+
// The source now: a capture needs one, even from a plugin that never
|
|
257
|
+
// read the state (its copy then starts following the player).
|
|
258
|
+
const at = options.ifCurrent ?? (await player.current());
|
|
257
259
|
const { expected } = player.expected(at);
|
|
258
260
|
if (!expected)
|
|
259
261
|
throw failure("noSource", "no source to capture");
|
package/dist/plugin/packages.js
CHANGED
|
@@ -41,7 +41,9 @@ class ChangeHandle {
|
|
|
41
41
|
return;
|
|
42
42
|
for (const listener of this.#listeners)
|
|
43
43
|
this.#scope.run(listener, operation.status);
|
|
44
|
-
|
|
44
|
+
// `status` changed: bindings that show it are evaluated again (a full
|
|
45
|
+
// pass, through the connection: this file is a primitive).
|
|
46
|
+
this.#scope.runtime.signals.invalidate();
|
|
45
47
|
}
|
|
46
48
|
async #poll() {
|
|
47
49
|
const host = this.#scope.runtime.host.packages;
|
package/dist/plugin/passes.d.ts
CHANGED
|
@@ -21,6 +21,17 @@ export type Change = ReadonlyMap<string, ReadonlySet<string>>;
|
|
|
21
21
|
* without `update()`) still shows within about this long.
|
|
22
22
|
*/
|
|
23
23
|
export declare const SAFETY_PASS_MS = 1000;
|
|
24
|
+
/**
|
|
25
|
+
* The most passes in a row that a pass itself asks for (something it
|
|
26
|
+
* evaluated changed what it reads, `plugin.state` written in a `bind`
|
|
27
|
+
* function). The next one is dropped and reported once: without it such a
|
|
28
|
+
* plugin would spin in microtasks and never yield. It counts passes, not
|
|
29
|
+
* loops: a legitimate chain deeper than this (101 bindings, each writing a
|
|
30
|
+
* `plugin.state` field the next one reads) is cut the same way: the
|
|
31
|
+
* readers of the dropped pass's changes run again only in the next full
|
|
32
|
+
* pass (after a handler, `update()`).
|
|
33
|
+
*/
|
|
34
|
+
export declare const MAX_CHAINED_PASSES = 100;
|
|
24
35
|
/**
|
|
25
36
|
* Read-only counters of the update passes, for the SDK's own
|
|
26
37
|
* characterisation tests and benchmark (`test/golden-traces.test.ts`,
|
|
@@ -45,13 +56,39 @@ export interface PassCounts {
|
|
|
45
56
|
*/
|
|
46
57
|
safetyPasses: number;
|
|
47
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* One `Passes.bind` registration as its owner holds it: dispose it, or ask
|
|
61
|
+
* for it alone to be evaluated again ({@link BindingHandle.invalidate}).
|
|
62
|
+
*/
|
|
63
|
+
export interface BindingHandle extends Disposable {
|
|
64
|
+
/**
|
|
65
|
+
* Evaluate this binding in the next pass even if nothing it read
|
|
66
|
+
* changed (a precise pass, not a full one): its owner changed something
|
|
67
|
+
* the binding reads that no state copy tracks (`Command.set`).
|
|
68
|
+
*/
|
|
69
|
+
invalidate(): void;
|
|
70
|
+
}
|
|
48
71
|
/** The update pass scheduler of one plugin (`Runtime` delegates to it). */
|
|
49
72
|
export declare class Passes {
|
|
50
73
|
#private;
|
|
74
|
+
/** Where a runaway goes: the plugin's error handlers (`createPlugin`). */
|
|
75
|
+
report: (error: unknown) => void;
|
|
51
76
|
/** Pass counters, read by the SDK's own tests and benchmark ({@link PassCounts}). */
|
|
52
77
|
readonly counts: PassCounts;
|
|
53
78
|
constructor(connection: Connection);
|
|
54
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Register a binding: `evaluate` runs in a full pass now and in every
|
|
81
|
+
* pass that concerns it. Only what calls this takes part in the passes:
|
|
82
|
+
* a view on its first `bind()`, a command with a function field, a
|
|
83
|
+
* sequence provider (SDK 1.7.0; before, every view and command).
|
|
84
|
+
*/
|
|
85
|
+
bind(evaluate: () => void, slot?: number): BindingHandle;
|
|
86
|
+
/**
|
|
87
|
+
* A place in the evaluation order, for a binding made later (`bind`): a
|
|
88
|
+
* view or a command reserves one when it is made, so it is evaluated in
|
|
89
|
+
* the order of making whenever it joins.
|
|
90
|
+
*/
|
|
91
|
+
slot(): number;
|
|
55
92
|
/**
|
|
56
93
|
* A service's state for `event` is read: a binding evaluated now depends
|
|
57
94
|
* on it, so the event counts as listened to while the binding reads it.
|
package/dist/plugin/passes.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { failure } from "./errors.js";
|
|
1
2
|
/**
|
|
2
3
|
* The state each event keeps current, and whether `plugin.when` can say
|
|
3
4
|
* the same without the plugin running.
|
|
@@ -47,12 +48,28 @@ function merge(into, from) {
|
|
|
47
48
|
* without `update()`) still shows within about this long.
|
|
48
49
|
*/
|
|
49
50
|
export const SAFETY_PASS_MS = 1000;
|
|
51
|
+
/**
|
|
52
|
+
* The most passes in a row that a pass itself asks for (something it
|
|
53
|
+
* evaluated changed what it reads, `plugin.state` written in a `bind`
|
|
54
|
+
* function). The next one is dropped and reported once: without it such a
|
|
55
|
+
* plugin would spin in microtasks and never yield. It counts passes, not
|
|
56
|
+
* loops: a legitimate chain deeper than this (101 bindings, each writing a
|
|
57
|
+
* `plugin.state` field the next one reads) is cut the same way: the
|
|
58
|
+
* readers of the dropped pass's changes run again only in the next full
|
|
59
|
+
* pass (after a handler, `update()`).
|
|
60
|
+
*/
|
|
61
|
+
export const MAX_CHAINED_PASSES = 100;
|
|
50
62
|
/** The update pass scheduler of one plugin (`Runtime` delegates to it). */
|
|
51
63
|
export class Passes {
|
|
52
64
|
/** The plugin's connection: holds the events a binding reads. */
|
|
53
65
|
#connection;
|
|
54
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* Each binding with the events whose state it read last time (held), in
|
|
68
|
+
* the order of their slots (`slot`): the order they are evaluated in.
|
|
69
|
+
*/
|
|
55
70
|
#bindings = new Map();
|
|
71
|
+
/** The last slot handed out (`slot`). */
|
|
72
|
+
#slots = 0;
|
|
56
73
|
/** The events read by the binding being evaluated, with who read them. */
|
|
57
74
|
#reads;
|
|
58
75
|
/** Who reads now (a command's field and where it was added). */
|
|
@@ -62,6 +79,8 @@ export class Passes {
|
|
|
62
79
|
#full = false;
|
|
63
80
|
/** State copy changes since the last pass (a precise pass, unless `#full`). */
|
|
64
81
|
#pending = new Map();
|
|
82
|
+
/** Bindings their owner asked to evaluate in the next pass (`BindingHandle.invalidate`). */
|
|
83
|
+
#dirty = new Set();
|
|
65
84
|
/** The change the running precise pass is for; `undefined` in a full pass. */
|
|
66
85
|
#pass;
|
|
67
86
|
/** The state copy fields read by what is being evaluated now. */
|
|
@@ -74,6 +93,16 @@ export class Passes {
|
|
|
74
93
|
#skipped = false;
|
|
75
94
|
/** The plugin was disposed: no safety pass is armed any more. */
|
|
76
95
|
#stopped = false;
|
|
96
|
+
/** A pass is evaluating bindings now. */
|
|
97
|
+
#running = false;
|
|
98
|
+
/** The scheduled pass was asked for while a pass ran. */
|
|
99
|
+
#nested = false;
|
|
100
|
+
/** Passes in a row that the pass before asked for (`MAX_CHAINED_PASSES`). */
|
|
101
|
+
#chain = 0;
|
|
102
|
+
/** The runaway was reported (once per plugin). */
|
|
103
|
+
#reportedChain = false;
|
|
104
|
+
/** Where a runaway goes: the plugin's error handlers (`createPlugin`). */
|
|
105
|
+
report = (error) => console.error(`[${this.#connection.manifest.id}]`, error);
|
|
77
106
|
/** Pass counters, read by the SDK's own tests and benchmark ({@link PassCounts}). */
|
|
78
107
|
counts = {
|
|
79
108
|
passes: 0,
|
|
@@ -86,22 +115,48 @@ export class Passes {
|
|
|
86
115
|
constructor(connection) {
|
|
87
116
|
this.#connection = connection;
|
|
88
117
|
}
|
|
89
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Register a binding: `evaluate` runs in a full pass now and in every
|
|
120
|
+
* pass that concerns it. Only what calls this takes part in the passes:
|
|
121
|
+
* a view on its first `bind()`, a command with a function field, a
|
|
122
|
+
* sequence provider (SDK 1.7.0; before, every view and command).
|
|
123
|
+
*/
|
|
124
|
+
bind(evaluate, slot = this.slot()) {
|
|
90
125
|
const held = new Map();
|
|
91
|
-
const binding = { held, deps: new Map() };
|
|
126
|
+
const binding = { held, deps: new Map(), slot };
|
|
127
|
+
const last = [...this.#bindings.values()].at(-1);
|
|
92
128
|
this.#bindings.set(evaluate, binding);
|
|
129
|
+
// A slot reserved earlier (a view made before it was bound): evaluated
|
|
130
|
+
// where it was made, as when every view joined the passes when made.
|
|
131
|
+
if (last && last.slot > slot)
|
|
132
|
+
this.#bindings = new Map([...this.#bindings].sort((a, b) => a[1].slot - b[1].slot));
|
|
93
133
|
this.invalidate();
|
|
94
134
|
return {
|
|
135
|
+
invalidate: () => {
|
|
136
|
+
if (this.#bindings.get(evaluate) !== binding)
|
|
137
|
+
return;
|
|
138
|
+
this.#dirty.add(binding);
|
|
139
|
+
this.#schedule();
|
|
140
|
+
},
|
|
95
141
|
dispose: async () => {
|
|
96
142
|
if (this.#bindings.get(evaluate) !== binding)
|
|
97
143
|
return;
|
|
98
144
|
this.#bindings.delete(evaluate);
|
|
145
|
+
this.#dirty.delete(binding);
|
|
99
146
|
for (const hold of held.values())
|
|
100
147
|
await hold.dispose();
|
|
101
148
|
held.clear();
|
|
102
149
|
},
|
|
103
150
|
};
|
|
104
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* A place in the evaluation order, for a binding made later (`bind`): a
|
|
154
|
+
* view or a command reserves one when it is made, so it is evaluated in
|
|
155
|
+
* the order of making whenever it joins.
|
|
156
|
+
*/
|
|
157
|
+
slot() {
|
|
158
|
+
return ++this.#slots;
|
|
159
|
+
}
|
|
105
160
|
/**
|
|
106
161
|
* A service's state for `event` is read: a binding evaluated now depends
|
|
107
162
|
* on it, so the event counts as listened to while the binding reads it.
|
|
@@ -281,9 +336,18 @@ export class Passes {
|
|
|
281
336
|
this.#schedule();
|
|
282
337
|
}
|
|
283
338
|
#schedule() {
|
|
339
|
+
// Nothing takes part in the passes (a plugin of handlers, `set()` and
|
|
340
|
+
// constant commands only): no pass at all. The first `bind` asks for
|
|
341
|
+
// a full pass anyway.
|
|
342
|
+
if (this.#bindings.size === 0) {
|
|
343
|
+
this.#full = false;
|
|
344
|
+
this.#pending.clear();
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
284
347
|
if (this.#scheduled)
|
|
285
348
|
return;
|
|
286
349
|
this.#scheduled = true;
|
|
350
|
+
this.#nested = this.#running;
|
|
287
351
|
queueMicrotask(() => this.#run());
|
|
288
352
|
}
|
|
289
353
|
/**
|
|
@@ -293,10 +357,27 @@ export class Passes {
|
|
|
293
357
|
*/
|
|
294
358
|
#run() {
|
|
295
359
|
this.#scheduled = false;
|
|
360
|
+
this.#chain = this.#nested ? this.#chain + 1 : 0;
|
|
361
|
+
this.#nested = false;
|
|
362
|
+
if (this.#chain >= MAX_CHAINED_PASSES) {
|
|
363
|
+
// A loop: each pass changed what it reads. Drop this one; the next
|
|
364
|
+
// change from outside a pass starts afresh.
|
|
365
|
+
this.#chain = 0;
|
|
366
|
+
this.#full = false;
|
|
367
|
+
this.#pending = new Map();
|
|
368
|
+
this.#dirty.clear();
|
|
369
|
+
if (!this.#reportedChain) {
|
|
370
|
+
this.#reportedChain = true;
|
|
371
|
+
this.report(failure("limit", `${MAX_CHAINED_PASSES} update passes in a row each changed what they read (a bind function or a command's state function that writes plugin.state it reads); the next was dropped`));
|
|
372
|
+
}
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
296
375
|
const full = this.#full;
|
|
297
376
|
const change = this.#pending;
|
|
377
|
+
const dirty = new Set(this.#dirty);
|
|
298
378
|
this.#full = false;
|
|
299
379
|
this.#pending = new Map();
|
|
380
|
+
this.#dirty.clear();
|
|
300
381
|
this.counts.passes++;
|
|
301
382
|
if (full)
|
|
302
383
|
this.counts.fullPasses++;
|
|
@@ -305,14 +386,16 @@ export class Passes {
|
|
|
305
386
|
this.#safety = undefined;
|
|
306
387
|
}
|
|
307
388
|
this.#skipped = false;
|
|
389
|
+
this.#running = true;
|
|
308
390
|
for (const [evaluate, binding] of [...this.#bindings]) {
|
|
309
391
|
if (this.#bindings.get(evaluate) !== binding)
|
|
310
392
|
continue;
|
|
311
|
-
if (!full && !affected(binding.deps, change)) {
|
|
393
|
+
if (!full && !dirty.has(binding) && !affected(binding.deps, change)) {
|
|
312
394
|
this.#skipped = true;
|
|
313
395
|
continue;
|
|
314
396
|
}
|
|
315
|
-
|
|
397
|
+
// A binding its owner invalidated is evaluated whole (every part).
|
|
398
|
+
this.#pass = full || dirty.has(binding) ? undefined : change;
|
|
316
399
|
try {
|
|
317
400
|
this.#evaluate(evaluate, binding);
|
|
318
401
|
}
|
|
@@ -323,6 +406,7 @@ export class Passes {
|
|
|
323
406
|
this.#pass = undefined;
|
|
324
407
|
}
|
|
325
408
|
}
|
|
409
|
+
this.#running = false;
|
|
326
410
|
if (this.#skipped && !this.#safety && !this.#stopped) {
|
|
327
411
|
this.#safety = setTimeout(() => {
|
|
328
412
|
this.#safety = undefined;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ScopeImpl } from "../scope.ts";
|
|
2
|
+
import type { Disposable, EventPayload, HostEvent } from "../types.ts";
|
|
3
|
+
/**
|
|
4
|
+
* The capability each event needs, as the player checks `events.subscribe`
|
|
5
|
+
* (`HOST_CAPABILITIES`: by event, otherwise `events`); `null`: none.
|
|
6
|
+
*/
|
|
7
|
+
export declare const EVENT_NEEDS: Readonly<Record<HostEvent, string | null>>;
|
|
8
|
+
/** `Player.on`: `listener` hears each `event`, with a copy of its data. */
|
|
9
|
+
export declare function playerOn<E extends HostEvent>(scope: ScopeImpl, event: E, listener: (data: EventPayload<E>) => void): Disposable;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `plugin.player.on` (L1, refactor plan §2.2; SDK 1.7.0): one listener of
|
|
3
|
+
* one player event, with the event's data as the player sent it. It is a
|
|
4
|
+
* plain subscription of the connection (counted as a listener, its `why`
|
|
5
|
+
* naming where the plugin added it), never a state copy: nothing is kept,
|
|
6
|
+
* nothing is compared.
|
|
7
|
+
*/
|
|
8
|
+
import { failure } from "../errors.js";
|
|
9
|
+
/**
|
|
10
|
+
* The capability each event needs, as the player checks `events.subscribe`
|
|
11
|
+
* (`HOST_CAPABILITIES`: by event, otherwise `events`); `null`: none.
|
|
12
|
+
*/
|
|
13
|
+
export const EVENT_NEEDS = {
|
|
14
|
+
"source.state": "events",
|
|
15
|
+
"playback.backend": "events",
|
|
16
|
+
"window.state": "events",
|
|
17
|
+
"packages.changed": null,
|
|
18
|
+
"bindings.changed": "bindings.manage",
|
|
19
|
+
"commands.keys": "commands",
|
|
20
|
+
"timeline.changed": "events",
|
|
21
|
+
"appearance.changed": "events",
|
|
22
|
+
"resolvers.fileTypes": "events",
|
|
23
|
+
"video.upscaling.changed": "video.upscaling",
|
|
24
|
+
};
|
|
25
|
+
/** `Player.on`: `listener` hears each `event`, with a copy of its data. */
|
|
26
|
+
export function playerOn(scope, event, listener) {
|
|
27
|
+
if (typeof event !== "string" || !Object.hasOwn(EVENT_NEEDS, event))
|
|
28
|
+
throw failure("invalid", `unknown event ${JSON.stringify(event)}; the events are ${Object.keys(EVENT_NEEDS).join(", ")}`);
|
|
29
|
+
if (typeof listener !== "function")
|
|
30
|
+
throw failure("invalid", "on takes an event name and a listener");
|
|
31
|
+
const watch = scope.runtime.on(event,
|
|
32
|
+
// A copy: the same data also feeds the SDK's own state copies.
|
|
33
|
+
// No full pass after it (`runQuiet`): the listener pushes its own
|
|
34
|
+
// values; `plugin.state` writes run the passes that concern them.
|
|
35
|
+
(data) => scope.runQuiet(listener, structuredClone(data)), EVENT_NEEDS[event]);
|
|
36
|
+
const handle = {
|
|
37
|
+
dispose: async () => {
|
|
38
|
+
scope.forget(handle);
|
|
39
|
+
await watch.dispose();
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
return scope.add(handle);
|
|
43
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The player's rules for its controls that the SDK checks before asking
|
|
3
|
+
* (L1, refactor plan §2.2): shared by `plugin.player`, `plugin.host` and
|
|
4
|
+
* `TestHost`.
|
|
5
|
+
*/
|
|
6
|
+
/** A step-seek length the player accepts: 0.1–3600 seconds in tenths. */
|
|
7
|
+
export declare const validStep: (seconds: unknown) => seconds is number;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The player's rules for its controls that the SDK checks before asking
|
|
3
|
+
* (L1, refactor plan §2.2): shared by `plugin.player`, `plugin.host` and
|
|
4
|
+
* `TestHost`.
|
|
5
|
+
*/
|
|
6
|
+
/** A step-seek length the player accepts: 0.1–3600 seconds in tenths. */
|
|
7
|
+
export const validStep = (seconds) => typeof seconds === "number" &&
|
|
8
|
+
Number.isFinite(seconds) &&
|
|
9
|
+
seconds >= 0.1 &&
|
|
10
|
+
seconds <= 3600 &&
|
|
11
|
+
Math.abs(Math.round(seconds * 10) - seconds * 10) <= 1e-9;
|
package/dist/plugin/player.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import type { SourceIntent, SourceStamp, SourceState, SourceTicket } from "../so
|
|
|
2
2
|
import { Latest } from "./latest.ts";
|
|
3
3
|
import type { Runtime } from "./runtime.ts";
|
|
4
4
|
import type { ScopeImpl } from "./scope.ts";
|
|
5
|
+
import { resolvedStream } from "./stream.ts";
|
|
6
|
+
import type { StreamSource } from "./stream.ts";
|
|
5
7
|
import type { Conditional, Disposable, Player, PlayerState } from "./types.ts";
|
|
6
8
|
/**
|
|
7
9
|
* The key of `plugin.player.state` in the runtime's field tracking
|
|
@@ -10,11 +12,21 @@ import type { Conditional, Disposable, Player, PlayerState } from "./types.ts";
|
|
|
10
12
|
*/
|
|
11
13
|
export declare const PLAYER = "player";
|
|
12
14
|
export declare const rawOf: (state: PlayerState) => SourceState | undefined;
|
|
13
|
-
/** A step-seek length the player accepts: 0.1–3600 seconds in tenths. */
|
|
14
|
-
export declare const validStep: (seconds: unknown) => seconds is number;
|
|
15
15
|
export declare const sameStamp: (a: SourceStamp, b: SourceStamp) => boolean;
|
|
16
|
-
/**
|
|
17
|
-
|
|
16
|
+
/**
|
|
17
|
+
* One per plugin: the state store and the operation book client.
|
|
18
|
+
*
|
|
19
|
+
* The state copy (a mirror of `source.state`) follows the player's events
|
|
20
|
+
* from the plugin's start when the manifest declares `events`
|
|
21
|
+
* (`createPlugin` subscribes before the start-up read, as before 1.7.0, so
|
|
22
|
+
* a read in any later handler is current). Without `events` no event can
|
|
23
|
+
* arrive; `start` is then called by the first use of the state (a read of
|
|
24
|
+
* `plugin.player.state`, `onChange`, `isCurrent`, a media handle, a
|
|
25
|
+
* scrub, a stream, a filter, a shader or view request, a capture) and
|
|
26
|
+
* subscribes nothing. A start on demand with `events` and `playback.read`
|
|
27
|
+
* would read the state again; `createPlugin` makes it unreachable today.
|
|
28
|
+
*/
|
|
29
|
+
export declare class PlayerService implements StreamSource {
|
|
18
30
|
#private;
|
|
19
31
|
readonly runtime: Runtime;
|
|
20
32
|
raw: SourceState;
|
|
@@ -30,6 +42,20 @@ export declare class PlayerService {
|
|
|
30
42
|
}>;
|
|
31
43
|
constructor(runtime: Runtime);
|
|
32
44
|
init(): Promise<void>;
|
|
45
|
+
/** Whether the mirror follows the player's events yet. */
|
|
46
|
+
get started(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Follow `source.state` from now on: the SDK's copy of the state (a
|
|
49
|
+
* mirror; a plugin listens through `watch` and the bindings that read
|
|
50
|
+
* `state`). Then read the state once more (with `playback.read` and
|
|
51
|
+
* `events`): a change between the start-up read and the subscription
|
|
52
|
+
* sent no event to this plugin. Resolves when that read is in.
|
|
53
|
+
* `reread: false`: subscribed before the start-up read
|
|
54
|
+
* (`createPlugin`), which then is that read.
|
|
55
|
+
*/
|
|
56
|
+
start(reread?: boolean): Promise<void>;
|
|
57
|
+
/** The state as the player has it now, for a call that needs a source. */
|
|
58
|
+
current(): Promise<PlayerState>;
|
|
33
59
|
/** Drop anything older than what was already delivered. */
|
|
34
60
|
accept(raw: SourceState): void;
|
|
35
61
|
watch(watcher: (raw: SourceState) => void): Disposable;
|
|
@@ -52,4 +78,11 @@ export declare class PlayerService {
|
|
|
52
78
|
closeIfCurrent(generation: number): Promise<void>;
|
|
53
79
|
}
|
|
54
80
|
export declare const playerOf: (runtime: Runtime) => PlayerService;
|
|
81
|
+
/**
|
|
82
|
+
* The player's source as a stream needs it (`stream.ts`, L1): a stream
|
|
83
|
+
* follows the source, so its state copy starts following the events.
|
|
84
|
+
*/
|
|
85
|
+
export declare function streamSource(runtime: Runtime): StreamSource;
|
|
86
|
+
/** A file resolver's stream (`resolvers.ts`), over {@link streamSource}. */
|
|
87
|
+
export declare const resolvedPlayerStream: (scope: ScopeImpl, stream: Parameters<typeof resolvedStream>[2], signal: AbortSignal) => Promise<import("../source-resolvers.ts").ResolvedProducer>;
|
|
55
88
|
export declare function player(scope: ScopeImpl): Player;
|