@vestra-player/sdk 1.7.20 → 1.9.0
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 +72 -0
- package/README.md +2 -2
- package/bin/vestra-plugin.mjs +139 -100
- package/capability-scan.json +369 -0
- package/dist/api-requests.d.ts +11 -36
- package/dist/api-requests.js +22 -47
- package/dist/capability-scan.d.ts +95 -0
- package/dist/capability-scan.js +249 -0
- package/dist/commands.d.ts +35 -0
- package/dist/commands.js +42 -1
- package/dist/docs-tree.json.gz +0 -0
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +1 -1
- package/dist/index.d.ts +4 -5
- package/dist/manifest.d.ts +5 -0
- package/dist/manifest.js +9 -24
- package/dist/member-uses.d.ts +61 -0
- package/dist/member-uses.js +160 -0
- package/dist/mpv.d.ts +139 -0
- package/dist/mpv.js +496 -0
- package/dist/player-runtime.d.ts +3 -3
- package/dist/player-runtime.js +3 -3
- package/dist/plugin/appearance.d.ts +1 -1
- package/dist/plugin/appearance.js +2 -2
- package/dist/plugin/bindings.d.ts +1 -1
- package/dist/plugin/bindings.js +2 -2
- package/dist/plugin/commands.js +6 -14
- package/dist/plugin/connection.d.ts +26 -7
- package/dist/plugin/connection.js +68 -36
- package/dist/plugin/drops.js +1 -1
- package/dist/plugin/index.js +9 -15
- package/dist/plugin/media.js +0 -12
- package/dist/plugin/mpv.d.ts +3 -0
- package/dist/plugin/mpv.js +91 -0
- package/dist/plugin/packages.js +1 -2
- package/dist/plugin/player/events.d.ts +4 -3
- package/dist/plugin/player/events.js +7 -6
- package/dist/plugin/player.d.ts +21 -13
- package/dist/plugin/player.js +56 -21
- package/dist/plugin/scope.d.ts +1 -0
- package/dist/plugin/scope.js +2 -0
- package/dist/plugin/services.d.ts +4 -4
- package/dist/plugin/services.js +7 -29
- package/dist/plugin/settings.js +1 -1
- package/dist/plugin/shaders.js +0 -2
- package/dist/plugin/stream.d.ts +2 -1
- package/dist/plugin/stream.js +2 -2
- package/dist/plugin/testing/commands.d.ts +3 -10
- package/dist/plugin/testing/commands.js +43 -24
- package/dist/plugin/testing/index.d.ts +75 -114
- package/dist/plugin/testing/index.js +83 -102
- package/dist/plugin/testing/mpv.d.ts +7 -0
- package/dist/plugin/testing/mpv.js +90 -0
- package/dist/plugin/testing/processing.js +1 -1
- package/dist/plugin/testing/services.js +0 -1
- package/dist/plugin/timeline.d.ts +2 -3
- package/dist/plugin/timeline.js +4 -8
- package/dist/plugin/types/base.d.ts +49 -88
- package/dist/plugin/types/commands.d.ts +44 -77
- package/dist/plugin/types/packages.d.ts +17 -55
- package/dist/plugin/types/playback.d.ts +302 -135
- package/dist/plugin/types/plugin-wire.d.ts +6 -36
- package/dist/plugin/types/processing.d.ts +10 -49
- package/dist/plugin/types/services.d.ts +11 -70
- package/dist/plugin/types/snapshots.d.ts +7 -60
- package/dist/plugin/types/sources.d.ts +2 -11
- package/dist/plugin/types/subtitles.d.ts +5 -26
- package/dist/plugin/types/ui-content.d.ts +1 -16
- package/dist/plugin/types/ui-layout.d.ts +53 -79
- package/dist/plugin/types/ui-locale.d.ts +5 -23
- package/dist/plugin/types/ui-shell.d.ts +13 -59
- package/dist/plugin/view/layout.js +1 -1
- package/dist/plugin/view.js +0 -2
- package/dist/plugin/window.d.ts +1 -1
- package/dist/plugin/window.js +1 -1
- package/dist/plugin/wire-facade.js +1 -2
- package/dist/processing.d.ts +2 -3
- package/dist/protocol.d.ts +14 -0
- package/dist/protocol.js +14 -0
- package/dist/request-queue.js +1 -1
- package/dist/subtitles.d.ts +1 -1
- package/dist/ts-plugin.d.ts +8 -15
- package/dist/ts-plugin.js +3 -141
- package/dist/wire.d.ts +22 -12
- package/dist/wire.js +17 -8
- package/llms.txt +5 -5
- package/package.json +4 -3
- package/slint/vestra/widgets.slint +12 -4
- package/dist/capabilities.d.ts +0 -107
- package/dist/capabilities.js +0 -69
- package/dist/capability-check.d.ts +0 -133
- package/dist/capability-check.js +0 -371
- package/dist/capability-rules.d.ts +0 -125
- package/dist/capability-rules.js +0 -192
- package/dist/host-capabilities.d.ts +0 -10
- package/dist/host-capabilities.js +0 -477
|
@@ -12,9 +12,14 @@ export type Why = () => string;
|
|
|
12
12
|
* the palette, a resolver), not playback.
|
|
13
13
|
*/
|
|
14
14
|
export declare const WAKE_EVENTS: readonly string[];
|
|
15
|
+
/**
|
|
16
|
+
* What the runtime reads of the plugin's manifest: its id. Nothing in the
|
|
17
|
+
* manifest switches behaviour (1.9.0): event delivery and the start-up
|
|
18
|
+
* reads are the plugin's explicit calls (`plugin.player.subscribe()`,
|
|
19
|
+
* `plugin.player.read()`).
|
|
20
|
+
*/
|
|
15
21
|
export interface PluginManifest {
|
|
16
22
|
id: string;
|
|
17
|
-
capabilities: string[];
|
|
18
23
|
}
|
|
19
24
|
/** How the plugin is run: the player's runner, or `TestHost`. */
|
|
20
25
|
export interface RuntimeOptions {
|
|
@@ -63,6 +68,11 @@ export declare class Connection {
|
|
|
63
68
|
* `REQUEST_LIMITS` in flight, the rest wait in order (`request-queue.ts`).
|
|
64
69
|
*/
|
|
65
70
|
readonly requests: RequestQueue;
|
|
71
|
+
/**
|
|
72
|
+
* The player's state is read again after the plugin's own actions:
|
|
73
|
+
* `plugin.player.read()` was called.
|
|
74
|
+
*/
|
|
75
|
+
reads: boolean;
|
|
66
76
|
readonly views: Map<string, (callback: string, args: Json[]) => void>;
|
|
67
77
|
readonly commands: Map<string, () => void>;
|
|
68
78
|
/**
|
|
@@ -104,7 +114,14 @@ export declare class Connection {
|
|
|
104
114
|
*/
|
|
105
115
|
readonly features: ReadonlySet<string>;
|
|
106
116
|
constructor(transport: Transport, manifest: PluginManifest, directory: string, dataDirectory?: string, app?: unknown, options?: RuntimeOptions);
|
|
107
|
-
|
|
117
|
+
/** Event delivery is on (`plugin.player.subscribe()` was called). */
|
|
118
|
+
get delivering(): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Turn event delivery on (`plugin.player.subscribe()`): every later
|
|
121
|
+
* listener is subscribed, and so is what was added before and heard
|
|
122
|
+
* nothing. Idempotent.
|
|
123
|
+
*/
|
|
124
|
+
deliver(): void;
|
|
108
125
|
/** Read the state copy kept by `event` again, if one exists; never rejects. */
|
|
109
126
|
reread(event: string): Promise<void>;
|
|
110
127
|
/** Lazily created singletons shared by every scope of this plugin. */
|
|
@@ -133,17 +150,19 @@ export declare class Connection {
|
|
|
133
150
|
callSite(): () => string | undefined;
|
|
134
151
|
/**
|
|
135
152
|
* Host events with one `events.subscribe` per name, however many listeners.
|
|
136
|
-
*
|
|
153
|
+
* An event that needs delivery (`"events"`) is subscribed only once
|
|
154
|
+
* `plugin.player.subscribe()` was called; until then its listener simply
|
|
155
|
+
* never fires.
|
|
137
156
|
* `mirror`: the SDK's own copy of the state (`plugin.player.state` and
|
|
138
157
|
* the like), not a listener of the plugin's (see {@link EventGroup}).
|
|
139
158
|
*/
|
|
140
159
|
on(event: string, listener: Listener,
|
|
141
|
-
/**
|
|
142
|
-
needs?:
|
|
160
|
+
/** `"events"`: it arrives after `plugin.player.subscribe()`; `null`: always. */
|
|
161
|
+
needs?: "events" | null, mirror?: boolean): Disposable;
|
|
143
162
|
/**
|
|
144
163
|
* Count `event` as listened to while held: a watcher of a service's
|
|
145
164
|
* state, a binding that reads it. Nothing when nothing subscribed to it
|
|
146
|
-
* (no
|
|
165
|
+
* (no `plugin.player.subscribe()`, or the service did not start).
|
|
147
166
|
*/
|
|
148
167
|
hold(event: string, why?: Why): Disposable;
|
|
149
168
|
/**
|
|
@@ -154,7 +173,7 @@ export declare class Connection {
|
|
|
154
173
|
listening(): Map<string, string[]>;
|
|
155
174
|
/**
|
|
156
175
|
* One request by its method name, as given (`plugin.wire.request`): nothing
|
|
157
|
-
* added, nothing checked here
|
|
176
|
+
* added, nothing checked here; the player checks the request. Every other
|
|
158
177
|
* part of the SDK uses the typed clients (`host`); `scripts/check-layers.mjs`
|
|
159
178
|
* keeps it so. It waits in the request queue like every other.
|
|
160
179
|
*/
|
|
@@ -88,8 +88,18 @@ export class Connection {
|
|
|
88
88
|
*/
|
|
89
89
|
requests;
|
|
90
90
|
#events = new Map();
|
|
91
|
-
/** The missing `
|
|
91
|
+
/** The missing `subscribe()` warning was given (once per plugin). */
|
|
92
92
|
#warnedEvents = false;
|
|
93
|
+
/**
|
|
94
|
+
* Event delivery is on: `plugin.player.subscribe()` was called
|
|
95
|
+
* ({@link Connection.deliver}).
|
|
96
|
+
*/
|
|
97
|
+
#delivering = false;
|
|
98
|
+
/**
|
|
99
|
+
* The player's state is read again after the plugin's own actions:
|
|
100
|
+
* `plugin.player.read()` was called.
|
|
101
|
+
*/
|
|
102
|
+
reads = false;
|
|
93
103
|
views = new Map();
|
|
94
104
|
commands = new Map();
|
|
95
105
|
/**
|
|
@@ -169,8 +179,24 @@ export class Connection {
|
|
|
169
179
|
this.commands.get(data.id)?.();
|
|
170
180
|
});
|
|
171
181
|
}
|
|
172
|
-
|
|
173
|
-
|
|
182
|
+
/** Event delivery is on (`plugin.player.subscribe()` was called). */
|
|
183
|
+
get delivering() {
|
|
184
|
+
return this.#delivering;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Turn event delivery on (`plugin.player.subscribe()`): every later
|
|
188
|
+
* listener is subscribed, and so is what was added before and heard
|
|
189
|
+
* nothing. Idempotent.
|
|
190
|
+
*/
|
|
191
|
+
deliver() {
|
|
192
|
+
if (this.#delivering)
|
|
193
|
+
return;
|
|
194
|
+
this.#delivering = true;
|
|
195
|
+
for (const [event, group] of this.#events)
|
|
196
|
+
if (group.unheard) {
|
|
197
|
+
group.unheard = false;
|
|
198
|
+
this.#open(event, group);
|
|
199
|
+
}
|
|
174
200
|
}
|
|
175
201
|
/** Read the state copy kept by `event` again, if one exists; never rejects. */
|
|
176
202
|
async reread(event) {
|
|
@@ -275,12 +301,14 @@ export class Connection {
|
|
|
275
301
|
}
|
|
276
302
|
/**
|
|
277
303
|
* Host events with one `events.subscribe` per name, however many listeners.
|
|
278
|
-
*
|
|
304
|
+
* An event that needs delivery (`"events"`) is subscribed only once
|
|
305
|
+
* `plugin.player.subscribe()` was called; until then its listener simply
|
|
306
|
+
* never fires.
|
|
279
307
|
* `mirror`: the SDK's own copy of the state (`plugin.player.state` and
|
|
280
308
|
* the like), not a listener of the plugin's (see {@link EventGroup}).
|
|
281
309
|
*/
|
|
282
310
|
on(event, listener,
|
|
283
|
-
/**
|
|
311
|
+
/** `"events"`: it arrives after `plugin.player.subscribe()`; `null`: always. */
|
|
284
312
|
needs = "events", mirror = false) {
|
|
285
313
|
let entry = this.#events.get(event);
|
|
286
314
|
const created = !entry;
|
|
@@ -302,34 +330,12 @@ export class Connection {
|
|
|
302
330
|
group.active++;
|
|
303
331
|
group.whys.set(token, listenerWhy(this.callSite()));
|
|
304
332
|
}
|
|
305
|
-
if (created && needs === "events" && !this
|
|
333
|
+
if (created && needs === "events" && !this.#delivering)
|
|
306
334
|
group.unheard = true;
|
|
307
335
|
if (!mirror && group.unheard)
|
|
308
336
|
this.#warnUnheard(event);
|
|
309
|
-
if (created &&
|
|
310
|
-
|
|
311
|
-
const whys = group.told ? allWhys(group) : undefined;
|
|
312
|
-
group.toldWhy = whys?.join("\n");
|
|
313
|
-
group.off = this.host.events.subscribe(event, (data) => {
|
|
314
|
-
// Split once: the state copies first, each on its own (one that
|
|
315
|
-
// throws stops neither the others nor the plugin's listeners),
|
|
316
|
-
// then the plugin's listeners in order.
|
|
317
|
-
const mirrors = [];
|
|
318
|
-
const others = [];
|
|
319
|
-
for (const each of group.listeners)
|
|
320
|
-
(group.mirrors.has(each) ? mirrors : others).push(each);
|
|
321
|
-
for (const each of mirrors)
|
|
322
|
-
try {
|
|
323
|
-
each(data);
|
|
324
|
-
}
|
|
325
|
-
catch (error) {
|
|
326
|
-
this.reportMirror(error);
|
|
327
|
-
}
|
|
328
|
-
for (const each of others)
|
|
329
|
-
each(data);
|
|
330
|
-
}, !group.told, whys);
|
|
331
|
-
this.starting(group.off, (error) => console.error(`[${this.manifest.id}] subscribe ${event}:`, error));
|
|
332
|
-
}
|
|
337
|
+
if (created && !group.unheard)
|
|
338
|
+
this.#open(event, group);
|
|
333
339
|
else
|
|
334
340
|
this.#tell(event, group);
|
|
335
341
|
let listening = true;
|
|
@@ -353,10 +359,35 @@ export class Connection {
|
|
|
353
359
|
},
|
|
354
360
|
};
|
|
355
361
|
}
|
|
362
|
+
/** Subscribe `group` to `event` at the player, as it stands now. */
|
|
363
|
+
#open(event, group) {
|
|
364
|
+
group.told = group.active > 0;
|
|
365
|
+
const whys = group.told ? allWhys(group) : undefined;
|
|
366
|
+
group.toldWhy = whys?.join("\n");
|
|
367
|
+
group.off = this.host.events.subscribe(event, (data) => {
|
|
368
|
+
// Split once: the state copies first, each on its own (one that
|
|
369
|
+
// throws stops neither the others nor the plugin's listeners),
|
|
370
|
+
// then the plugin's listeners in order.
|
|
371
|
+
const mirrors = [];
|
|
372
|
+
const others = [];
|
|
373
|
+
for (const each of group.listeners)
|
|
374
|
+
(group.mirrors.has(each) ? mirrors : others).push(each);
|
|
375
|
+
for (const each of mirrors)
|
|
376
|
+
try {
|
|
377
|
+
each(data);
|
|
378
|
+
}
|
|
379
|
+
catch (error) {
|
|
380
|
+
this.reportMirror(error);
|
|
381
|
+
}
|
|
382
|
+
for (const each of others)
|
|
383
|
+
each(data);
|
|
384
|
+
}, !group.told, whys);
|
|
385
|
+
this.starting(group.off, (error) => console.error(`[${this.manifest.id}] subscribe ${event}:`, error));
|
|
386
|
+
}
|
|
356
387
|
/**
|
|
357
388
|
* Count `event` as listened to while held: a watcher of a service's
|
|
358
389
|
* state, a binding that reads it. Nothing when nothing subscribed to it
|
|
359
|
-
* (no
|
|
390
|
+
* (no `plugin.player.subscribe()`, or the service did not start).
|
|
360
391
|
*/
|
|
361
392
|
hold(event, why) {
|
|
362
393
|
const group = this.#events.get(event);
|
|
@@ -383,15 +414,16 @@ export class Connection {
|
|
|
383
414
|
}
|
|
384
415
|
/**
|
|
385
416
|
* A development warning, once per plugin, no behaviour change: the plugin
|
|
386
|
-
* follows `event` (an `onChange`, a `bind` that reads the
|
|
387
|
-
* `
|
|
388
|
-
* another plugin) never reach it; the state moves
|
|
417
|
+
* follows `event` (a listener, an `onChange`, a `bind` that reads the
|
|
418
|
+
* state) before `plugin.player.subscribe()`, so changes made elsewhere
|
|
419
|
+
* (the user, the player, another plugin) never reach it; the state moves
|
|
420
|
+
* only after its own calls.
|
|
389
421
|
*/
|
|
390
422
|
#warnUnheard(event) {
|
|
391
423
|
if (this.#warnedEvents)
|
|
392
424
|
return;
|
|
393
425
|
this.#warnedEvents = true;
|
|
394
|
-
console.warn(`[${this.manifest.id}] follows ${event} (onChange, or a bind() that reads the state)
|
|
426
|
+
console.warn(`[${this.manifest.id}] follows ${event} (a listener, onChange, or a bind() that reads the state) before plugin.player.subscribe(): changes made elsewhere will not reach it, only its own calls refresh the state. Call plugin.player.subscribe() first in activate().`);
|
|
395
427
|
}
|
|
396
428
|
/**
|
|
397
429
|
* Tell the player when `group` changes between mirror and listener, and
|
|
@@ -430,7 +462,7 @@ export class Connection {
|
|
|
430
462
|
}
|
|
431
463
|
/**
|
|
432
464
|
* One request by its method name, as given (`plugin.wire.request`): nothing
|
|
433
|
-
* added, nothing checked here
|
|
465
|
+
* added, nothing checked here; the player checks the request. Every other
|
|
434
466
|
* part of the SDK uses the typed clients (`host`); `scripts/check-layers.mjs`
|
|
435
467
|
* keeps it so. It waits in the request queue like every other.
|
|
436
468
|
*/
|
package/dist/plugin/drops.js
CHANGED
package/dist/plugin/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import { Runtime } from "./runtime.js";
|
|
|
2
2
|
import { stopReason } from "./connection.js";
|
|
3
3
|
import { failure } from "./errors.js";
|
|
4
4
|
import { ScopeImpl } from "./scope.js";
|
|
5
|
-
import { playerOf } from "./player.js";
|
|
6
5
|
import { windowOf } from "./window.js";
|
|
7
6
|
import { timelineOf } from "./timeline.js";
|
|
8
7
|
export async function createPlugin(transport, manifest, directory, dataDirectory,
|
|
@@ -11,20 +10,15 @@ app,
|
|
|
11
10
|
/** `TestHost` sets `strictDeclarations`; the player's runner does not. */
|
|
12
11
|
options) {
|
|
13
12
|
const runtime = new Runtime(transport, manifest, directory, dataDirectory, app, options);
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
// subscribe on their first use.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
await Promise.all([
|
|
24
|
-
player.init(),
|
|
25
|
-
windowOf(runtime).init(),
|
|
26
|
-
timelineOf(runtime).init(),
|
|
27
|
-
]);
|
|
13
|
+
// The window state is synchronous for plugins: read it first. The
|
|
14
|
+
// player's state and the timeline are the plugin's explicit calls, first
|
|
15
|
+
// in `activate`: `plugin.player.subscribe()` (event delivery, the copy
|
|
16
|
+
// of the player's state follows from then on) and
|
|
17
|
+
// `await plugin.player.read()` (state and timeline read once). Window and
|
|
18
|
+
// timeline subscribe on their first use. The timeline's copy exists from
|
|
19
|
+
// the start: it tells the connection how `read()` reads the lists.
|
|
20
|
+
timelineOf(runtime);
|
|
21
|
+
await windowOf(runtime).init();
|
|
28
22
|
const root = new ScopeImpl(runtime);
|
|
29
23
|
// A runaway of the update passes goes to the plugin's error handlers.
|
|
30
24
|
runtime.passes.report = (error) => root.report(error);
|
package/dist/plugin/media.js
CHANGED
|
@@ -324,7 +324,6 @@ export function mediaCapture(scope) {
|
|
|
324
324
|
const service = serviceOf(runtime);
|
|
325
325
|
if (typeof options !== "object" || options === null)
|
|
326
326
|
throw failure("invalid", "export options must be an object");
|
|
327
|
-
needSources(scope);
|
|
328
327
|
const parts = checkParts(options.parts);
|
|
329
328
|
let mode;
|
|
330
329
|
if (options.format === "copy") {
|
|
@@ -377,7 +376,6 @@ export function mediaCapture(scope) {
|
|
|
377
376
|
// As the player: parts carry their own ends; `end` is a snapshot's.
|
|
378
377
|
if (options?.end !== undefined)
|
|
379
378
|
throw failure("invalid", "end belongs to a snapshot's check; parts carry their own end");
|
|
380
|
-
needSources(scope);
|
|
381
379
|
return scope.runtime.host.jobs.check(checkParts(input), encoding);
|
|
382
380
|
},
|
|
383
381
|
};
|
|
@@ -431,14 +429,8 @@ function checkParts(parts) {
|
|
|
431
429
|
throw failure("invalid", `the parts are ${total} s long; an export takes at most ${MEDIA_SOURCE_LIMITS.totalSeconds} s`);
|
|
432
430
|
return checked;
|
|
433
431
|
}
|
|
434
|
-
/** The parts' tokens are media.sources': refuse at once without it, as the player does. */
|
|
435
|
-
function needSources(scope) {
|
|
436
|
-
if (!scope.runtime.can("media.sources"))
|
|
437
|
-
throw failure("capability", "media.sources must be declared in manifest");
|
|
438
|
-
}
|
|
439
432
|
function mediaSources(scope) {
|
|
440
433
|
const host = () => {
|
|
441
|
-
needSources(scope);
|
|
442
434
|
return scope.runtime.host.mediaSources;
|
|
443
435
|
};
|
|
444
436
|
const token = (value) => {
|
|
@@ -459,10 +451,6 @@ function mediaSources(scope) {
|
|
|
459
451
|
forget: async (value) => host().forget(token(value)),
|
|
460
452
|
list: async () => host().list(),
|
|
461
453
|
async open(value, options = {}) {
|
|
462
|
-
needSources(scope);
|
|
463
|
-
// An open like Player.open's: the player asks playback.control too.
|
|
464
|
-
if (!scope.runtime.can("playback.control"))
|
|
465
|
-
throw failure("capability", "playback.control must be declared in manifest");
|
|
466
454
|
const start = options?.start;
|
|
467
455
|
if (start !== undefined && !(Number.isFinite(start) && start >= 0))
|
|
468
456
|
throw failure("invalid", "start must be seconds from 0");
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `plugin.mpv`: the mpv pass-through (L1). The checks here are the
|
|
3
|
+
* player's own, made early with the same table (`src/mpv.ts`); what only
|
|
4
|
+
* the player can tell (another plugin's label, mpv's answer) is its.
|
|
5
|
+
*/
|
|
6
|
+
import { mpvCommandProblem, mpvCommandRefusal, mpvNameProblem, mpvPropertyRefusal, } from "../mpv.js";
|
|
7
|
+
import { failure } from "./errors.js";
|
|
8
|
+
/** One per plugin: the properties observed and their listeners. */
|
|
9
|
+
class Observers {
|
|
10
|
+
#runtime;
|
|
11
|
+
#names = new Map();
|
|
12
|
+
#started = false;
|
|
13
|
+
constructor(runtime) {
|
|
14
|
+
this.#runtime = runtime;
|
|
15
|
+
}
|
|
16
|
+
/** One `mpv.observe` per name, however many listeners. */
|
|
17
|
+
add(name, listener, report) {
|
|
18
|
+
if (!this.#started) {
|
|
19
|
+
this.#started = true;
|
|
20
|
+
// Sent to the plugin that observes: no subscription of its own.
|
|
21
|
+
this.#runtime.raw("mpv.property", (data) => {
|
|
22
|
+
const event = data;
|
|
23
|
+
for (const each of [...(this.#names.get(event.name) ?? [])])
|
|
24
|
+
each(event.value);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
let listeners = this.#names.get(name);
|
|
28
|
+
if (!listeners) {
|
|
29
|
+
listeners = new Set();
|
|
30
|
+
this.#names.set(name, listeners);
|
|
31
|
+
this.#runtime.starting(this.#runtime.host.mpv.observeProperty(name), report);
|
|
32
|
+
}
|
|
33
|
+
listeners.add(listener);
|
|
34
|
+
}
|
|
35
|
+
async remove(name, listener) {
|
|
36
|
+
const listeners = this.#names.get(name);
|
|
37
|
+
if (!listeners?.delete(listener) || listeners.size)
|
|
38
|
+
return;
|
|
39
|
+
this.#names.delete(name);
|
|
40
|
+
await this.#runtime.host.mpv.unobserveProperty(name).catch(() => { });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export const mpv = (scope) => {
|
|
44
|
+
const named = (name, write) => {
|
|
45
|
+
const problem = mpvNameProblem(name);
|
|
46
|
+
if (problem)
|
|
47
|
+
throw failure("invalid", problem);
|
|
48
|
+
const refused = mpvPropertyRefusal(name, write);
|
|
49
|
+
if (refused)
|
|
50
|
+
throw failure("refused", refused);
|
|
51
|
+
return name;
|
|
52
|
+
};
|
|
53
|
+
const observers = () => scope.runtime.service("mpv.observers", () => new Observers(scope.runtime));
|
|
54
|
+
return {
|
|
55
|
+
async command(args) {
|
|
56
|
+
const problem = mpvCommandProblem(args);
|
|
57
|
+
if (problem)
|
|
58
|
+
throw failure("invalid", problem);
|
|
59
|
+
const refused = mpvCommandRefusal(args);
|
|
60
|
+
if (refused)
|
|
61
|
+
throw failure("refused", refused);
|
|
62
|
+
const answer = await scope.runtime.host.mpv.command([...args]);
|
|
63
|
+
return (answer?.result ?? null);
|
|
64
|
+
},
|
|
65
|
+
async get(name) {
|
|
66
|
+
const answer = await scope.runtime.host.mpv.get(named(name, false));
|
|
67
|
+
return (answer?.value ?? null);
|
|
68
|
+
},
|
|
69
|
+
async set(name, value) {
|
|
70
|
+
const property = named(name, true);
|
|
71
|
+
if (value === undefined)
|
|
72
|
+
throw failure("invalid", "set takes a value");
|
|
73
|
+
await scope.runtime.host.mpv.set(property, value);
|
|
74
|
+
},
|
|
75
|
+
observe(name, listener) {
|
|
76
|
+
const property = named(name, false);
|
|
77
|
+
if (typeof listener !== "function")
|
|
78
|
+
throw failure("invalid", "observe takes a property name and a listener");
|
|
79
|
+
// Like `player.on`: no full update pass after it.
|
|
80
|
+
const deliver = (value) => scope.runQuiet(listener, value);
|
|
81
|
+
observers().add(property, deliver, (error) => scope.report(error));
|
|
82
|
+
const handle = {
|
|
83
|
+
dispose: async () => {
|
|
84
|
+
scope.forget(handle);
|
|
85
|
+
await observers().remove(property, deliver);
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
return scope.add(handle);
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
};
|
package/dist/plugin/packages.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Package validation, install and uninstall
|
|
1
|
+
/** Package validation, install and uninstall. */
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { failure, sleep, uncertain } from "./errors.js";
|
|
@@ -159,7 +159,6 @@ const info = (plugin) => Object.freeze({
|
|
|
159
159
|
origin: plugin.origin,
|
|
160
160
|
state: plugin.state,
|
|
161
161
|
error: plugin.error,
|
|
162
|
-
capabilities: [...plugin.capabilities],
|
|
163
162
|
directory: plugin.directory,
|
|
164
163
|
builtin: plugin.builtin === true,
|
|
165
164
|
source: plugin.source ? Object.freeze({ ...plugin.source }) : null,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { ScopeImpl } from "../scope.ts";
|
|
2
2
|
import type { Disposable, EventPayload, HostEvent } from "../types.ts";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* (
|
|
4
|
+
* Which events need event delivery (`"events"`: they reach the plugin only
|
|
5
|
+
* after `plugin.player.subscribe()`, as they needed the `events`
|
|
6
|
+
* declaration before 1.9.0); `null`: they arrive from the first listener.
|
|
6
7
|
*/
|
|
7
|
-
export declare const EVENT_NEEDS: Readonly<Record<HostEvent,
|
|
8
|
+
export declare const EVENT_NEEDS: Readonly<Record<HostEvent, "events" | null>>;
|
|
8
9
|
/** `Player.on`'s arguments: a {@link HostEvent} name and a function. */
|
|
9
10
|
export declare function checkOn(event: unknown, listener: unknown): asserts event is HostEvent;
|
|
10
11
|
/** `Player.on`: `listener` hears each `event`, with a copy of its data. */
|
|
@@ -7,21 +7,22 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { failure } from "../errors.js";
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
* (
|
|
10
|
+
* Which events need event delivery (`"events"`: they reach the plugin only
|
|
11
|
+
* after `plugin.player.subscribe()`, as they needed the `events`
|
|
12
|
+
* declaration before 1.9.0); `null`: they arrive from the first listener.
|
|
12
13
|
*/
|
|
13
14
|
export const EVENT_NEEDS = {
|
|
14
15
|
"source.state": "events",
|
|
15
16
|
"playback.backend": "events",
|
|
16
17
|
"window.state": "events",
|
|
17
18
|
"packages.changed": null,
|
|
18
|
-
"bindings.changed":
|
|
19
|
-
"commands.keys":
|
|
19
|
+
"bindings.changed": null,
|
|
20
|
+
"commands.keys": null,
|
|
20
21
|
"timeline.changed": "events",
|
|
21
22
|
"appearance.changed": "events",
|
|
22
23
|
"resolvers.fileTypes": "events",
|
|
23
|
-
"video.upscaling.changed":
|
|
24
|
-
"video.motion.changed":
|
|
24
|
+
"video.upscaling.changed": null,
|
|
25
|
+
"video.motion.changed": null,
|
|
25
26
|
};
|
|
26
27
|
/** `Player.on`'s arguments: a {@link HostEvent} name and a function. */
|
|
27
28
|
export function checkOn(event, listener) {
|
package/dist/plugin/player.d.ts
CHANGED
|
@@ -17,14 +17,13 @@ export declare const sameStamp: (a: SourceStamp, b: SourceStamp) => boolean;
|
|
|
17
17
|
* One per plugin: the state store and the operation book client.
|
|
18
18
|
*
|
|
19
19
|
* The state copy (a mirror of `source.state`) follows the player's events
|
|
20
|
-
* from
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* arrive; `start` is then called by the first use of the state (a read of
|
|
20
|
+
* from `plugin.player.subscribe()` on (`subscribe`, first in `activate`
|
|
21
|
+
* as the plugin writes it). Before that no event can arrive; `start` is
|
|
22
|
+
* then called by the first use of the state (a read of
|
|
24
23
|
* `plugin.player.state`, `onChange`, `isCurrent`, a media handle, a
|
|
25
24
|
* scrub, a stream, a filter, a shader or view request, a capture) and
|
|
26
|
-
* subscribes nothing
|
|
27
|
-
*
|
|
25
|
+
* subscribes nothing until `subscribe()`, which subscribes it and, after
|
|
26
|
+
* `read()`, reads the state once more (`#catchUp`).
|
|
28
27
|
*/
|
|
29
28
|
export declare class PlayerService implements StreamSource {
|
|
30
29
|
#private;
|
|
@@ -41,19 +40,28 @@ export declare class PlayerService implements StreamSource {
|
|
|
41
40
|
muted?: boolean;
|
|
42
41
|
}>;
|
|
43
42
|
constructor(runtime: Runtime);
|
|
44
|
-
|
|
43
|
+
/**
|
|
44
|
+
* `plugin.player.read()`: read the source state and the timeline now, and
|
|
45
|
+
* from now on read the state again after the plugin's own actions
|
|
46
|
+
* (`Connection.reads`). Idempotent: one read, however often it is called;
|
|
47
|
+
* a read that failed is tried again by the next call.
|
|
48
|
+
*/
|
|
49
|
+
read(): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* `plugin.player.subscribe()`: turn event delivery on and follow
|
|
52
|
+
* `source.state` now. Idempotent.
|
|
53
|
+
*/
|
|
54
|
+
subscribe(): void;
|
|
45
55
|
/** Whether the mirror follows the player's events yet. */
|
|
46
56
|
get started(): boolean;
|
|
47
57
|
/**
|
|
48
58
|
* Follow `source.state` from now on: the SDK's copy of the state (a
|
|
49
59
|
* mirror; a plugin listens through `watch` and the bindings that read
|
|
50
|
-
* `state`). Then read the state once more (
|
|
51
|
-
* `
|
|
52
|
-
*
|
|
53
|
-
* `reread: false`: subscribed before the start-up read
|
|
54
|
-
* (`createPlugin`), which then is that read.
|
|
60
|
+
* `state`). Then read the state once more (after `read()` and
|
|
61
|
+
* `subscribe()`): a change between that read and the subscription sent
|
|
62
|
+
* no event to this plugin. Resolves when that read is in.
|
|
55
63
|
*/
|
|
56
|
-
start(
|
|
64
|
+
start(): Promise<void>;
|
|
57
65
|
/** The state as the player has it now, for a call that needs a source. */
|
|
58
66
|
current(): Promise<PlayerState>;
|
|
59
67
|
/** Drop anything older than what was already delivered. */
|