@vestra-player/sdk 1.11.0-rc.1 → 1.11.0-rc.3

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 CHANGED
@@ -7,9 +7,10 @@
7
7
  **The second batch of events** (needs the player version that sends them, 0.11):
8
8
 
9
9
  - **Fact events** (new, `FactEvent` and `FactEventPayloads`, a third overload of `player.on`): `video.reconfigured` (`{ sourceId, width, height, displayWidth, displayHeight, fps, rotation, hdr }`), `audio.reconfigured` (`{ sourceId, sampleRate, channels, format }`), `audio.tracks.changed` (`{ sourceId, audioTracks }`, as `AudioTrack`s), `subtitles.changed` (`{ state }`, a `SubtitlesState`, taken into `plugin.subtitles.state` first), `window.changed` (a `WindowState`, taken into `plugin.window.state` first; a resize once it has settled for 300 ms), `layout.changed` (`{ slots }`, each position with its panels, `LayoutPosition`), `audio.devices.changed` (`{ devices, requested, active }`) and `app.started` (`{ version, previous }`). Each is sent once per change; a listener of one does not keep the plugin running, and the player wakes a plugin in standby for it.
10
+ - **The copies take a fact first** (1.11.0-rc.2 adds the last two): `subtitles.changed` into `plugin.subtitles.state`, `window.changed` into `plugin.window.state`, `layout.changed` into the panel layout, `audio.tracks.changed` into `plugin.player.state.audioTracks` (when it is the copy's source) and `audio.devices.changed` into `plugin.player.state.audioOutput`, so the copy holds it when the listener runs and a binding that reads it runs again.
10
11
  - Removed `Player.subscribe()` and `Player.onChange()`.
11
12
  - **An event reaches a plugin from its first listener.** `source.state`, `playback.backend`, `window.state`, `timeline.changed`, `appearance.changed` and `resolvers.fileTypes` are subscribed while a listener, a watcher (`MainWindow.onChange`, a panel slot's `onChange`, `Subtitles.onChange`, a media handle's `ready` and `onEnd`, a scrub) or a stream holds them; the SDK's own copy and a binding's read never subscribe them on their own, so a bound value or a command state that reads `plugin.player.state` shows the newest snapshot the plugin has. `Media.ready` no longer polls the state every 100 ms.
12
- - **No request after `runtime.stop`**: once the player sent `runtime.stop`, every request of the plugin is refused with `disabled` and not sent, the plugin's own cleanup included (the player's runner refused them already). In `TestHost` the cleanup requests at a plugin's stop (and at `park()` and `upgrade()`) are therefore no longer sent, and the test host revokes what the run held itself, as the player does: its windows, panels, commands, settings pages, resolvers, sequence provider, streams and filter chains.
13
+ - **No request after `runtime.stop`**: once the player sent `runtime.stop`, every request of the plugin is refused with `disabled` and not sent, the plugin's own cleanup included (the player's runner refused them already). In `TestHost` the cleanup requests at a plugin's stop (and at `park()` and `upgrade()`) are therefore no longer sent, and the test host revokes what the run held itself, as the player does (1.11.0-rc.3 matches each kind of stop): at every stop its windows, panels, commands, settings pages, resolvers, sequence provider, streams, filter chains, display layer, render options and shaders; its timeline layer, always-on-top and cursor settings stay through `park()` (an idle stop) and go at every other stop (disable, a fault, uninstall, reload, `upgrade()`, quit, or `stop()` without a reason).
13
14
  - **`TestHost`** sends the fact events by the player's rules: `audio.tracks.changed` after a source change, `window.changed` and `layout.changed` after a `window.state`, `subtitles.changed` and `audio.devices.changed` after a request or an event changed them, and `video.reconfigured` and `audio.reconfigured` from `host.stats` when a source becomes ready. `app.started` is sent with `host.emit`.
14
15
 
15
16
  **No capability disclosure:**
Binary file
@@ -71,6 +71,13 @@ export declare class PlayerService implements StreamSource {
71
71
  * `source.state` (`Connection.hold`). `always`: the state is read once
72
72
  * more when the subscription starts, also without `read()`.
73
73
  */
74
+ /**
75
+ * A fact event's fields of the state (1.11.0-rc.2): taken into the copy
76
+ * when `belongs` holds for it, as `accept` takes a state (a precise
77
+ * pass for the fields that changed); its event sequence is kept, so the
78
+ * next `source.state` is accepted as before.
79
+ */
80
+ patch(belongs: (raw: SourceState) => boolean, fields: Partial<SourceState>): void;
74
81
  watch(watcher: (raw: SourceState) => void, always?: boolean): Disposable;
75
82
  /**
76
83
  * `watch`, for `plugin.player.stream`: the copy hears `source.state` while
@@ -105,11 +112,18 @@ export declare class PlayerService implements StreamSource {
105
112
  /**
106
113
  * `audio.tracks.changed`'s data as the listener gets it (`ScopeImpl.fact`,
107
114
  * SDK 1.11.0): the tracks as {@link PlayerState.audioTracks} lists them.
115
+ * The copy takes them first (1.11.0-rc.2), when they are of its source.
108
116
  */
109
- export declare function audioTracksChanged(data: unknown): {
117
+ export declare function audioTracksChanged(runtime: Runtime, data: unknown): {
110
118
  sourceId: number;
111
119
  audioTracks: AudioTrack[];
112
120
  };
121
+ /**
122
+ * `audio.devices.changed`'s data as the listener gets it (1.11.0-rc.2):
123
+ * as the player sent it; the copy takes `requested` and `active` into
124
+ * {@link PlayerState.audioOutput} first.
125
+ */
126
+ export declare function audioDevicesChanged(runtime: Runtime, data: unknown): unknown;
113
127
  export declare const playerOf: (runtime: Runtime) => PlayerService;
114
128
  /**
115
129
  * The player's source as a stream needs it (`stream.ts`, L1): a stream
@@ -270,6 +270,27 @@ export class PlayerService {
270
270
  * `source.state` (`Connection.hold`). `always`: the state is read once
271
271
  * more when the subscription starts, also without `read()`.
272
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
+ }
273
294
  watch(watcher, always = false) {
274
295
  void this.start();
275
296
  this.#watchers.add(watcher);
@@ -597,11 +618,25 @@ function provideSequence(scope, provider) {
597
618
  /**
598
619
  * `audio.tracks.changed`'s data as the listener gets it (`ScopeImpl.fact`,
599
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.
600
622
  */
601
- export function audioTracksChanged(data) {
623
+ export function audioTracksChanged(runtime, data) {
602
624
  const { sourceId, audioTracks } = data;
625
+ playerOf(runtime).patch((raw) => raw.stamp.generation === sourceId, {
626
+ audioTracks,
627
+ });
603
628
  return { sourceId, audioTracks: audioTracks.map(audioTrack) };
604
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
+ }
605
640
  export const playerOf = (runtime) => runtime.service("player", () => new PlayerService(runtime));
606
641
  /**
607
642
  * The player's source as a stream needs it (`stream.ts`, L1): a stream
@@ -12,7 +12,7 @@ import { drops } from "./drops.js";
12
12
  import { appearance, appearanceOf } from "./appearance.js";
13
13
  import { settings } from "./settings.js";
14
14
  import { i18n } from "./language.js";
15
- import { audioTracksChanged, player } from "./player.js";
15
+ import { audioDevicesChanged, audioTracksChanged, player } from "./player.js";
16
16
  import { audioFilters, videoFilters } from "./filters.js";
17
17
  import { videoRender, videoView } from "./view.js";
18
18
  import { videoShaders } from "./shaders.js";
@@ -43,7 +43,8 @@ const COPIES = {
43
43
  * as the player sent them.
44
44
  */
45
45
  const FACTS = {
46
- "audio.tracks.changed": (_, data) => audioTracksChanged(data),
46
+ "audio.tracks.changed": audioTracksChanged,
47
+ "audio.devices.changed": audioDevicesChanged,
47
48
  "subtitles.changed": subtitlesChanged,
48
49
  "window.changed": windowChanged,
49
50
  "layout.changed": layoutChanged,
@@ -1830,7 +1830,7 @@ export class TestHost {
1830
1830
  * pass it to {@link startPlugin} as `host`.
1831
1831
  */
1832
1832
  constructor() {
1833
- revokers.set(this, () => this.#revoke());
1833
+ revokers.set(this, (reason) => this.#revoke(reason));
1834
1834
  this.subtitles = {
1835
1835
  presentation: {
1836
1836
  revision: 1,
@@ -2929,7 +2929,7 @@ export class TestHost {
2929
2929
  return upgrade(this, this.#inner, activate);
2930
2930
  }
2931
2931
  /** See {@link revokeRun}: each through the host's own handler. */
2932
- #revoke() {
2932
+ #revoke(reason) {
2933
2933
  const run = (method, params) => {
2934
2934
  try {
2935
2935
  void Promise.resolve(this.#defaults[method]?.(params)).catch(() => { });
@@ -2953,8 +2953,28 @@ export class TestHost {
2953
2953
  for (const [producerId, producer] of this.producers)
2954
2954
  if (!producer.released)
2955
2955
  run("producer.release", { producerId });
2956
- // Its processing chains (filters) are withdrawn.
2956
+ // The playback worker's part (`owner.parked` and `owner.disabled`
2957
+ // alike): its filter chains, display layer, render options, shaders.
2957
2958
  this.processing.resources.clear();
2959
+ if (this.videoView.owner === this.manifestId)
2960
+ run("video.view.release", {});
2961
+ if (this.videoRender.owner === this.manifestId)
2962
+ run("video.render.release", {});
2963
+ this.videoShaders.handles.clear();
2964
+ // Kept through a standby, removed at every other stop (the player's
2965
+ // `keeps_shown_state`: an idle stop only).
2966
+ if (reason === "idle")
2967
+ return;
2968
+ const id = this.manifestId;
2969
+ const marks = this.timeline.layers.delete(id);
2970
+ const ranges = this.timeline.rangeLayers.delete(id);
2971
+ if (marks || ranges)
2972
+ this.emit("timeline.changed", {
2973
+ marks: this.timeline.marks,
2974
+ ranges: this.timeline.ranges,
2975
+ });
2976
+ this.mainWindow.onTop = false;
2977
+ this.mainWindow.cursorAutoHide = "fullscreen";
2958
2978
  }
2959
2979
  #defaults = {
2960
2980
  ...triggersHandlers(this, this.#inner),
@@ -3112,7 +3132,7 @@ export async function startPlugin(activate, options = {}) {
3112
3132
  await instance.dispose({ reason });
3113
3133
  await host.settle();
3114
3134
  // Standby and an upgrade stop the run: the player revokes what it held.
3115
- revokeRun(host);
3135
+ revokeRun(host, reason);
3116
3136
  await host.settle();
3117
3137
  };
3118
3138
  await host.settle();
@@ -3136,7 +3156,7 @@ export async function startPlugin(activate, options = {}) {
3136
3156
  if (!triggers.parked)
3137
3157
  await instance.dispose({ reason });
3138
3158
  await host.settle();
3139
- revokeRun(host);
3159
+ revokeRun(host, typeof reason === "string" ? reason : undefined);
3140
3160
  await host.settle();
3141
3161
  host.close();
3142
3162
  };
@@ -3164,7 +3184,7 @@ export async function startPlugin(activate, options = {}) {
3164
3184
  host.loseConnection();
3165
3185
  await instance.dispose({ reason: "host-lost" });
3166
3186
  await host.settle();
3167
- revokeRun(host);
3187
+ revokeRun(host, "host-lost");
3168
3188
  await host.settle();
3169
3189
  host.close();
3170
3190
  },
@@ -6,10 +6,17 @@ import type { TestHost } from "./index.ts";
6
6
  * What the player undoes by itself when a plugin's run stops (SDK 1.11.0):
7
7
  * the plugin's own cleanup requests are not sent after `runtime.stop`
8
8
  * (`RequestQueue.close`), so the test host revokes what the run held, as
9
- * the player does (its stop revokes the run's windows, panels, commands,
10
- * settings pages, resolvers, sequence provider, streams and filter
11
- * chains). By host.
9
+ * the player does at every stop (`host/lifecycle.rs` `stop_run` and the
10
+ * playback worker's `owner.parked` / `owner.disabled`): the run's windows,
11
+ * panels, commands, settings pages, resolvers, sequence provider, streams,
12
+ * filter chains, display layer, render options and shaders. Its timeline
13
+ * layer, always-on-top and cursor settings stay through a standby (an idle
14
+ * stop, `keeps_shown_state`) and go at every other stop: disable, a
15
+ * fault, uninstall, reload, upgrade, quit. By host.
12
16
  */
13
- export declare const revokers: WeakMap<TestHost, () => void>;
14
- /** Revoke what the plugin's run held (`startPlugin`'s `stop`). */
15
- export declare function revokeRun(host: TestHost): void;
17
+ export declare const revokers: WeakMap<TestHost, (reason?: string) => void>;
18
+ /**
19
+ * Revoke what the plugin's run held, for a stop with `reason`
20
+ * (`startPlugin`'s `stop`, `park()` with `idle`, `upgrade()`).
21
+ */
22
+ export declare function revokeRun(host: TestHost, reason?: string): void;
@@ -2,12 +2,19 @@
2
2
  * What the player undoes by itself when a plugin's run stops (SDK 1.11.0):
3
3
  * the plugin's own cleanup requests are not sent after `runtime.stop`
4
4
  * (`RequestQueue.close`), so the test host revokes what the run held, as
5
- * the player does (its stop revokes the run's windows, panels, commands,
6
- * settings pages, resolvers, sequence provider, streams and filter
7
- * chains). By host.
5
+ * the player does at every stop (`host/lifecycle.rs` `stop_run` and the
6
+ * playback worker's `owner.parked` / `owner.disabled`): the run's windows,
7
+ * panels, commands, settings pages, resolvers, sequence provider, streams,
8
+ * filter chains, display layer, render options and shaders. Its timeline
9
+ * layer, always-on-top and cursor settings stay through a standby (an idle
10
+ * stop, `keeps_shown_state`) and go at every other stop: disable, a
11
+ * fault, uninstall, reload, upgrade, quit. By host.
8
12
  */
9
13
  export const revokers = new WeakMap();
10
- /** Revoke what the plugin's run held (`startPlugin`'s `stop`). */
11
- export function revokeRun(host) {
12
- revokers.get(host)?.();
14
+ /**
15
+ * Revoke what the plugin's run held, for a stop with `reason`
16
+ * (`startPlugin`'s `stop`, `park()` with `idle`, `upgrade()`).
17
+ */
18
+ export function revokeRun(host, reason) {
19
+ revokers.get(host)?.(reason);
13
20
  }
@@ -1138,9 +1138,10 @@ export interface Player {
1138
1138
  * not keep the plugin running: the player starts a plugin in standby to
1139
1139
  * deliver them, and an event that arrives while the plugin starts waits
1140
1140
  * for its activation. Where the data carries a state the SDK keeps
1141
- * (`subtitles.changed`, `window.changed`), the SDK takes it first, so
1142
- * `plugin.subtitles.state` and `plugin.window.state` hold it when the
1143
- * listener runs. As for every {@link Player.on} listener, no full update
1141
+ * (`subtitles.changed`, `window.changed`, `layout.changed`, and
1142
+ * `audio.tracks.changed` and `audio.devices.changed` for
1143
+ * `plugin.player.state`), the SDK takes it first, so the copy holds it
1144
+ * when the listener runs. As for every {@link Player.on} listener, no full update
1144
1145
  * pass follows it.
1145
1146
  *
1146
1147
  * @param event - The event's name.
@@ -2081,7 +2082,11 @@ export interface FactEventPayloads {
2081
2082
  * loads; `source.ended` and `source.opening` say so).
2082
2083
  */
2083
2084
  "audio.tracks.changed": {
2084
- /** The source it belongs to ({@link PlayerState.sourceId}). */
2085
+ /**
2086
+ * The source it belongs to ({@link PlayerState.sourceId}). When it is
2087
+ * the source of `plugin.player.state`, the SDK takes the tracks into
2088
+ * {@link PlayerState.audioTracks} first.
2089
+ */
2085
2090
  sourceId: number;
2086
2091
  /** Its audio tracks, as {@link PlayerState.audioTracks} lists them. */
2087
2092
  audioTracks: AudioTrack[];
@@ -2129,7 +2134,9 @@ export interface FactEventPayloads {
2129
2134
  /**
2130
2135
  * The audio output devices changed: one was plugged in or removed, or
2131
2136
  * the device in use changed (`setAudioDevice`, or the chosen one went
2132
- * away and the system default plays). Checked once a second.
2137
+ * away and the system default plays). Checked once a second. The SDK
2138
+ * takes `requested` and `active` into {@link PlayerState.audioOutput}
2139
+ * first.
2133
2140
  */
2134
2141
  "audio.devices.changed": {
2135
2142
  /** The devices, as {@link Player.audioDevices} lists them. */
package/llms.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  # Vestra Player SDK
2
2
 
3
- > @vestra-player/sdk 1.11.0-rc.1: write plugins for Vestra Player in TypeScript (plugin API `vestra/1`). A plugin is a folder with `manifest.json` and an entry module whose default export `activate(plugin)` the player calls. The documentation is a tree of short pages read by path, like `go doc`: the same pages and API as https://vestrasys.github.io/vestra-player-sdk/.
3
+ > @vestra-player/sdk 1.11.0-rc.3: write plugins for Vestra Player in TypeScript (plugin API `vestra/1`). A plugin is a folder with `manifest.json` and an entry module whose default export `activate(plugin)` the player calls. The documentation is a tree of short pages read by path, like `go doc`: the same pages and API as https://vestrasys.github.io/vestra-player-sdk/.
4
4
 
5
5
  ## Read the documentation
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vestra-player/sdk",
3
- "version": "1.11.0-rc.1",
3
+ "version": "1.11.0-rc.3",
4
4
  "description": "Plugin API types, test host and plugin CLI for Vestra Player (apiVersion vestra/1)",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {