@vestra-player/sdk 1.10.0 → 1.11.0-rc.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 +36 -0
- package/bin/vestra-plugin.mjs +1 -131
- package/dist/api-requests.d.ts +1 -1
- package/dist/api-requests.js +10 -2
- package/dist/commands.js +1 -0
- package/dist/docs-tree.json.gz +0 -0
- package/dist/manifest.d.ts +0 -5
- package/dist/manifest.js +1 -8
- package/dist/mpv.js +1 -1
- package/dist/plugin/appearance.d.ts +2 -2
- package/dist/plugin/appearance.js +3 -3
- package/dist/plugin/connection.d.ts +39 -29
- package/dist/plugin/connection.js +110 -101
- package/dist/plugin/index.js +8 -6
- package/dist/plugin/passes.js +1 -1
- package/dist/plugin/player/events.d.ts +18 -9
- package/dist/plugin/player/events.js +36 -11
- package/dist/plugin/player.d.ts +31 -28
- package/dist/plugin/player.js +42 -68
- package/dist/plugin/scope.d.ts +2 -9
- package/dist/plugin/scope.js +21 -27
- package/dist/plugin/subtitles.d.ts +6 -1
- package/dist/plugin/subtitles.js +18 -2
- package/dist/plugin/testing/commands.d.ts +5 -0
- package/dist/plugin/testing/commands.js +6 -3
- package/dist/plugin/testing/facts.d.ts +46 -0
- package/dist/plugin/testing/facts.js +106 -0
- package/dist/plugin/testing/index.d.ts +38 -13
- package/dist/plugin/testing/index.js +63 -17
- package/dist/plugin/testing/media.js +6 -0
- package/dist/plugin/testing/revoke.d.ts +15 -0
- package/dist/plugin/testing/revoke.js +13 -0
- package/dist/plugin/testing/services.js +50 -1
- package/dist/plugin/testing/transport.js +8 -0
- package/dist/plugin/timeline.d.ts +2 -2
- package/dist/plugin/timeline.js +3 -3
- package/dist/plugin/types/base.d.ts +91 -13
- package/dist/plugin/types/commands.d.ts +8 -8
- package/dist/plugin/types/packages.d.ts +10 -1
- package/dist/plugin/types/playback.d.ts +240 -116
- package/dist/plugin/types/plugin-wire.d.ts +2 -2
- package/dist/plugin/types/processing.d.ts +2 -3
- package/dist/plugin/types/services.d.ts +10 -4
- package/dist/plugin/types/subtitles.d.ts +9 -8
- package/dist/plugin/types/ui-layout.d.ts +32 -17
- package/dist/plugin/types/ui-locale.d.ts +9 -9
- package/dist/plugin/types/ui-shell.d.ts +7 -6
- package/dist/plugin/view/layout.d.ts +33 -1
- package/dist/plugin/view/layout.js +63 -34
- package/dist/plugin/window.d.ts +9 -1
- package/dist/plugin/window.js +14 -2
- package/dist/processing.d.ts +2 -2
- package/dist/request-queue.d.ts +7 -3
- package/dist/request-queue.js +19 -5
- package/dist/ts-plugin.d.ts +3 -4
- package/dist/ts-plugin.js +1 -1
- package/dist/wire.d.ts +4 -1
- package/dist/wire.js +2 -1
- package/llms.txt +3 -3
- package/package.json +3 -5
- package/capability-scan.json +0 -387
- package/dist/capability-scan.d.ts +0 -95
- package/dist/capability-scan.js +0 -249
- package/dist/member-uses.d.ts +0 -61
- package/dist/member-uses.js +0 -160
package/dist/plugin/player.js
CHANGED
|
@@ -6,7 +6,7 @@ import { HostError } from "../wire.js";
|
|
|
6
6
|
import { Latest } from "./latest.js";
|
|
7
7
|
import { abortError, failure, quiet, sleep, uncertain } from "./errors.js";
|
|
8
8
|
import { openStream, resolvedStream } from "./stream.js";
|
|
9
|
-
import { SOURCE_EVENTS, checkOn, playerOn } from "./player/events.js";
|
|
9
|
+
import { FACT_EVENTS, SOURCE_EVENTS, checkOn, playerOn, } from "./player/events.js";
|
|
10
10
|
import { validStep } from "./player/rules.js";
|
|
11
11
|
const raws = new WeakMap();
|
|
12
12
|
const empty = {
|
|
@@ -156,30 +156,23 @@ function sourceFailure(error) {
|
|
|
156
156
|
/**
|
|
157
157
|
* One per plugin: the state store and the operation book client.
|
|
158
158
|
*
|
|
159
|
-
* The state copy (a mirror of `source.state`)
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
* `
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
159
|
+
* The state copy (a mirror of `source.state`) is started by the first use
|
|
160
|
+
* of the state (a read of `plugin.player.state`, `isCurrent`, a media
|
|
161
|
+
* handle, a scrub, a stream, a filter, a shader or view request, a
|
|
162
|
+
* capture). It follows the player's events only while something holds
|
|
163
|
+
* `source.state` (a stream, a `player.on` listener of it, a media
|
|
164
|
+
* handle's `ready` or `onEnd`, a scrub; `Connection.hold`); otherwise it
|
|
165
|
+
* is the newest snapshot the plugin has: its start-up read, its own calls
|
|
166
|
+
* and the state a source event carries.
|
|
167
167
|
*/
|
|
168
168
|
export class PlayerService {
|
|
169
169
|
runtime;
|
|
170
170
|
raw = empty;
|
|
171
171
|
state;
|
|
172
|
-
/**
|
|
173
|
-
* The fields the last accepted state changed (`onChange` listeners are
|
|
174
|
-
* told so a listener that read none of them needs no full pass).
|
|
175
|
-
*/
|
|
176
|
-
change = new Map();
|
|
177
172
|
#watchers = new Set();
|
|
178
173
|
#operation = 0;
|
|
179
|
-
/** The mirror
|
|
174
|
+
/** The mirror registered (`start`). */
|
|
180
175
|
#started = false;
|
|
181
|
-
/** The read that followed the subscription (resolved: none was needed). */
|
|
182
|
-
#fresh = Promise.resolve();
|
|
183
176
|
/** `read()`'s one read, once asked for. */
|
|
184
177
|
#read;
|
|
185
178
|
output;
|
|
@@ -218,44 +211,23 @@ export class PlayerService {
|
|
|
218
211
|
}
|
|
219
212
|
})());
|
|
220
213
|
}
|
|
221
|
-
/**
|
|
222
|
-
* `plugin.player.subscribe()`: turn event delivery on and follow
|
|
223
|
-
* `source.state` now. Idempotent.
|
|
224
|
-
*/
|
|
225
|
-
subscribe() {
|
|
226
|
-
if (this.runtime.delivering)
|
|
227
|
-
return;
|
|
228
|
-
this.runtime.deliver();
|
|
229
|
-
// A copy started on demand heard nothing so far; it is subscribed now,
|
|
230
|
-
// and a change before that sent no event.
|
|
231
|
-
if (this.#started)
|
|
232
|
-
this.#catchUp();
|
|
233
|
-
else
|
|
234
|
-
void this.start();
|
|
235
|
-
}
|
|
236
|
-
/** Whether the mirror follows the player's events yet. */
|
|
214
|
+
/** Whether the mirror is registered yet. */
|
|
237
215
|
get started() {
|
|
238
216
|
return this.#started;
|
|
239
217
|
}
|
|
240
218
|
/**
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
219
|
+
* Register the SDK's copy of the state (a mirror of `source.state`; a
|
|
220
|
+
* plugin listens through `watch`, `follow` and `player.on`). It hears
|
|
221
|
+
* the events while something holds the event (`Connection.hold`), which
|
|
222
|
+
* also reads the state once more after `read()` when the subscription
|
|
223
|
+
* starts. Resolves at once.
|
|
246
224
|
*/
|
|
247
225
|
start() {
|
|
248
226
|
if (this.#started)
|
|
249
|
-
return
|
|
227
|
+
return Promise.resolve();
|
|
250
228
|
this.#started = true;
|
|
251
|
-
this.runtime.on("source.state", (data) => this.accept(data), "
|
|
252
|
-
|
|
253
|
-
return this.#fresh;
|
|
254
|
-
}
|
|
255
|
-
/** Read the state once more after a subscription, when it is read at all. */
|
|
256
|
-
#catchUp() {
|
|
257
|
-
if (this.runtime.reads && this.runtime.delivering)
|
|
258
|
-
this.#fresh = this.refresh().then(() => { }, () => { });
|
|
229
|
+
this.runtime.on("source.state", (data) => this.accept(data), "held", true);
|
|
230
|
+
return Promise.resolve();
|
|
259
231
|
}
|
|
260
232
|
/** The state as the player has it now, for a call that needs a source. */
|
|
261
233
|
async current() {
|
|
@@ -273,7 +245,6 @@ export class PlayerService {
|
|
|
273
245
|
this.raw = raw;
|
|
274
246
|
this.state = view(raw, this.runtime);
|
|
275
247
|
const changed = changes(last, lastRaw, this.state, raw);
|
|
276
|
-
this.change = new Map([[PLAYER, new Set(changed)]]);
|
|
277
248
|
for (const watcher of [...this.#watchers])
|
|
278
249
|
watcher(raw);
|
|
279
250
|
// A precise pass: only the bindings that read a changed field.
|
|
@@ -294,10 +265,15 @@ export class PlayerService {
|
|
|
294
265
|
this.accept(message.state);
|
|
295
266
|
return { ...message, state: view(message.state) };
|
|
296
267
|
}
|
|
297
|
-
|
|
268
|
+
/**
|
|
269
|
+
* `watcher` hears each accepted state while the handle lives; it holds
|
|
270
|
+
* `source.state` (`Connection.hold`). `always`: the state is read once
|
|
271
|
+
* more when the subscription starts, also without `read()`.
|
|
272
|
+
*/
|
|
273
|
+
watch(watcher, always = false) {
|
|
298
274
|
void this.start();
|
|
299
275
|
this.#watchers.add(watcher);
|
|
300
|
-
const held = this.runtime.hold("source.state");
|
|
276
|
+
const held = this.runtime.hold("source.state", undefined, always);
|
|
301
277
|
return {
|
|
302
278
|
dispose: async () => {
|
|
303
279
|
this.#watchers.delete(watcher);
|
|
@@ -307,8 +283,8 @@ export class PlayerService {
|
|
|
307
283
|
}
|
|
308
284
|
/**
|
|
309
285
|
* `watch`, for `plugin.player.stream`: the copy hears `source.state` while
|
|
310
|
-
* the watcher is open,
|
|
311
|
-
*
|
|
286
|
+
* the watcher is open, and the plugin counts as listening to it
|
|
287
|
+
* (`Connection.follow`; the stream reads the state itself).
|
|
312
288
|
*/
|
|
313
289
|
follow(watcher, why) {
|
|
314
290
|
void this.start();
|
|
@@ -420,10 +396,8 @@ class MediaHandle {
|
|
|
420
396
|
ready(options = {}) {
|
|
421
397
|
const service = this.#service;
|
|
422
398
|
return new Promise((resolve, reject) => {
|
|
423
|
-
let poll;
|
|
424
399
|
const finish = (error) => {
|
|
425
400
|
watch.dispose();
|
|
426
|
-
clearInterval(poll);
|
|
427
401
|
options.signal?.removeEventListener("abort", abort);
|
|
428
402
|
if (error)
|
|
429
403
|
reject(error);
|
|
@@ -445,13 +419,13 @@ class MediaHandle {
|
|
|
445
419
|
finish(abortError());
|
|
446
420
|
void this.close().catch((error) => this.#scope.report(error));
|
|
447
421
|
};
|
|
448
|
-
|
|
422
|
+
// The watch holds `source.state`: the copy follows the player's
|
|
423
|
+
// events until it ends. A change before its subscription is in sent
|
|
424
|
+
// no event, so the state is read once more then (`always`).
|
|
425
|
+
const watch = service.watch(check, true);
|
|
449
426
|
if (options.signal?.aborted)
|
|
450
427
|
return abort();
|
|
451
428
|
options.signal?.addEventListener("abort", abort, { once: true });
|
|
452
|
-
// Without event delivery the state only moves when read.
|
|
453
|
-
if (!service.runtime.delivering)
|
|
454
|
-
poll = setInterval(() => void service.refresh().catch(() => { }), 100);
|
|
455
429
|
check();
|
|
456
430
|
});
|
|
457
431
|
}
|
|
@@ -620,6 +594,14 @@ function provideSequence(scope, provider) {
|
|
|
620
594
|
runtime.services.set("sequence.provider", handle);
|
|
621
595
|
return scope.add(handle);
|
|
622
596
|
}
|
|
597
|
+
/**
|
|
598
|
+
* `audio.tracks.changed`'s data as the listener gets it (`ScopeImpl.fact`,
|
|
599
|
+
* SDK 1.11.0): the tracks as {@link PlayerState.audioTracks} lists them.
|
|
600
|
+
*/
|
|
601
|
+
export function audioTracksChanged(data) {
|
|
602
|
+
const { sourceId, audioTracks } = data;
|
|
603
|
+
return { sourceId, audioTracks: audioTracks.map(audioTrack) };
|
|
604
|
+
}
|
|
623
605
|
export const playerOf = (runtime) => runtime.service("player", () => new PlayerService(runtime));
|
|
624
606
|
/**
|
|
625
607
|
* The player's source as a stream needs it (`stream.ts`, L1): a stream
|
|
@@ -641,15 +623,6 @@ export function player(scope) {
|
|
|
641
623
|
scope.runtime.depends(PLAYER);
|
|
642
624
|
return service().state;
|
|
643
625
|
},
|
|
644
|
-
onChange(listener) {
|
|
645
|
-
const watch = service().watch(() => scope.runOn(service().change, listener, service().state));
|
|
646
|
-
return scope.add({
|
|
647
|
-
dispose: async () => {
|
|
648
|
-
scope.forget(watch);
|
|
649
|
-
await watch.dispose();
|
|
650
|
-
},
|
|
651
|
-
});
|
|
652
|
-
},
|
|
653
626
|
stream(listener) {
|
|
654
627
|
if (typeof listener !== "function")
|
|
655
628
|
throw failure("invalid", "stream takes a function");
|
|
@@ -693,7 +666,6 @@ export function player(scope) {
|
|
|
693
666
|
});
|
|
694
667
|
},
|
|
695
668
|
refresh: () => service().refresh(),
|
|
696
|
-
subscribe: () => service().subscribe(),
|
|
697
669
|
read: () => service().read(),
|
|
698
670
|
on(event, listener) {
|
|
699
671
|
// Checked first; the copy then starts before the listener subscribes
|
|
@@ -702,6 +674,8 @@ export function player(scope) {
|
|
|
702
674
|
scope.followCopy(event);
|
|
703
675
|
if (SOURCE_EVENTS.has(event))
|
|
704
676
|
return playerOn(scope, event, listener, (data) => service().sourceEvent(event, data));
|
|
677
|
+
if (FACT_EVENTS.has(event))
|
|
678
|
+
return playerOn(scope, event, listener, (data) => scope.fact(event, data));
|
|
705
679
|
return playerOn(scope, event, listener);
|
|
706
680
|
},
|
|
707
681
|
isCurrent(state) {
|
package/dist/plugin/scope.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/** Scopes own handles. Disposal runs newest first and never throws. */
|
|
2
2
|
import type { MotionEngine } from "./types.ts";
|
|
3
|
-
import type { Change } from "./passes.ts";
|
|
4
3
|
import type { Runtime } from "./runtime.ts";
|
|
5
4
|
import type { Disposable, DisposeInfo, Plugin, PluginError, Scope, StopReason, Trigger } from "./types.ts";
|
|
6
5
|
export declare class ScopeImpl implements Plugin {
|
|
@@ -19,6 +18,8 @@ export declare class ScopeImpl implements Plugin {
|
|
|
19
18
|
* an event without one.
|
|
20
19
|
*/
|
|
21
20
|
followCopy(event: string): void;
|
|
21
|
+
/** A fact event's data as `player.on`'s listener gets it ({@link FACTS}). */
|
|
22
|
+
fact(event: string, data: unknown): unknown;
|
|
22
23
|
readonly commands: import("./types.ts").Commands;
|
|
23
24
|
readonly when: import("./types.ts").When;
|
|
24
25
|
readonly windows: import("./types.ts").Windows;
|
|
@@ -71,14 +72,6 @@ export declare class ScopeImpl implements Plugin {
|
|
|
71
72
|
report(error: unknown): void;
|
|
72
73
|
/** Invoke plugin code on its behalf: report failures, then refresh bindings. */
|
|
73
74
|
run(handler: (...args: never[]) => unknown, ...args: unknown[]): void;
|
|
74
|
-
/**
|
|
75
|
-
* Run a listener of a state change (`player.onChange`) like `run`, except
|
|
76
|
-
* that the full pass after it is left out when it returned synchronously
|
|
77
|
-
* and read only fields of the state that `change` left alone: its result
|
|
78
|
-
* then depends on nothing new. The precise pass for the change runs
|
|
79
|
-
* anyway, and a full pass follows within `SAFETY_PASS_MS`.
|
|
80
|
-
*/
|
|
81
|
-
runOn(change: Change, handler: (...args: never[]) => unknown, ...args: unknown[]): void;
|
|
82
75
|
/**
|
|
83
76
|
* Run a listener that pushes its own values (`player.on`) like `run`, except
|
|
84
77
|
* that no full pass follows it: what it writes to `plugin.state` runs the
|
package/dist/plugin/scope.js
CHANGED
|
@@ -5,22 +5,23 @@ import { WHEN } from "./when.js";
|
|
|
5
5
|
import { dialogs } from "./services/dialogs.js";
|
|
6
6
|
import { ui } from "./view/image.js";
|
|
7
7
|
import { panels } from "./view/panel.js";
|
|
8
|
+
import { layoutChanged } from "./view/layout.js";
|
|
8
9
|
import { windows } from "./view/window.js";
|
|
9
10
|
import { timeline, timelineOf } from "./timeline.js";
|
|
10
11
|
import { drops } from "./drops.js";
|
|
11
12
|
import { appearance, appearanceOf } from "./appearance.js";
|
|
12
13
|
import { settings } from "./settings.js";
|
|
13
14
|
import { i18n } from "./language.js";
|
|
14
|
-
import { player } from "./player.js";
|
|
15
|
+
import { audioTracksChanged, player } from "./player.js";
|
|
15
16
|
import { audioFilters, videoFilters } from "./filters.js";
|
|
16
17
|
import { videoRender, videoView } from "./view.js";
|
|
17
18
|
import { videoShaders } from "./shaders.js";
|
|
18
|
-
import { subtitles } from "./subtitles.js";
|
|
19
|
+
import { subtitles, subtitlesChanged } from "./subtitles.js";
|
|
19
20
|
import { mediaCapture } from "./media.js";
|
|
20
21
|
import { resolvers } from "./resolvers.js";
|
|
21
22
|
import { packages } from "./packages.js";
|
|
22
23
|
import { osd } from "./osd.js";
|
|
23
|
-
import { mainWindow } from "./window.js";
|
|
24
|
+
import { mainWindow, windowChanged } from "./window.js";
|
|
24
25
|
import { bindingsApi } from "./bindings.js";
|
|
25
26
|
import { trackedState } from "./state.js";
|
|
26
27
|
import { wire } from "./wire-facade.js";
|
|
@@ -36,6 +37,17 @@ const COPIES = {
|
|
|
36
37
|
"timeline.changed": (runtime) => timelineOf(runtime).start(),
|
|
37
38
|
"appearance.changed": (runtime) => appearanceOf(runtime).start(),
|
|
38
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* The fact events (SDK 1.11.0) whose data the listener gets in the SDK's
|
|
42
|
+
* shape, each taken into the copy it concerns first; the others reach it
|
|
43
|
+
* as the player sent them.
|
|
44
|
+
*/
|
|
45
|
+
const FACTS = {
|
|
46
|
+
"audio.tracks.changed": (_, data) => audioTracksChanged(data),
|
|
47
|
+
"subtitles.changed": subtitlesChanged,
|
|
48
|
+
"window.changed": windowChanged,
|
|
49
|
+
"layout.changed": layoutChanged,
|
|
50
|
+
};
|
|
39
51
|
export class ScopeImpl {
|
|
40
52
|
runtime;
|
|
41
53
|
#parent;
|
|
@@ -74,6 +86,12 @@ export class ScopeImpl {
|
|
|
74
86
|
if (Object.hasOwn(COPIES, event))
|
|
75
87
|
COPIES[event](this.runtime);
|
|
76
88
|
}
|
|
89
|
+
/** A fact event's data as `player.on`'s listener gets it ({@link FACTS}). */
|
|
90
|
+
fact(event, data) {
|
|
91
|
+
return Object.hasOwn(FACTS, event)
|
|
92
|
+
? FACTS[event](this.runtime, data)
|
|
93
|
+
: data;
|
|
94
|
+
}
|
|
77
95
|
commands = commands(this);
|
|
78
96
|
when = WHEN;
|
|
79
97
|
windows = windows(this);
|
|
@@ -189,30 +207,6 @@ export class ScopeImpl {
|
|
|
189
207
|
}
|
|
190
208
|
this.update();
|
|
191
209
|
}
|
|
192
|
-
/**
|
|
193
|
-
* Run a listener of a state change (`player.onChange`) like `run`, except
|
|
194
|
-
* that the full pass after it is left out when it returned synchronously
|
|
195
|
-
* and read only fields of the state that `change` left alone: its result
|
|
196
|
-
* then depends on nothing new. The precise pass for the change runs
|
|
197
|
-
* anyway, and a full pass follows within `SAFETY_PASS_MS`.
|
|
198
|
-
*/
|
|
199
|
-
runOn(change, handler, ...args) {
|
|
200
|
-
if (this.disposed)
|
|
201
|
-
return;
|
|
202
|
-
let full = true;
|
|
203
|
-
try {
|
|
204
|
-
const { value, deps } = this.runtime.observe(() => handler(...args));
|
|
205
|
-
if (value instanceof Promise)
|
|
206
|
-
value.catch((error) => this.report(error)).finally(() => this.update());
|
|
207
|
-
else
|
|
208
|
-
full = this.runtime.needsFull(deps, change);
|
|
209
|
-
}
|
|
210
|
-
catch (error) {
|
|
211
|
-
this.report(error);
|
|
212
|
-
}
|
|
213
|
-
if (full)
|
|
214
|
-
this.update();
|
|
215
|
-
}
|
|
216
210
|
/**
|
|
217
211
|
* Run a listener that pushes its own values (`player.on`) like `run`, except
|
|
218
212
|
* that no full pass follows it: what it writes to `plugin.state` runs the
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { Runtime } from "./runtime.ts";
|
|
1
2
|
import type { ScopeImpl } from "./scope.ts";
|
|
2
|
-
import type { Subtitles } from "./types.ts";
|
|
3
|
+
import type { Subtitles, SubtitlesState } from "./types.ts";
|
|
3
4
|
/**
|
|
4
5
|
* The player's limits on subtitle files a plugin loads with
|
|
5
6
|
* {@link Subtitles.load}, which `TestHost` enforces with the player's codes.
|
|
@@ -59,4 +60,8 @@ export declare const SUBTITLE_LIMITS: Readonly<{
|
|
|
59
60
|
/** Loads of every plugin in progress at the same time (8). */
|
|
60
61
|
readonly uploads: 8;
|
|
61
62
|
}>;
|
|
63
|
+
/** `subtitles.changed`'s data as the listener gets it (`ScopeImpl.fact`). */
|
|
64
|
+
export declare function subtitlesChanged(runtime: Runtime, data: unknown): {
|
|
65
|
+
state: SubtitlesState;
|
|
66
|
+
};
|
|
62
67
|
export declare function subtitles(scope: ScopeImpl): Subtitles;
|
package/dist/plugin/subtitles.js
CHANGED
|
@@ -95,8 +95,8 @@ class SubtitleService {
|
|
|
95
95
|
return;
|
|
96
96
|
this.#source = source;
|
|
97
97
|
void this.refresh().catch(() => { });
|
|
98
|
-
}, "
|
|
99
|
-
runtime.on("playback.backend", () => void this.refresh().catch(() => { }), "
|
|
98
|
+
}, "held", true);
|
|
99
|
+
runtime.on("playback.backend", () => void this.refresh().catch(() => { }), "held", true);
|
|
100
100
|
this.style = new Latest(async ({ style, options }) => {
|
|
101
101
|
const expected = await this.expected(options);
|
|
102
102
|
await this.#mutate(++this.#operation, (operationId) => runtime.host.subtitles.style({
|
|
@@ -148,6 +148,17 @@ class SubtitleService {
|
|
|
148
148
|
watcher();
|
|
149
149
|
this.#runtime.invalidate();
|
|
150
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* `subtitles.changed`'s state (SDK 1.11.0): taken into the copy when it
|
|
153
|
+
* is newer, and handed to the listener as a {@link SubtitlesState} (the
|
|
154
|
+
* copy's own when it holds the same state, so it works as `ifCurrent`).
|
|
155
|
+
*/
|
|
156
|
+
event(raw) {
|
|
157
|
+
this.accept(raw);
|
|
158
|
+
return this.state && JSON.stringify(this.raw) === JSON.stringify(raw)
|
|
159
|
+
? this.state
|
|
160
|
+
: this.#view(raw);
|
|
161
|
+
}
|
|
151
162
|
#view(raw) {
|
|
152
163
|
const tracks = raw.tracks.map((track) => {
|
|
153
164
|
const info = Object.freeze({
|
|
@@ -264,6 +275,11 @@ function target(track) {
|
|
|
264
275
|
throw failure("invalid", "unknown subtitle track");
|
|
265
276
|
return found;
|
|
266
277
|
}
|
|
278
|
+
/** `subtitles.changed`'s data as the listener gets it (`ScopeImpl.fact`). */
|
|
279
|
+
export function subtitlesChanged(runtime, data) {
|
|
280
|
+
const { state } = data;
|
|
281
|
+
return { state: serviceOf(runtime).event(state) };
|
|
282
|
+
}
|
|
267
283
|
export function subtitles(scope) {
|
|
268
284
|
const service = () => serviceOf(scope.runtime);
|
|
269
285
|
const host = () => scope.runtime.host.subtitles;
|
|
@@ -67,6 +67,11 @@ export declare function press(host: TestHost, inner: Internals, binding: string,
|
|
|
67
67
|
export declare function barButtons(host: TestHost, _inner: Internals): readonly FakeBarButton[];
|
|
68
68
|
/** The default handlers of this area's wire methods, by method name. */
|
|
69
69
|
export declare function commandsHandlers(host: TestHost, inner: Internals): Record<string, Handler>;
|
|
70
|
+
/**
|
|
71
|
+
* The player's refusal of a built-in-only request to any other plugin
|
|
72
|
+
* (also `app.openWindow`, ./services.ts).
|
|
73
|
+
*/
|
|
74
|
+
export declare function builtinOnly(host: TestHost): void;
|
|
70
75
|
/** The default handlers of `commands.run` and `palette.lead`. */
|
|
71
76
|
export declare function builtinHandlers(host: TestHost, inner: Internals): Record<string, Handler>;
|
|
72
77
|
/** Implements `TestHost.runPaletteLead`. */
|
|
@@ -419,10 +419,13 @@ export function commandsHandlers(host, inner) {
|
|
|
419
419
|
};
|
|
420
420
|
}
|
|
421
421
|
/// ---------------------------------------------------------------- built-in only: commands.run, palette.lead
|
|
422
|
-
/**
|
|
423
|
-
|
|
422
|
+
/**
|
|
423
|
+
* The player's refusal of a built-in-only request to any other plugin
|
|
424
|
+
* (also `app.openWindow`, ./services.ts).
|
|
425
|
+
*/
|
|
426
|
+
export function builtinOnly(host) {
|
|
424
427
|
if (!host.builtin)
|
|
425
|
-
throw new HostError("
|
|
428
|
+
throw new HostError("builtin-only", "this is for built-in plugins only");
|
|
426
429
|
}
|
|
427
430
|
/** The palette's rows: the player's core commands and the plugin's own. */
|
|
428
431
|
function rows(host) {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The second batch of events in the test host (SDK 1.11.0; the player's
|
|
3
|
+
* `src/host/src/fact_events.rs`): after the host's state changed, the
|
|
4
|
+
* facts that changed are sent once each, by the player's rules.
|
|
5
|
+
*
|
|
6
|
+
* - `audio.tracks.changed`: after a `source.state`, the source's audio
|
|
7
|
+
* track list when it is known and differs from the state before.
|
|
8
|
+
* - `window.changed`, `layout.changed`: after a `window.state`, when the
|
|
9
|
+
* window's state or the panel layout differ from what was last sent (the
|
|
10
|
+
* test host has no resize gesture: each change is one event).
|
|
11
|
+
* - `subtitles.changed`: when a loaded source's subtitle tracks or its
|
|
12
|
+
* primary or secondary selection differ from what was last sent.
|
|
13
|
+
* - `audio.devices.changed`: when the device list, the requested device or
|
|
14
|
+
* the device in use differ from what was last sent.
|
|
15
|
+
* - `video.reconfigured`, `audio.reconfigured`: when a source becomes
|
|
16
|
+
* ready, from `host.stats` (its `video` and `audio`), once per source.
|
|
17
|
+
*
|
|
18
|
+
* The first look at each is the start, not a change. `app.started` is not
|
|
19
|
+
* sent by itself: a test sends it with `host.emit("app.started", …)`.
|
|
20
|
+
*
|
|
21
|
+
* Internal to the SDK; not exported from `@vestra-player/sdk/testing`.
|
|
22
|
+
*/
|
|
23
|
+
import type { SourceState } from "../../source.ts";
|
|
24
|
+
import type { TestHost } from "./index.ts";
|
|
25
|
+
/** What was last sent of each fact, as JSON (`undefined`: not looked at yet). */
|
|
26
|
+
export interface FactsSent {
|
|
27
|
+
window?: string;
|
|
28
|
+
layout?: string;
|
|
29
|
+
subtitles?: string;
|
|
30
|
+
devices?: string;
|
|
31
|
+
/** The source the reconfigurations were sent for. */
|
|
32
|
+
reconfigured?: number;
|
|
33
|
+
/** Set while the facts are being sent (their own emits look at nothing). */
|
|
34
|
+
busy?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/** `audio.tracks.changed` for the `source.state` `next` after `previous` (the player's rule). */
|
|
37
|
+
export declare function tracksChanged(previous: SourceState, next: SourceState): {
|
|
38
|
+
sourceId: number;
|
|
39
|
+
audioTracks: import("../../source.ts").SourceAudioTrack[];
|
|
40
|
+
} | null;
|
|
41
|
+
/**
|
|
42
|
+
* After the host's state may have changed (a request answered, an event
|
|
43
|
+
* sent): send the facts that changed. `event` is the event just sent, if
|
|
44
|
+
* any.
|
|
45
|
+
*/
|
|
46
|
+
export declare function sendFacts(host: TestHost, event?: string): void;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
const sent = new WeakMap();
|
|
2
|
+
const of = (host) => {
|
|
3
|
+
let facts = sent.get(host);
|
|
4
|
+
if (!facts)
|
|
5
|
+
sent.set(host, (facts = {}));
|
|
6
|
+
return facts;
|
|
7
|
+
};
|
|
8
|
+
/** `data` when its JSON differs from `facts[key]` (set to it); the first look sends nothing. */
|
|
9
|
+
function changed(facts, key, data) {
|
|
10
|
+
const text = JSON.stringify(data);
|
|
11
|
+
const first = facts[key] === undefined;
|
|
12
|
+
if (facts[key] === text)
|
|
13
|
+
return false;
|
|
14
|
+
facts[key] = text;
|
|
15
|
+
return !first;
|
|
16
|
+
}
|
|
17
|
+
/** `audio.tracks.changed` for the `source.state` `next` after `previous` (the player's rule). */
|
|
18
|
+
export function tracksChanged(previous, next) {
|
|
19
|
+
if (!Array.isArray(next.audioTracks) || next.source === null)
|
|
20
|
+
return null;
|
|
21
|
+
if (previous.stamp.generation === next.stamp.generation &&
|
|
22
|
+
JSON.stringify(previous.audioTracks) === JSON.stringify(next.audioTracks))
|
|
23
|
+
return null;
|
|
24
|
+
return { sourceId: next.stamp.generation, audioTracks: next.audioTracks };
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* After the host's state may have changed (a request answered, an event
|
|
28
|
+
* sent): send the facts that changed. `event` is the event just sent, if
|
|
29
|
+
* any.
|
|
30
|
+
*/
|
|
31
|
+
export function sendFacts(host, event) {
|
|
32
|
+
const facts = of(host);
|
|
33
|
+
if (facts.busy)
|
|
34
|
+
return;
|
|
35
|
+
facts.busy = true;
|
|
36
|
+
try {
|
|
37
|
+
if (event === undefined || event === "window.state") {
|
|
38
|
+
const w = host.mainWindow;
|
|
39
|
+
const window = {
|
|
40
|
+
fullscreen: w.fullscreen,
|
|
41
|
+
maximized: w.maximized && !w.fullscreen,
|
|
42
|
+
videoArea: { ...w.videoArea },
|
|
43
|
+
pictureInPicture: { ...w.pictureInPicture },
|
|
44
|
+
};
|
|
45
|
+
if (changed(facts, "window", window))
|
|
46
|
+
host.emit("window.changed", window);
|
|
47
|
+
const layout = {
|
|
48
|
+
...host.layout,
|
|
49
|
+
backdrop: host.backdrop && {
|
|
50
|
+
owner: 1,
|
|
51
|
+
effective: host.backdrop.effective,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
if (changed(facts, "layout", layout))
|
|
55
|
+
host.emit("layout.changed", structuredClone(layout));
|
|
56
|
+
}
|
|
57
|
+
const subtitles = host.subtitles;
|
|
58
|
+
if (["ready", "ended"].includes(host.source.phase)) {
|
|
59
|
+
const part = {
|
|
60
|
+
source: host.source.stamp.generation,
|
|
61
|
+
tracks: subtitles.tracks,
|
|
62
|
+
target: subtitles.selection.target,
|
|
63
|
+
secondary: subtitles.selection.secondary ?? null,
|
|
64
|
+
};
|
|
65
|
+
// Sent for the first loaded source too, as the player does.
|
|
66
|
+
const text = JSON.stringify(part);
|
|
67
|
+
if (facts.subtitles !== text && (facts.subtitles = text))
|
|
68
|
+
host.emit("subtitles.changed", { state: structuredClone(subtitles) });
|
|
69
|
+
}
|
|
70
|
+
const output = host.source.audioOutput ?? { requested: null, active: null };
|
|
71
|
+
const devices = {
|
|
72
|
+
devices: host.audioDevices.map(({ id, name }) => ({ id, name })),
|
|
73
|
+
requested: output.requested,
|
|
74
|
+
active: output.active,
|
|
75
|
+
};
|
|
76
|
+
if (changed(facts, "devices", devices))
|
|
77
|
+
host.emit("audio.devices.changed", devices);
|
|
78
|
+
const source = host.source;
|
|
79
|
+
if (source.phase === "ready" &&
|
|
80
|
+
facts.reconfigured !== source.stamp.generation) {
|
|
81
|
+
facts.reconfigured = source.stamp.generation;
|
|
82
|
+
const { video, audio } = host.stats;
|
|
83
|
+
if (video?.width && video.height)
|
|
84
|
+
host.emit("video.reconfigured", {
|
|
85
|
+
sourceId: source.stamp.generation,
|
|
86
|
+
width: video.width,
|
|
87
|
+
height: video.height,
|
|
88
|
+
displayWidth: video.displayWidth ?? video.width,
|
|
89
|
+
displayHeight: video.displayHeight ?? video.height,
|
|
90
|
+
fps: video.fps,
|
|
91
|
+
rotation: 0,
|
|
92
|
+
hdr: video.transfer === "pq" || video.transfer === "hlg",
|
|
93
|
+
});
|
|
94
|
+
if (audio?.sampleRate)
|
|
95
|
+
host.emit("audio.reconfigured", {
|
|
96
|
+
sourceId: source.stamp.generation,
|
|
97
|
+
sampleRate: audio.sampleRate,
|
|
98
|
+
channels: audio.channels,
|
|
99
|
+
format: audio.format ?? null,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
facts.busy = false;
|
|
105
|
+
}
|
|
106
|
+
}
|