@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.
Files changed (65) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/bin/vestra-plugin.mjs +1 -131
  3. package/dist/api-requests.d.ts +1 -1
  4. package/dist/api-requests.js +10 -2
  5. package/dist/commands.js +1 -0
  6. package/dist/docs-tree.json.gz +0 -0
  7. package/dist/manifest.d.ts +0 -5
  8. package/dist/manifest.js +1 -8
  9. package/dist/mpv.js +1 -1
  10. package/dist/plugin/appearance.d.ts +2 -2
  11. package/dist/plugin/appearance.js +3 -3
  12. package/dist/plugin/connection.d.ts +39 -29
  13. package/dist/plugin/connection.js +110 -101
  14. package/dist/plugin/index.js +8 -6
  15. package/dist/plugin/passes.js +1 -1
  16. package/dist/plugin/player/events.d.ts +18 -9
  17. package/dist/plugin/player/events.js +36 -11
  18. package/dist/plugin/player.d.ts +31 -28
  19. package/dist/plugin/player.js +42 -68
  20. package/dist/plugin/scope.d.ts +2 -9
  21. package/dist/plugin/scope.js +21 -27
  22. package/dist/plugin/subtitles.d.ts +6 -1
  23. package/dist/plugin/subtitles.js +18 -2
  24. package/dist/plugin/testing/commands.d.ts +5 -0
  25. package/dist/plugin/testing/commands.js +6 -3
  26. package/dist/plugin/testing/facts.d.ts +46 -0
  27. package/dist/plugin/testing/facts.js +106 -0
  28. package/dist/plugin/testing/index.d.ts +38 -13
  29. package/dist/plugin/testing/index.js +63 -17
  30. package/dist/plugin/testing/media.js +6 -0
  31. package/dist/plugin/testing/revoke.d.ts +15 -0
  32. package/dist/plugin/testing/revoke.js +13 -0
  33. package/dist/plugin/testing/services.js +50 -1
  34. package/dist/plugin/testing/transport.js +8 -0
  35. package/dist/plugin/timeline.d.ts +2 -2
  36. package/dist/plugin/timeline.js +3 -3
  37. package/dist/plugin/types/base.d.ts +91 -13
  38. package/dist/plugin/types/commands.d.ts +8 -8
  39. package/dist/plugin/types/packages.d.ts +10 -1
  40. package/dist/plugin/types/playback.d.ts +240 -116
  41. package/dist/plugin/types/plugin-wire.d.ts +2 -2
  42. package/dist/plugin/types/processing.d.ts +2 -3
  43. package/dist/plugin/types/services.d.ts +10 -4
  44. package/dist/plugin/types/subtitles.d.ts +9 -8
  45. package/dist/plugin/types/ui-layout.d.ts +32 -17
  46. package/dist/plugin/types/ui-locale.d.ts +9 -9
  47. package/dist/plugin/types/ui-shell.d.ts +7 -6
  48. package/dist/plugin/view/layout.d.ts +33 -1
  49. package/dist/plugin/view/layout.js +63 -34
  50. package/dist/plugin/window.d.ts +9 -1
  51. package/dist/plugin/window.js +14 -2
  52. package/dist/processing.d.ts +2 -2
  53. package/dist/request-queue.d.ts +7 -3
  54. package/dist/request-queue.js +19 -5
  55. package/dist/ts-plugin.d.ts +3 -4
  56. package/dist/ts-plugin.js +1 -1
  57. package/dist/wire.d.ts +4 -1
  58. package/dist/wire.js +2 -1
  59. package/llms.txt +3 -3
  60. package/package.json +3 -5
  61. package/capability-scan.json +0 -387
  62. package/dist/capability-scan.d.ts +0 -95
  63. package/dist/capability-scan.js +0 -249
  64. package/dist/member-uses.d.ts +0 -61
  65. package/dist/member-uses.js +0 -160
@@ -34,6 +34,15 @@ export const WAKE_EVENTS = [
34
34
  "source.opening",
35
35
  "source.ready",
36
36
  "source.ended",
37
+ // SDK 1.11.0: the facts that changed, once per change.
38
+ "video.reconfigured",
39
+ "audio.reconfigured",
40
+ "audio.tracks.changed",
41
+ "subtitles.changed",
42
+ "window.changed",
43
+ "layout.changed",
44
+ "audio.devices.changed",
45
+ "app.started",
37
46
  ];
38
47
  /**
39
48
  * The player's answers to a declaration that refuse that one declaration (a
@@ -94,13 +103,6 @@ export class Connection {
94
103
  */
95
104
  requests;
96
105
  #events = new Map();
97
- /** The missing `subscribe()` warning was given (once per plugin). */
98
- #warnedEvents = false;
99
- /**
100
- * Event delivery is on: `plugin.player.subscribe()` was called
101
- * ({@link Connection.deliver}).
102
- */
103
- #delivering = false;
104
106
  /**
105
107
  * The player's state is read again after the plugin's own actions:
106
108
  * `plugin.player.read()` was called.
@@ -158,7 +160,7 @@ export class Connection {
158
160
  locale: transport.locale,
159
161
  });
160
162
  const host = this.host;
161
- this.app = appInfo(app, () => host.app.system());
163
+ this.app = appInfo(app, () => host.app.system(), (paths) => host.app.openWindow([...paths]));
162
164
  const features = app
163
165
  ?.features;
164
166
  this.features = new Set(Array.isArray(features)
@@ -185,25 +187,6 @@ export class Connection {
185
187
  this.commands.get(data.id)?.();
186
188
  });
187
189
  }
188
- /** Event delivery is on (`plugin.player.subscribe()` was called). */
189
- get delivering() {
190
- return this.#delivering;
191
- }
192
- /**
193
- * Turn event delivery on (`plugin.player.subscribe()`): every later
194
- * listener is subscribed, and so is what was added before and heard
195
- * nothing. Idempotent.
196
- */
197
- deliver() {
198
- if (this.#delivering)
199
- return;
200
- this.#delivering = true;
201
- for (const [event, group] of this.#events)
202
- if (group.unheard) {
203
- group.unheard = false;
204
- this.#open(event, group);
205
- }
206
- }
207
190
  /** Read the state copy kept by `event` again, if one exists; never rejects. */
208
191
  async reread(event) {
209
192
  await this.rereads
@@ -307,15 +290,14 @@ export class Connection {
307
290
  }
308
291
  /**
309
292
  * Host events with one `events.subscribe` per name, however many listeners.
310
- * An event that needs delivery (`"events"`) is subscribed only once
311
- * `plugin.player.subscribe()` was called; until then its listener simply
312
- * never fires.
293
+ * A plugin listener subscribes its event at once. A `"held"` event (the
294
+ * default, {@link Needs}) is subscribed only while a listener, a hold or
295
+ * a stream holds it: a state copy alone (`mirror`) waits, and hears the
296
+ * events while something else holds the group.
313
297
  * `mirror`: the SDK's own copy of the state (`plugin.player.state` and
314
298
  * the like), not a listener of the plugin's (see {@link EventGroup}).
315
299
  */
316
- on(event, listener,
317
- /** `"events"`: it arrives after `plugin.player.subscribe()`; `null`: always. */
318
- needs = "events", mirror = false) {
300
+ on(event, listener, needs = "held", mirror = false) {
319
301
  let entry = this.#events.get(event);
320
302
  const created = !entry;
321
303
  if (!entry) {
@@ -324,6 +306,8 @@ export class Connection {
324
306
  mirrors: new Set(),
325
307
  active: 0,
326
308
  whys: new Map(),
309
+ held: needs === "held",
310
+ holders: 0,
327
311
  };
328
312
  this.#events.set(event, entry);
329
313
  }
@@ -334,16 +318,17 @@ export class Connection {
334
318
  const token = {};
335
319
  if (!mirror) {
336
320
  group.active++;
321
+ group.holders++;
337
322
  group.whys.set(token, listenerWhy(this.callSite()));
338
323
  }
339
- if (created && needs === "events" && !this.#delivering)
340
- group.unheard = true;
341
- if (!mirror && group.unheard)
342
- this.#warnUnheard(event);
343
- if (created && !group.unheard)
344
- this.#open(event, group);
324
+ if (created) {
325
+ if (group.held && group.holders === 0)
326
+ group.unheard = true;
327
+ else
328
+ this.#open(event, group);
329
+ }
345
330
  else
346
- this.#tell(event, group);
331
+ this.#heldBy(event, group, "never");
347
332
  let listening = true;
348
333
  return {
349
334
  dispose: async () => {
@@ -352,19 +337,57 @@ export class Connection {
352
337
  listening = false;
353
338
  group.listeners.delete(listener);
354
339
  group.mirrors.delete(listener);
355
- if (!mirror)
340
+ if (!mirror) {
356
341
  group.active--;
342
+ group.holders--;
343
+ }
357
344
  group.whys.delete(token);
358
345
  if (this.#events.get(event) !== group)
359
346
  return;
360
347
  if (group.listeners.size)
361
- return this.#tell(event, group);
348
+ return this.#released(event, group);
362
349
  this.#events.delete(event);
363
350
  const off = await group.off?.catch(() => undefined);
364
351
  await off?.().catch(() => { });
365
352
  },
366
353
  };
367
354
  }
355
+ /**
356
+ * `group` gained a holder (or a mirror joined it): subscribed now if it
357
+ * waited for one, else the player is told what listens. `catchUp`: when
358
+ * it opens, the copy is read once more (a change between the last read
359
+ * and the subscription sent no event): after `read()`, always, or never.
360
+ */
361
+ #heldBy(event, group, catchUp) {
362
+ if (!(group.unheard && group.holders > 0))
363
+ return this.#tell(event, group);
364
+ group.unheard = false;
365
+ this.#open(event, group);
366
+ const opened = group.off;
367
+ const again = catchUp === "always" || (catchUp === "read" && this.reads);
368
+ if (again && opened)
369
+ void opened
370
+ .then(() => (group.off === opened ? this.reread(event) : undefined))
371
+ .catch(() => { });
372
+ }
373
+ /**
374
+ * `group` lost a holder: a held-only group that nothing holds any more is
375
+ * unsubscribed at the player and waits again, its copy kept as it was;
376
+ * otherwise the player is told what listens now.
377
+ */
378
+ #released(event, group) {
379
+ if (!(group.held && group.holders === 0 && !group.unheard))
380
+ return this.#tell(event, group);
381
+ group.unheard = true;
382
+ const off = group.off;
383
+ group.off = undefined;
384
+ group.told = undefined;
385
+ group.toldWhy = undefined;
386
+ void off
387
+ ?.catch(() => undefined)
388
+ .then((unsubscribe) => unsubscribe?.())
389
+ .catch(() => { });
390
+ }
368
391
  /** Subscribe `group` to `event` at the player, as it stands now. */
369
392
  #open(event, group) {
370
393
  group.told = group.active > 0;
@@ -391,20 +414,34 @@ export class Connection {
391
414
  this.starting(group.off, (error) => console.error(`[${this.manifest.id}] subscribe ${event}:`, error));
392
415
  }
393
416
  /**
394
- * Count `event` as listened to while held: a watcher of a service's
395
- * state, a binding that reads it. Nothing when nothing subscribed to it
396
- * (no `plugin.player.subscribe()`, or the service did not start).
417
+ * Hold `event` while the handle lives: a watcher of a service's state
418
+ * (`MainWindow.onChange`, a panel slot's `onChange`, a media handle's
419
+ * `ready` and `onEnd`, a scrub). It counts as listened to, and a
420
+ * held-only group ({@link Needs}) is subscribed while held, with its copy
421
+ * read once more when the subscription starts after `read()` (or
422
+ * `always`). Nothing when nothing started the group (the service did
423
+ * not start).
424
+ */
425
+ hold(event, why, always = false) {
426
+ return this.#hold(event, why, always ? "always" : "read");
427
+ }
428
+ /**
429
+ * {@link Connection.hold} for `plugin.player.stream` (SDK 1.10.0): the
430
+ * stream reads the state itself when it opens, so the copy is not read
431
+ * once more here.
397
432
  */
398
- hold(event, why) {
433
+ follow(event, why) {
434
+ return this.#hold(event, why, "never");
435
+ }
436
+ #hold(event, why, catchUp) {
399
437
  const group = this.#events.get(event);
400
438
  if (!group)
401
439
  return { dispose: async () => { } };
402
- if (group.unheard)
403
- this.#warnUnheard(event);
404
440
  group.active++;
441
+ group.holders++;
405
442
  const token = {};
406
443
  group.whys.set(token, why ?? listenerWhy(this.callSite()));
407
- this.#tell(event, group);
444
+ this.#heldBy(event, group, catchUp);
408
445
  let held = true;
409
446
  return {
410
447
  dispose: async () => {
@@ -412,76 +449,42 @@ export class Connection {
412
449
  return;
413
450
  held = false;
414
451
  group.active--;
452
+ group.holders--;
415
453
  group.whys.delete(token);
416
454
  if (this.#events.get(event) === group)
417
- this.#tell(event, group);
455
+ this.#released(event, group);
418
456
  },
419
457
  };
420
458
  }
421
459
  /**
422
- * Hear `event` while followed, whether or not event delivery is on, and
423
- * count it as listened to (`plugin.player.stream`, SDK 1.10.0): the group
424
- * the caller started (a state copy's) is subscribed now if it waited for
425
- * `plugin.player.subscribe()`, and only it. When the last follower ends,
426
- * such a group waits again as before: its subscription at the player
427
- * ends, and the copy stays as it was. Nothing when nothing started the
428
- * group.
460
+ * Count `event` as listened to while a binding reads its state: the
461
+ * binding's reason joins what the player is told while the group is
462
+ * subscribed, but it never subscribes a held-only group on its own (a
463
+ * bound value that reads `plugin.player.state` shows the newest snapshot
464
+ * the plugin has; a stream or an event makes it follow the player).
465
+ * Nothing when nothing started the group.
429
466
  */
430
- follow(event, why) {
467
+ bindingReads(event, why) {
431
468
  const group = this.#events.get(event);
432
469
  if (!group)
433
470
  return { dispose: async () => { } };
434
- group.followers = (group.followers ?? 0) + 1;
435
471
  group.active++;
436
472
  const token = {};
437
- group.whys.set(token, why ?? listenerWhy(this.callSite()));
438
- if (group.unheard) {
439
- group.unheard = false;
440
- group.followed = true;
441
- this.#open(event, group);
442
- }
443
- else
444
- this.#tell(event, group);
445
- let following = true;
473
+ group.whys.set(token, why);
474
+ this.#tell(event, group);
475
+ let reading = true;
446
476
  return {
447
477
  dispose: async () => {
448
- if (!following)
478
+ if (!reading)
449
479
  return;
450
- following = false;
480
+ reading = false;
451
481
  group.active--;
452
- group.followers = (group.followers ?? 1) - 1;
453
482
  group.whys.delete(token);
454
- if (this.#events.get(event) !== group)
455
- return;
456
- if (group.followers === 0 && group.followed && !this.#delivering) {
457
- // Back to waiting for `subscribe()`, as before the first follower.
458
- group.followed = false;
459
- group.unheard = true;
460
- const off = group.off;
461
- group.off = undefined;
462
- group.told = undefined;
463
- group.toldWhy = undefined;
464
- const unsubscribe = await off?.catch(() => undefined);
465
- await unsubscribe?.().catch(() => { });
466
- return;
467
- }
468
- this.#tell(event, group);
483
+ if (this.#events.get(event) === group)
484
+ this.#tell(event, group);
469
485
  },
470
486
  };
471
487
  }
472
- /**
473
- * A development warning, once per plugin, no behaviour change: the plugin
474
- * follows `event` (a listener, an `onChange`, a `bind` that reads the
475
- * state) before `plugin.player.subscribe()`, so changes made elsewhere
476
- * (the user, the player, another plugin) never reach it; the state moves
477
- * only after its own calls.
478
- */
479
- #warnUnheard(event) {
480
- if (this.#warnedEvents)
481
- return;
482
- this.#warnedEvents = true;
483
- 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().`);
484
- }
485
488
  /**
486
489
  * Tell the player when `group` changes between mirror and listener, and
487
490
  * why it listens when that changed.
@@ -542,7 +545,7 @@ function allWhys(group) {
542
545
  return [...new Set([...group.whys.values()].map((why) => why()))];
543
546
  }
544
547
  /** `plugin.app` from the start-up handshake (the runner's environment). */
545
- export function appInfo(raw, system = () => Promise.reject(failure("unavailable", "no player to ask"))) {
548
+ export function appInfo(raw, system = () => Promise.reject(failure("unavailable", "no player to ask")), openWindow = () => Promise.reject(failure("unavailable", "no player to ask"))) {
546
549
  const info = (raw ?? {});
547
550
  const parts = (info.components ?? {});
548
551
  const text = (value) => (typeof value === "string" ? value : null);
@@ -558,8 +561,14 @@ export function appInfo(raw, system = () => Promise.reject(failure("unavailable"
558
561
  libav: Object.freeze(libav),
559
562
  slint: text(parts.slint) ?? "",
560
563
  }),
564
+ // Only in a temporary window (player 0.10.3); absent otherwise.
565
+ ...(info.temporary === true ? { temporary: true } : {}),
561
566
  };
562
- // A method, not data: kept out of comparisons and JSON of the facts.
567
+ // Methods, not data: kept out of comparisons and JSON of the facts.
563
568
  Object.defineProperty(app, "system", { value: system, enumerable: false });
569
+ Object.defineProperty(app, "openWindow", {
570
+ value: openWindow,
571
+ enumerable: false,
572
+ });
564
573
  return Object.freeze(app);
565
574
  }
@@ -13,9 +13,9 @@ options) {
13
13
  const runtime = new Runtime(transport, manifest, directory, dataDirectory, app, options);
14
14
  // The window state is synchronous for plugins: read it first. The
15
15
  // player's state and the timeline are the plugin's explicit calls, first
16
- // in `activate`: `plugin.player.subscribe()` (event delivery, the copy
17
- // of the player's state follows from then on) and
18
- // `await plugin.player.read()` (state and timeline read once). Window and
16
+ // in `activate`: `await plugin.player.read()` (state and timeline read
17
+ // once); the copies follow the player's events while something holds
18
+ // them (a listener, a watcher, a stream; `Connection.hold`). Window and
19
19
  // timeline subscribe on their first use. The timeline's copy exists from
20
20
  // the start: it tells the connection how `read()` reads the lists.
21
21
  timelineOf(runtime);
@@ -50,9 +50,11 @@ options) {
50
50
  activated: () => runtime.activated(),
51
51
  dispose: async (info) => {
52
52
  runtime.stopping ??= { reason: stopReason(info?.reason) };
53
- // Before the cleanup runs: what still waits to be sent rejects as the
54
- // requests in flight do when the runner stops (`disabled`); the
55
- // cleanup's own requests go to the transport as before.
53
+ // Before the cleanup runs (the player sent `runtime.stop`): what
54
+ // still waits to be sent rejects as the requests in flight do when the
55
+ // runner stops (`disabled`), and every later request, the cleanup's
56
+ // own included, is refused without being sent (`RequestQueue.close`):
57
+ // the player has let go of the plugin and undoes what it held itself.
56
58
  runtime.requests.close();
57
59
  await root.dispose();
58
60
  runtime.stop();
@@ -305,7 +305,7 @@ export class Passes {
305
305
  }
306
306
  for (const [event, why] of reads)
307
307
  if (!held.has(event))
308
- held.set(event, this.#connection.hold(event, why));
308
+ held.set(event, this.#connection.bindingReads(event, why));
309
309
  }
310
310
  }
311
311
  /**
@@ -1,21 +1,30 @@
1
+ import type { Needs } from "../connection.ts";
1
2
  import type { ScopeImpl } from "../scope.ts";
2
- import type { Disposable, EventPayload, HostEvent, SourceEvent } from "../types.ts";
3
+ import type { Disposable, EventPayload, FactEvent, HostEvent, SourceEvent } from "../types.ts";
3
4
  /**
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.
5
+ * Every event a plugin listens to by name, and when its group is
6
+ * subscribed at the player (`Needs`): `"held"` only while a listener, a
7
+ * hold or a stream holds it (the SDK's own copy of a frequent state never
8
+ * subscribes on its own); `null` from its first entry, a copy included.
9
+ * A plugin listener subscribes its event either way.
7
10
  */
8
- export declare const EVENT_NEEDS: Readonly<Record<HostEvent | SourceEvent, "events" | null>>;
11
+ export declare const EVENT_NEEDS: Readonly<Record<HostEvent | SourceEvent | FactEvent, Needs>>;
9
12
  /** `Player.on`'s arguments: a {@link HostEvent} name and a function. */
10
- export declare function checkOn(event: unknown, listener: unknown): asserts event is HostEvent | SourceEvent;
13
+ export declare function checkOn(event: unknown, listener: unknown): asserts event is HostEvent | SourceEvent | FactEvent;
11
14
  /**
12
15
  * The discrete source events (player 0.10.0): their `state` reaches the
13
16
  * listener as a `PlayerState`, not in the wire shape.
14
17
  */
15
18
  export declare const SOURCE_EVENTS: ReadonlySet<string>;
19
+ /**
20
+ * The second batch of events (SDK 1.11.0): a fact that changed, once per
21
+ * change. Some reach the listener in the SDK's shape (the scope converts
22
+ * them, `ScopeImpl.fact`).
23
+ */
24
+ export declare const FACT_EVENTS: ReadonlySet<string>;
16
25
  /**
17
26
  * `Player.on`: `listener` hears each `event`, with a copy of its data;
18
- * `convert` (the source events) turns the copy into what the listener
19
- * gets.
27
+ * `convert` (the source and fact events) turns the copy into what the
28
+ * listener gets.
20
29
  */
21
- export declare function playerOn<E extends HostEvent>(scope: ScopeImpl, event: E | SourceEvent, listener: (data: EventPayload<E>) => void, convert?: (data: unknown) => unknown): Disposable;
30
+ export declare function playerOn<E extends HostEvent>(scope: ScopeImpl, event: E | SourceEvent | FactEvent, listener: (data: EventPayload<E>) => void, convert?: (data: unknown) => unknown): Disposable;
@@ -7,25 +7,35 @@
7
7
  */
8
8
  import { failure } from "../errors.js";
9
9
  /**
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.
10
+ * Every event a plugin listens to by name, and when its group is
11
+ * subscribed at the player (`Needs`): `"held"` only while a listener, a
12
+ * hold or a stream holds it (the SDK's own copy of a frequent state never
13
+ * subscribes on its own); `null` from its first entry, a copy included.
14
+ * A plugin listener subscribes its event either way.
13
15
  */
14
16
  export const EVENT_NEEDS = {
15
- "source.state": "events",
16
- "playback.backend": "events",
17
- "window.state": "events",
17
+ "source.state": "held",
18
+ "playback.backend": "held",
19
+ "window.state": "held",
18
20
  "packages.changed": null,
19
21
  "bindings.changed": null,
20
22
  "commands.keys": null,
21
- "timeline.changed": "events",
22
- "appearance.changed": "events",
23
- "resolvers.fileTypes": "events",
23
+ "timeline.changed": "held",
24
+ "appearance.changed": "held",
25
+ "resolvers.fileTypes": "held",
24
26
  "video.upscaling.changed": null,
25
27
  "video.motion.changed": null,
26
28
  "source.opening": null,
27
29
  "source.ready": null,
28
30
  "source.ended": null,
31
+ "video.reconfigured": null,
32
+ "audio.reconfigured": null,
33
+ "audio.tracks.changed": null,
34
+ "subtitles.changed": null,
35
+ "window.changed": null,
36
+ "layout.changed": null,
37
+ "audio.devices.changed": null,
38
+ "app.started": null,
29
39
  };
30
40
  /** `Player.on`'s arguments: a {@link HostEvent} name and a function. */
31
41
  export function checkOn(event, listener) {
@@ -43,10 +53,25 @@ export const SOURCE_EVENTS = new Set([
43
53
  "source.ready",
44
54
  "source.ended",
45
55
  ]);
56
+ /**
57
+ * The second batch of events (SDK 1.11.0): a fact that changed, once per
58
+ * change. Some reach the listener in the SDK's shape (the scope converts
59
+ * them, `ScopeImpl.fact`).
60
+ */
61
+ export const FACT_EVENTS = new Set([
62
+ "video.reconfigured",
63
+ "audio.reconfigured",
64
+ "audio.tracks.changed",
65
+ "subtitles.changed",
66
+ "window.changed",
67
+ "layout.changed",
68
+ "audio.devices.changed",
69
+ "app.started",
70
+ ]);
46
71
  /**
47
72
  * `Player.on`: `listener` hears each `event`, with a copy of its data;
48
- * `convert` (the source events) turns the copy into what the listener
49
- * gets.
73
+ * `convert` (the source and fact events) turns the copy into what the
74
+ * listener gets.
50
75
  */
51
76
  export function playerOn(scope, event, listener, convert = (data) => data) {
52
77
  checkOn(event, listener);
@@ -4,7 +4,7 @@ import type { Runtime } from "./runtime.ts";
4
4
  import type { ScopeImpl } from "./scope.ts";
5
5
  import { resolvedStream } from "./stream.ts";
6
6
  import type { StreamSource } from "./stream.ts";
7
- import type { Conditional, Disposable, Player, PlayerState } from "./types.ts";
7
+ import type { AudioTrack, Conditional, Disposable, Player, PlayerState } from "./types.ts";
8
8
  /**
9
9
  * The key of `plugin.player.state` in the runtime's field tracking
10
10
  * (`Runtime.depends`). Its fields are the state's own, plus `stamp` for
@@ -16,25 +16,20 @@ export declare const sameStamp: (a: SourceStamp, b: SourceStamp) => boolean;
16
16
  /**
17
17
  * One per plugin: the state store and the operation book client.
18
18
  *
19
- * The state copy (a mirror of `source.state`) follows the player's events
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
23
- * `plugin.player.state`, `onChange`, `isCurrent`, a media handle, a
24
- * scrub, a stream, a filter, a shader or view request, a capture) and
25
- * subscribes nothing until `subscribe()`, which subscribes it and, after
26
- * `read()`, reads the state once more (`#catchUp`).
19
+ * The state copy (a mirror of `source.state`) is started by the first use
20
+ * of the state (a read of `plugin.player.state`, `isCurrent`, a media
21
+ * handle, a scrub, a stream, a filter, a shader or view request, a
22
+ * capture). It follows the player's events only while something holds
23
+ * `source.state` (a stream, a `player.on` listener of it, a media
24
+ * handle's `ready` or `onEnd`, a scrub; `Connection.hold`); otherwise it
25
+ * is the newest snapshot the plugin has: its start-up read, its own calls
26
+ * and the state a source event carries.
27
27
  */
28
28
  export declare class PlayerService implements StreamSource {
29
29
  #private;
30
30
  readonly runtime: Runtime;
31
31
  raw: SourceState;
32
32
  state: PlayerState;
33
- /**
34
- * The fields the last accepted state changed (`onChange` listeners are
35
- * told so a listener that read none of them needs no full pass).
36
- */
37
- change: ReadonlyMap<string, ReadonlySet<string>>;
38
33
  readonly output: Latest<{
39
34
  volume?: number;
40
35
  muted?: boolean;
@@ -47,19 +42,14 @@ export declare class PlayerService implements StreamSource {
47
42
  * a read that failed is tried again by the next call.
48
43
  */
49
44
  read(): Promise<void>;
50
- /**
51
- * `plugin.player.subscribe()`: turn event delivery on and follow
52
- * `source.state` now. Idempotent.
53
- */
54
- subscribe(): void;
55
- /** Whether the mirror follows the player's events yet. */
45
+ /** Whether the mirror is registered yet. */
56
46
  get started(): boolean;
57
47
  /**
58
- * Follow `source.state` from now on: the SDK's copy of the state (a
59
- * mirror; a plugin listens through `watch` and the bindings 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.
48
+ * Register the SDK's copy of the state (a mirror of `source.state`; a
49
+ * plugin listens through `watch`, `follow` and `player.on`). It hears
50
+ * the events while something holds the event (`Connection.hold`), which
51
+ * also reads the state once more after `read()` when the subscription
52
+ * starts. Resolves at once.
63
53
  */
64
54
  start(): Promise<void>;
65
55
  /** The state as the player has it now, for a call that needs a source. */
@@ -76,11 +66,16 @@ export declare class PlayerService implements StreamSource {
76
66
  * is not the player's current one and is not taken.
77
67
  */
78
68
  sourceEvent(event: string, data: unknown): unknown;
79
- watch(watcher: (raw: SourceState) => void): Disposable;
69
+ /**
70
+ * `watcher` hears each accepted state while the handle lives; it holds
71
+ * `source.state` (`Connection.hold`). `always`: the state is read once
72
+ * more when the subscription starts, also without `read()`.
73
+ */
74
+ watch(watcher: (raw: SourceState) => void, always?: boolean): Disposable;
80
75
  /**
81
76
  * `watch`, for `plugin.player.stream`: the copy hears `source.state` while
82
- * the watcher is open, with or without `subscribe()`, and the plugin
83
- * counts as listening to it (`Connection.follow`).
77
+ * the watcher is open, and the plugin counts as listening to it
78
+ * (`Connection.follow`; the stream reads the state itself).
84
79
  */
85
80
  follow(watcher: (raw: SourceState) => void, why: () => string): Disposable;
86
81
  refresh(): Promise<PlayerState>;
@@ -107,6 +102,14 @@ export declare class PlayerService implements StreamSource {
107
102
  /** Close only if `generation` is still the player's source. */
108
103
  closeIfCurrent(generation: number): Promise<void>;
109
104
  }
105
+ /**
106
+ * `audio.tracks.changed`'s data as the listener gets it (`ScopeImpl.fact`,
107
+ * SDK 1.11.0): the tracks as {@link PlayerState.audioTracks} lists them.
108
+ */
109
+ export declare function audioTracksChanged(data: unknown): {
110
+ sourceId: number;
111
+ audioTracks: AudioTrack[];
112
+ };
110
113
  export declare const playerOf: (runtime: Runtime) => PlayerService;
111
114
  /**
112
115
  * The player's source as a stream needs it (`stream.ts`, L1): a stream