@vestra-player/sdk 1.10.1 → 1.11.0-rc.2

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.
Files changed (60) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/bin/vestra-plugin.mjs +1 -131
  3. package/dist/api-requests.d.ts +1 -1
  4. package/dist/api-requests.js +9 -2
  5. package/dist/docs-tree.json.gz +0 -0
  6. package/dist/manifest.d.ts +0 -5
  7. package/dist/manifest.js +1 -8
  8. package/dist/mpv.js +1 -1
  9. package/dist/plugin/appearance.d.ts +2 -2
  10. package/dist/plugin/appearance.js +3 -3
  11. package/dist/plugin/connection.d.ts +38 -28
  12. package/dist/plugin/connection.js +101 -98
  13. package/dist/plugin/index.js +8 -6
  14. package/dist/plugin/passes.js +1 -1
  15. package/dist/plugin/player/events.d.ts +18 -9
  16. package/dist/plugin/player/events.js +36 -11
  17. package/dist/plugin/player.d.ts +45 -28
  18. package/dist/plugin/player.js +77 -68
  19. package/dist/plugin/scope.d.ts +2 -9
  20. package/dist/plugin/scope.js +22 -27
  21. package/dist/plugin/subtitles.d.ts +6 -1
  22. package/dist/plugin/subtitles.js +18 -2
  23. package/dist/plugin/testing/commands.js +1 -1
  24. package/dist/plugin/testing/facts.d.ts +46 -0
  25. package/dist/plugin/testing/facts.js +106 -0
  26. package/dist/plugin/testing/index.d.ts +12 -14
  27. package/dist/plugin/testing/index.js +52 -18
  28. package/dist/plugin/testing/media.js +6 -0
  29. package/dist/plugin/testing/revoke.d.ts +15 -0
  30. package/dist/plugin/testing/revoke.js +13 -0
  31. package/dist/plugin/testing/transport.js +8 -0
  32. package/dist/plugin/timeline.d.ts +2 -2
  33. package/dist/plugin/timeline.js +3 -3
  34. package/dist/plugin/types/base.d.ts +15 -15
  35. package/dist/plugin/types/commands.d.ts +8 -8
  36. package/dist/plugin/types/playback.d.ts +247 -116
  37. package/dist/plugin/types/plugin-wire.d.ts +2 -2
  38. package/dist/plugin/types/processing.d.ts +2 -3
  39. package/dist/plugin/types/subtitles.d.ts +9 -8
  40. package/dist/plugin/types/ui-layout.d.ts +32 -17
  41. package/dist/plugin/types/ui-locale.d.ts +9 -9
  42. package/dist/plugin/types/ui-shell.d.ts +7 -6
  43. package/dist/plugin/view/layout.d.ts +33 -1
  44. package/dist/plugin/view/layout.js +63 -34
  45. package/dist/plugin/window.d.ts +9 -1
  46. package/dist/plugin/window.js +14 -2
  47. package/dist/processing.d.ts +2 -2
  48. package/dist/request-queue.d.ts +7 -3
  49. package/dist/request-queue.js +19 -5
  50. package/dist/ts-plugin.d.ts +3 -4
  51. package/dist/ts-plugin.js +1 -1
  52. package/dist/wire.d.ts +1 -1
  53. package/dist/wire.js +1 -1
  54. package/llms.txt +3 -3
  55. package/package.json +2 -4
  56. package/capability-scan.json +0 -389
  57. package/dist/capability-scan.d.ts +0 -95
  58. package/dist/capability-scan.js +0 -249
  59. package/dist/member-uses.d.ts +0 -61
  60. package/dist/member-uses.js +0 -160
@@ -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`) follows the player's events
160
- * from `plugin.player.subscribe()` on (`subscribe`, first in `activate`
161
- * as the plugin writes it). Before that no event can arrive; `start` is
162
- * 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 until `subscribe()`, which subscribes it and, after
166
- * `read()`, reads the state once more (`#catchUp`).
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 subscribed (`start`). */
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
- * Follow `source.state` from now on: the SDK's copy of the state (a
242
- * mirror; a plugin listens through `watch` and the bindings that read
243
- * `state`). Then read the state once more (after `read()` and
244
- * `subscribe()`): a change between that read and the subscription sent
245
- * no event to this plugin. Resolves when that read is in.
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 this.#fresh;
227
+ return Promise.resolve();
250
228
  this.#started = true;
251
- this.runtime.on("source.state", (data) => this.accept(data), "events", true);
252
- this.#catchUp();
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,36 @@ export class PlayerService {
294
265
  this.accept(message.state);
295
266
  return { ...message, state: view(message.state) };
296
267
  }
297
- watch(watcher) {
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
+ /**
274
+ * A fact event's fields of the state (1.11.0-rc.2): taken into the copy
275
+ * when `belongs` holds for it, as `accept` takes a state (a precise
276
+ * pass for the fields that changed); its event sequence is kept, so the
277
+ * next `source.state` is accepted as before.
278
+ */
279
+ patch(belongs, fields) {
280
+ if (!belongs(this.raw))
281
+ return;
282
+ const raw = { ...this.raw, ...fields };
283
+ if (JSON.stringify(raw) === JSON.stringify(this.raw))
284
+ return;
285
+ const last = this.state;
286
+ const lastRaw = this.raw;
287
+ this.raw = raw;
288
+ this.state = view(raw, this.runtime);
289
+ const changed = changes(last, lastRaw, this.state, raw);
290
+ for (const watcher of [...this.#watchers])
291
+ watcher(raw);
292
+ this.runtime.changed(PLAYER, changed);
293
+ }
294
+ watch(watcher, always = false) {
298
295
  void this.start();
299
296
  this.#watchers.add(watcher);
300
- const held = this.runtime.hold("source.state");
297
+ const held = this.runtime.hold("source.state", undefined, always);
301
298
  return {
302
299
  dispose: async () => {
303
300
  this.#watchers.delete(watcher);
@@ -307,8 +304,8 @@ export class PlayerService {
307
304
  }
308
305
  /**
309
306
  * `watch`, for `plugin.player.stream`: the copy hears `source.state` while
310
- * the watcher is open, with or without `subscribe()`, and the plugin
311
- * counts as listening to it (`Connection.follow`).
307
+ * the watcher is open, and the plugin counts as listening to it
308
+ * (`Connection.follow`; the stream reads the state itself).
312
309
  */
313
310
  follow(watcher, why) {
314
311
  void this.start();
@@ -420,10 +417,8 @@ class MediaHandle {
420
417
  ready(options = {}) {
421
418
  const service = this.#service;
422
419
  return new Promise((resolve, reject) => {
423
- let poll;
424
420
  const finish = (error) => {
425
421
  watch.dispose();
426
- clearInterval(poll);
427
422
  options.signal?.removeEventListener("abort", abort);
428
423
  if (error)
429
424
  reject(error);
@@ -445,13 +440,13 @@ class MediaHandle {
445
440
  finish(abortError());
446
441
  void this.close().catch((error) => this.#scope.report(error));
447
442
  };
448
- const watch = service.watch(check);
443
+ // The watch holds `source.state`: the copy follows the player's
444
+ // events until it ends. A change before its subscription is in sent
445
+ // no event, so the state is read once more then (`always`).
446
+ const watch = service.watch(check, true);
449
447
  if (options.signal?.aborted)
450
448
  return abort();
451
449
  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
450
  check();
456
451
  });
457
452
  }
@@ -620,6 +615,28 @@ function provideSequence(scope, provider) {
620
615
  runtime.services.set("sequence.provider", handle);
621
616
  return scope.add(handle);
622
617
  }
618
+ /**
619
+ * `audio.tracks.changed`'s data as the listener gets it (`ScopeImpl.fact`,
620
+ * SDK 1.11.0): the tracks as {@link PlayerState.audioTracks} lists them.
621
+ * The copy takes them first (1.11.0-rc.2), when they are of its source.
622
+ */
623
+ export function audioTracksChanged(runtime, data) {
624
+ const { sourceId, audioTracks } = data;
625
+ playerOf(runtime).patch((raw) => raw.stamp.generation === sourceId, {
626
+ audioTracks,
627
+ });
628
+ return { sourceId, audioTracks: audioTracks.map(audioTrack) };
629
+ }
630
+ /**
631
+ * `audio.devices.changed`'s data as the listener gets it (1.11.0-rc.2):
632
+ * as the player sent it; the copy takes `requested` and `active` into
633
+ * {@link PlayerState.audioOutput} first.
634
+ */
635
+ export function audioDevicesChanged(runtime, data) {
636
+ const { requested, active } = data;
637
+ playerOf(runtime).patch(() => true, { audioOutput: { requested, active } });
638
+ return data;
639
+ }
623
640
  export const playerOf = (runtime) => runtime.service("player", () => new PlayerService(runtime));
624
641
  /**
625
642
  * The player's source as a stream needs it (`stream.ts`, L1): a stream
@@ -641,15 +658,6 @@ export function player(scope) {
641
658
  scope.runtime.depends(PLAYER);
642
659
  return service().state;
643
660
  },
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
661
  stream(listener) {
654
662
  if (typeof listener !== "function")
655
663
  throw failure("invalid", "stream takes a function");
@@ -693,7 +701,6 @@ export function player(scope) {
693
701
  });
694
702
  },
695
703
  refresh: () => service().refresh(),
696
- subscribe: () => service().subscribe(),
697
704
  read: () => service().read(),
698
705
  on(event, listener) {
699
706
  // Checked first; the copy then starts before the listener subscribes
@@ -702,6 +709,8 @@ export function player(scope) {
702
709
  scope.followCopy(event);
703
710
  if (SOURCE_EVENTS.has(event))
704
711
  return playerOn(scope, event, listener, (data) => service().sourceEvent(event, data));
712
+ if (FACT_EVENTS.has(event))
713
+ return playerOn(scope, event, listener, (data) => scope.fact(event, data));
705
714
  return playerOn(scope, event, listener);
706
715
  },
707
716
  isCurrent(state) {
@@ -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
@@ -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 { audioDevicesChanged, 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,18 @@ 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": audioTracksChanged,
47
+ "audio.devices.changed": audioDevicesChanged,
48
+ "subtitles.changed": subtitlesChanged,
49
+ "window.changed": windowChanged,
50
+ "layout.changed": layoutChanged,
51
+ };
39
52
  export class ScopeImpl {
40
53
  runtime;
41
54
  #parent;
@@ -74,6 +87,12 @@ export class ScopeImpl {
74
87
  if (Object.hasOwn(COPIES, event))
75
88
  COPIES[event](this.runtime);
76
89
  }
90
+ /** A fact event's data as `player.on`'s listener gets it ({@link FACTS}). */
91
+ fact(event, data) {
92
+ return Object.hasOwn(FACTS, event)
93
+ ? FACTS[event](this.runtime, data)
94
+ : data;
95
+ }
77
96
  commands = commands(this);
78
97
  when = WHEN;
79
98
  windows = windows(this);
@@ -189,30 +208,6 @@ export class ScopeImpl {
189
208
  }
190
209
  this.update();
191
210
  }
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
211
  /**
217
212
  * Run a listener that pushes its own values (`player.on`) like `run`, except
218
213
  * 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;
@@ -95,8 +95,8 @@ class SubtitleService {
95
95
  return;
96
96
  this.#source = source;
97
97
  void this.refresh().catch(() => { });
98
- }, "events", true);
99
- runtime.on("playback.backend", () => void this.refresh().catch(() => { }), "events", true);
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;
@@ -425,7 +425,7 @@ export function commandsHandlers(host, inner) {
425
425
  */
426
426
  export function builtinOnly(host) {
427
427
  if (!host.builtin)
428
- throw new HostError("capability", "this is for built-in plugins only");
428
+ throw new HostError("builtin-only", "this is for built-in plugins only");
429
429
  }
430
430
  /** The palette's rows: the player's core commands and the plugin's own. */
431
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
+ }
@@ -806,8 +806,8 @@ export declare class TestHost implements Transport {
806
806
  *
807
807
  * @example Simulate the user choosing French for the next start
808
808
  * The plugin hears that the saved interface language changed. The host
809
- * pushes `appearance.changed`, which a plugin sees (after `plugin.player.subscribe()`) in
810
- * `appearance.language` once it has read it and subscribed; this run's
809
+ * pushes `appearance.changed`, which a plugin that listens to it sees in
810
+ * `appearance.language`; this run's
811
811
  * language does not change.
812
812
  * ```ts
813
813
  * import assert from "node:assert/strict";
@@ -1070,8 +1070,8 @@ export declare class TestHost implements Transport {
1070
1070
  * @example Let another plugin publish chapters
1071
1071
  * The plugin under test sees two chapter marks another plugin put on the
1072
1072
  * timeline. `setTimelineLayer` stores that plugin's whole layer and pushes
1073
- * `timeline.changed`; once the plugin uses `plugin.timeline` (after
1074
- * `plugin.player.subscribe()`) the SDK keeps `marks` current from that event, and `settle()`
1073
+ * `timeline.changed`; while the plugin listens to it the SDK keeps
1074
+ * `marks` current from that event, and `settle()`
1075
1075
  * lets it arrive.
1076
1076
  * ```ts
1077
1077
  * import assert from "node:assert/strict";
@@ -1192,7 +1192,7 @@ export declare class TestHost implements Transport {
1192
1192
  *
1193
1193
  * @example Simulate another plugin switching to the light palette
1194
1194
  * The plugin hears the palette change. The host updates `appearance` and
1195
- * pushes `appearance.changed` to a plugin that listens (after `plugin.player.subscribe()`).
1195
+ * pushes `appearance.changed` to a plugin that listens.
1196
1196
  * ```ts
1197
1197
  * import assert from "node:assert/strict";
1198
1198
  * declare const host: TestHost;
@@ -2415,7 +2415,7 @@ export declare class TestHost implements Transport {
2415
2415
  * The plugin is built into the player (`startPlugin`'s `builtin`). Only
2416
2416
  * then does the host answer the built-in-only requests
2417
2417
  * (`commands.list`, `commands.run`, `palette.lead.*`); otherwise they
2418
- * fail with `capability`, as in the player.
2418
+ * fail with `builtin-only`, as in the player.
2419
2419
  *
2420
2420
  * @since 1.7.9
2421
2421
  */
@@ -2432,7 +2432,7 @@ export declare class TestHost implements Transport {
2432
2432
  * oldest first: the files and the process id answered
2433
2433
  * ({@link "@vestra-player/sdk"!App.openWindow | App.openWindow}). No
2434
2434
  * process starts. A
2435
- * plugin that is not built in is refused with `capability`, as in the
2435
+ * plugin that is not built in is refused with `builtin-only`, as in the
2436
2436
  * player; the files are checked as the player does (`invalid`,
2437
2437
  * `missing`).
2438
2438
  *
@@ -2590,7 +2590,7 @@ export declare class TestHost implements Transport {
2590
2590
  * Deliver a host event to the plugin. Like the player, subscription-based
2591
2591
  * events (`source.state`, `playback.backend`, `window.state`,
2592
2592
  * `timeline.changed`, `appearance.changed`) are delivered only when the
2593
- * plugin subscribed (it called `plugin.player.subscribe()` and listens). Most tests use the
2593
+ * plugin subscribed (something of it listens). Most tests use the
2594
2594
  * higher-level helpers (`setSource`, `setMainWindow`, ...) instead.
2595
2595
  *
2596
2596
  * @param event - The wire event name.
@@ -3345,13 +3345,11 @@ export declare class TestHost implements Transport {
3345
3345
  * The manifest id comes from `directory/manifest.json` unless `id` is
3346
3346
  * given; then no manifest is read (and without `directory` none is read
3347
3347
  * either: the id is `"test.plugin"`). Nothing in the manifest changes how
3348
- * the plugin runs: event delivery and the start-up reads are the plugin's
3349
- * own calls (`plugin.player.subscribe()`, `plugin.player.read()`), as in
3350
- * the player.
3348
+ * the plugin runs: the start-up read is the plugin's own call
3349
+ * (`plugin.player.read()`), and an event reaches it from its first
3350
+ * listener, as in the player.
3351
3351
  *
3352
- * Rejects when `manifest.json` cannot be read or parsed, when it still has
3353
- * `capabilities` (removed in 1.9.0; the message says what to call
3354
- * instead), when `activate`
3352
+ * Rejects when `manifest.json` cannot be read or parsed, when `activate`
3355
3353
  * throws, or when a registration made during activation fails (for example
3356
3354
  * `limit`, `conflict`, `invalid`). Stricter than the player's runner for
3357
3355
  * commands: there the SDK logs a command declaration the player refuses during