@vestra-player/sdk 1.6.19 → 1.6.21
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 +19 -0
- package/dist/commands.js +19 -18
- package/dist/docs-tree.json.gz +0 -0
- package/dist/i18n-tools.js +7 -2
- package/dist/plugin/runtime.d.ts +1 -0
- package/dist/plugin/runtime.js +3 -0
- package/dist/plugin/types/base.d.ts +1097 -0
- package/dist/plugin/types/base.js +1 -0
- package/dist/plugin/types/commands.d.ts +1189 -0
- package/dist/plugin/types/commands.js +1 -0
- package/dist/plugin/types/packages.d.ts +661 -0
- package/dist/plugin/types/packages.js +1 -0
- package/dist/plugin/types/playback.d.ts +1654 -0
- package/dist/plugin/types/playback.js +1 -0
- package/dist/plugin/types/processing.d.ts +974 -0
- package/dist/plugin/types/processing.js +1 -0
- package/dist/plugin/types/services.d.ts +1132 -0
- package/dist/plugin/types/services.js +1 -0
- package/dist/plugin/types/snapshots.d.ts +491 -0
- package/dist/plugin/types/snapshots.js +1 -0
- package/dist/plugin/types/sources.d.ts +302 -0
- package/dist/plugin/types/sources.js +1 -0
- package/dist/plugin/types/subtitles.d.ts +327 -0
- package/dist/plugin/types/subtitles.js +1 -0
- package/dist/plugin/types/ui-content.d.ts +692 -0
- package/dist/plugin/types/ui-content.js +1 -0
- package/dist/plugin/types/ui-layout.d.ts +1079 -0
- package/dist/plugin/types/ui-layout.js +1 -0
- package/dist/plugin/types/ui-locale.d.ts +490 -0
- package/dist/plugin/types/ui-locale.js +1 -0
- package/dist/plugin/types/ui-shell.d.ts +1072 -0
- package/dist/plugin/types/ui-shell.js +1 -0
- package/dist/plugin/types.d.ts +18 -11072
- package/llms.txt +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import type { Player, StreamOptions } from "./playback.ts";
|
|
2
|
+
import type { ResolvedMedia } from "../../source-resolvers.ts";
|
|
3
|
+
import type { Disposable } from "./base.ts";
|
|
4
|
+
import type { Stream, StreamFrame } from "./playback.ts";
|
|
5
|
+
/**
|
|
6
|
+
* Declaration of {@link Resolvers.add}: a web resolver
|
|
7
|
+
* ({@link WebResolverOptions}) or a file resolver ({@link FileResolverOptions}).
|
|
8
|
+
*
|
|
9
|
+
* @since 1.0.0
|
|
10
|
+
* @category Sources
|
|
11
|
+
*/
|
|
12
|
+
export type ResolverOptions = WebResolverOptions | FileResolverOptions;
|
|
13
|
+
/**
|
|
14
|
+
* A resolver for web pages: `https://host/…` to playable stream URLs.
|
|
15
|
+
*
|
|
16
|
+
* @since 1.0.0
|
|
17
|
+
* @category Sources
|
|
18
|
+
*/
|
|
19
|
+
export interface WebResolverOptions {
|
|
20
|
+
/** Local id, unique within the plugin. */
|
|
21
|
+
id: string;
|
|
22
|
+
/** URL schemes handled. */
|
|
23
|
+
schemes: ("http" | "https")[];
|
|
24
|
+
/** Exact host names. */
|
|
25
|
+
hosts: string[];
|
|
26
|
+
/** Turn a page URL into playable stream URLs. */
|
|
27
|
+
resolve(url: string, signal: AbortSignal): Promise<ResolvedMedia>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A resolver for local files by extension (SDK 1.5.3, player 0.4.1): when
|
|
31
|
+
* anyone opens such a file with {@link Player.open} (the Open dialog, the
|
|
32
|
+
* playlist, next / previous, the recent list, a drop that calls `open`),
|
|
33
|
+
* the player asks this plugin for a stream it generates instead of
|
|
34
|
+
* playing the file. Needs `source.resolve` and `producer.av`.
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* The open keeps everything of the original call: its `ifCurrent`, its
|
|
38
|
+
* operation (the opener's `open` and `media.ready()` settle as for any
|
|
39
|
+
* file), `paused` (the stream starts paused), and its path as
|
|
40
|
+
* `state.source`, with `state.kind` `"stream"`. A thrown error fails that
|
|
41
|
+
* open: `phase` `"error"` with the error's message as `state.error`,
|
|
42
|
+
* word for word. The stream belongs to this plugin, as with
|
|
43
|
+
* {@link Player.openStream}.
|
|
44
|
+
*
|
|
45
|
+
* Cancellation: `signal` aborts when the open is replaced, closed
|
|
46
|
+
* (`player.close()`, F4) or times out (30 seconds), or this resolver is
|
|
47
|
+
* disposed. Cancelled after `resolve` returned but before the stream ran,
|
|
48
|
+
* the SDK releases the stream and never calls `started`.
|
|
49
|
+
*
|
|
50
|
+
* One extension has one resolver: another plugin's resolver for it makes
|
|
51
|
+
* {@link Resolver.ready} reject with `conflict` without failing activation
|
|
52
|
+
* (the player shows a warning). When this plugin stops, its extensions are
|
|
53
|
+
* free again and such files go to the player as before.
|
|
54
|
+
*
|
|
55
|
+
* @example Play CHIP-8 programs with the plugin's own emulator
|
|
56
|
+
* Opening a `.ch8` file anywhere in the player (Open dialog, playlist,
|
|
57
|
+
* recent list) runs it in the plugin's emulator instead of failing as an
|
|
58
|
+
* unknown format. The player calls `resolve` with the path; the plugin
|
|
59
|
+
* reads the program and returns a stream whose `frame()` the SDK pulls on
|
|
60
|
+
* the audio clock, one 1/60 s frame per call. `started` runs once the
|
|
61
|
+
* stream plays; `signal` aborts the read when the open is replaced or
|
|
62
|
+
* closed.
|
|
63
|
+
* ```ts
|
|
64
|
+
* import { readFile } from "node:fs/promises";
|
|
65
|
+
* // The plugin's own emulator (made up here): one frame per call.
|
|
66
|
+
* declare function emulator(program: Uint8Array): () => StreamFrame;
|
|
67
|
+
* // ---cut---
|
|
68
|
+
* plugin.resolvers.add({
|
|
69
|
+
* id: "chip8",
|
|
70
|
+
* extensions: ["ch8"], // lower case, no dot; matches Game.CH8 too
|
|
71
|
+
* async resolve(path, signal) {
|
|
72
|
+
* const frame = emulator(await readFile(path, { signal }));
|
|
73
|
+
* return {
|
|
74
|
+
* kind: "stream",
|
|
75
|
+
* width: 64, // CHIP-8's display
|
|
76
|
+
* height: 32,
|
|
77
|
+
* frame,
|
|
78
|
+
* started: (stream) => stream.onStop((error) => error && plugin.osd.show(error.message)),
|
|
79
|
+
* };
|
|
80
|
+
* },
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @since 1.5.3
|
|
85
|
+
* @category Sources
|
|
86
|
+
*/
|
|
87
|
+
export interface FileResolverOptions {
|
|
88
|
+
/** Local id, unique within the plugin. */
|
|
89
|
+
id: string;
|
|
90
|
+
/**
|
|
91
|
+
* Lower case, without the dot: 1–16 entries of 1–16 lower-case letters or
|
|
92
|
+
* digits (not `"folder"`). Only absolute local paths match, by their
|
|
93
|
+
* extension in any case (`/roms/Game.NES`); URLs never do.
|
|
94
|
+
*/
|
|
95
|
+
extensions: string[];
|
|
96
|
+
/** Read the file and describe the stream to generate for it. */
|
|
97
|
+
resolve(path: string, signal: AbortSignal): Promise<ResolvedStream>;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* What a file resolver returns: a stream, with the same frame contract as
|
|
101
|
+
* {@link StreamOptions} (size limits, `frame()` on the audio clock).
|
|
102
|
+
*
|
|
103
|
+
* After `resolve` returns, the SDK starts the stream while the open waits.
|
|
104
|
+
* If that fails, the open fails with the player's words instead of the
|
|
105
|
+
* SDK's (the detail goes to the log): `device` "音频输出设备不可用",
|
|
106
|
+
* `timeout` "启动超时", `busy` "播放器正忙,请稍后重试", other start-up
|
|
107
|
+
* failures "无法启动播放". An error thrown by `frame()` keeps its message.
|
|
108
|
+
* To give your own text for a file you can tell is unusable (a bad header),
|
|
109
|
+
* check it in `resolve` and throw there.
|
|
110
|
+
*
|
|
111
|
+
* @since 1.5.3
|
|
112
|
+
* @category Sources
|
|
113
|
+
*/
|
|
114
|
+
export interface ResolvedStream {
|
|
115
|
+
/** Always `"stream"`. */
|
|
116
|
+
kind: "stream";
|
|
117
|
+
/** Frame width in pixels. */
|
|
118
|
+
width: number;
|
|
119
|
+
/** Frame height in pixels. */
|
|
120
|
+
height: number;
|
|
121
|
+
/** Produce the next frame. Never called concurrently or while paused. */
|
|
122
|
+
frame(): StreamFrame;
|
|
123
|
+
/**
|
|
124
|
+
* Called with the running stream once the player plays it, synchronously
|
|
125
|
+
* after activation and before any {@link Stream.onStop}. Not called when
|
|
126
|
+
* the open was cancelled first. `stream.stop()` closes the source (if
|
|
127
|
+
* still current); the plugin stopping stops it too.
|
|
128
|
+
*/
|
|
129
|
+
started?(stream: Stream): void;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* A registered resolver. Disposing it unregisters it and aborts resolutions in flight.
|
|
133
|
+
*
|
|
134
|
+
* @remarks
|
|
135
|
+
* A registered resolver, from {@link Resolvers.add}. Disposing it, its
|
|
136
|
+
* scope or stopping the plugin unregisters it and aborts resolutions in
|
|
137
|
+
* flight; the extensions or hosts are free again for other plugins.
|
|
138
|
+
*
|
|
139
|
+
* @capability source.resolve
|
|
140
|
+
*
|
|
141
|
+
* @example Report when another plugin already handles the format
|
|
142
|
+
* The plugin tells the user when its `.ch8` resolver could not register
|
|
143
|
+
* because another plugin holds that extension. `ready` rejects with
|
|
144
|
+
* `conflict`; for another plugin's claim that does not fail activation, so
|
|
145
|
+
* the plugin keeps running without the resolver.
|
|
146
|
+
* ```ts
|
|
147
|
+
* const resolver = plugin.resolvers.add({
|
|
148
|
+
* id: "chip8",
|
|
149
|
+
* extensions: ["ch8"],
|
|
150
|
+
* async resolve() {
|
|
151
|
+
* throw plugin.i18n.error("Not ready yet.");
|
|
152
|
+
* },
|
|
153
|
+
* });
|
|
154
|
+
* // Rejects with `conflict` when the extension is taken.
|
|
155
|
+
* resolver.ready.catch((error: PluginError) => {
|
|
156
|
+
* if (error.code === "conflict") void plugin.osd.show("Another plugin plays .ch8 files");
|
|
157
|
+
* });
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* @since 1.0.0
|
|
161
|
+
* @category Sources
|
|
162
|
+
*/
|
|
163
|
+
export interface Resolver extends Disposable {
|
|
164
|
+
/**
|
|
165
|
+
* Resolves when the player registered it; rejects otherwise: `conflict`
|
|
166
|
+
* when another resolver has the extension or the scheme + host (another
|
|
167
|
+
* plugin's: activation goes on; this plugin's own: activation fails),
|
|
168
|
+
* `invalid` for a malformed declaration (a player before 0.4.1 also for
|
|
169
|
+
* `extensions`).
|
|
170
|
+
*
|
|
171
|
+
* @throws `conflict` (rejects) Another resolver has the extension or the
|
|
172
|
+
* scheme + host, or this plugin already registered this id.
|
|
173
|
+
* @throws `busy` (rejects) The player already holds 16 resolvers.
|
|
174
|
+
* @throws `invalid` (rejects) A malformed declaration.
|
|
175
|
+
* @throws `capability` (rejects) The manifest does not declare
|
|
176
|
+
* `source.resolve`.
|
|
177
|
+
*/
|
|
178
|
+
readonly ready: Promise<void>;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* `plugin.resolvers`: turn web page URLs into playable streams, or local
|
|
182
|
+
* files into streams this plugin generates. Needs `source.resolve` (file
|
|
183
|
+
* resolvers also `producer.av`).
|
|
184
|
+
*
|
|
185
|
+
* @example Play pages of a video site
|
|
186
|
+
* Opening a `https://video.example.com/…` page plays its video. When the
|
|
187
|
+
* user opens a URL whose scheme and host this resolver declares, the
|
|
188
|
+
* player asks the plugin first; `resolve` returns the stream's address,
|
|
189
|
+
* and `signal` aborts the lookup when the open is replaced or closed.
|
|
190
|
+
* ```ts
|
|
191
|
+
* plugin.resolvers.add({
|
|
192
|
+
* id: "example",
|
|
193
|
+
* schemes: ["https"],
|
|
194
|
+
* hosts: ["video.example.com"],
|
|
195
|
+
* async resolve(url, signal) {
|
|
196
|
+
* const response = await fetch(url, { signal }); // the site's JSON for the page
|
|
197
|
+
* if (!response.ok) throw new Error(`video.example.com answered ${response.status}`);
|
|
198
|
+
* const page = await response.json();
|
|
199
|
+
* return { kind: "media", originalUrl: url, title: page.title, primary: { url: page.stream } };
|
|
200
|
+
* },
|
|
201
|
+
* });
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* @remarks
|
|
205
|
+
* A resolver turns something the player cannot play by itself into
|
|
206
|
+
* something it can: a web page address into stream URLs
|
|
207
|
+
* ({@link WebResolverOptions}), or a local file of a format the plugin
|
|
208
|
+
* understands into a stream the plugin generates
|
|
209
|
+
* ({@link FileResolverOptions}). The player asks the resolver whenever
|
|
210
|
+
* anyone opens a matching address or file (the Open dialog, the playlist,
|
|
211
|
+
* another plugin), so the plugin does not intercept opens itself.
|
|
212
|
+
*
|
|
213
|
+
* @capability source.resolve (file resolvers also `producer.av`)
|
|
214
|
+
* @see [Playback state, controls and sources](../../../docs/explanation/playback.md)
|
|
215
|
+
* @since 1.0.0
|
|
216
|
+
* @category Sources
|
|
217
|
+
*/
|
|
218
|
+
export interface Resolvers {
|
|
219
|
+
/**
|
|
220
|
+
* Register a resolver. When anyone opens a matching URL or file the
|
|
221
|
+
* player calls `resolve`; `signal` aborts when the open is cancelled or
|
|
222
|
+
* replaced. One scheme + host pair, and one extension, has one resolver
|
|
223
|
+
* (`conflict` otherwise). A rejected `resolve` fails the open with the
|
|
224
|
+
* error's message.
|
|
225
|
+
*
|
|
226
|
+
* @capability source.resolve
|
|
227
|
+
*
|
|
228
|
+
* @example Play a site's pages through the plugin
|
|
229
|
+
* Opening a `https://video.example.com/…` address plays the page's video.
|
|
230
|
+
* `add` returns at once and registers in the background (`ready` reports
|
|
231
|
+
* the answer); from then on the player calls `resolve` for every matching
|
|
232
|
+
* open, and the error a rejected `resolve` carries is what the user sees.
|
|
233
|
+
* ```ts
|
|
234
|
+
* plugin.resolvers.add({
|
|
235
|
+
* id: "example",
|
|
236
|
+
* schemes: ["https"],
|
|
237
|
+
* hosts: ["video.example.com"], // exact host names
|
|
238
|
+
* async resolve(url, signal) {
|
|
239
|
+
* const response = await fetch(url, { signal });
|
|
240
|
+
* if (!response.ok) throw new Error(`the page answered ${response.status}`);
|
|
241
|
+
* const page = (await response.json()) as { title: string; stream: string };
|
|
242
|
+
* return { kind: "media", originalUrl: url, title: page.title, primary: { url: page.stream } };
|
|
243
|
+
* },
|
|
244
|
+
* });
|
|
245
|
+
* ```
|
|
246
|
+
*
|
|
247
|
+
* @since 1.0.0
|
|
248
|
+
*/
|
|
249
|
+
add(options: ResolverOptions): Resolver;
|
|
250
|
+
/**
|
|
251
|
+
* The extensions some plugin's file resolver handles (SDK 1.5.8, player
|
|
252
|
+
* 0.4.2): lower case, without the dot, sorted, each once; not who
|
|
253
|
+
* registered them. Reading needs no capability; `[]` from older players.
|
|
254
|
+
* Without `events` it is the list from when the plugin first read it.
|
|
255
|
+
* Use it to accept such files beside the player's own media types, for
|
|
256
|
+
* example in a playlist's drop or folder scan.
|
|
257
|
+
*
|
|
258
|
+
* @example Accept files that a resolver plugin can play
|
|
259
|
+
* A plugin's own file filter also accepts types other plugins turn into
|
|
260
|
+
* streams. `fileTypes` lists the extensions every running file resolver
|
|
261
|
+
* claims (lower case, no dot); the SDK keeps it current with `events`.
|
|
262
|
+
* ```ts
|
|
263
|
+
* const MEDIA = ["mp4", "mkv", "mp3"];
|
|
264
|
+
* // Extensions compare in lower case, without the dot.
|
|
265
|
+
* const accepted = (path: string) => {
|
|
266
|
+
* const extension = path.split(".").pop()?.toLowerCase() ?? "";
|
|
267
|
+
* return MEDIA.includes(extension) || plugin.resolvers.fileTypes.includes(extension);
|
|
268
|
+
* };
|
|
269
|
+
* ```
|
|
270
|
+
*
|
|
271
|
+
* @capability None.
|
|
272
|
+
* @player 0.4.2
|
|
273
|
+
* @since 1.5.8
|
|
274
|
+
*/
|
|
275
|
+
readonly fileTypes: readonly string[];
|
|
276
|
+
/**
|
|
277
|
+
* {@link Resolvers.fileTypes} changed: a file resolver was added, or its
|
|
278
|
+
* plugin stopped. Needs `events`; without it the listener never fires.
|
|
279
|
+
* When the player starts a stopped plugin for this change (player
|
|
280
|
+
* 0.5.21), {@link Resolvers.fileTypes} already has the new list at start
|
|
281
|
+
* and the listener still hears the change (SDK 1.5.56; before, it did not
|
|
282
|
+
* run).
|
|
283
|
+
*
|
|
284
|
+
* @param listener - Receives the new list.
|
|
285
|
+
* @returns A handle that removes the listener.
|
|
286
|
+
*
|
|
287
|
+
* @example Say which file types became playable
|
|
288
|
+
* When a plugin with a file resolver starts or stops, the OSD lists the
|
|
289
|
+
* extra file types now accepted. The listener (which needs `events`)
|
|
290
|
+
* receives the new list each time it changes.
|
|
291
|
+
* ```ts
|
|
292
|
+
* plugin.resolvers.onFileTypesChange((types) => {
|
|
293
|
+
* void plugin.osd.show("Also accepted: {}", [plugin.i18n.list(types)]);
|
|
294
|
+
* });
|
|
295
|
+
* ```
|
|
296
|
+
*
|
|
297
|
+
* @capability `events`
|
|
298
|
+
* @player 0.4.2
|
|
299
|
+
* @since 1.5.8
|
|
300
|
+
*/
|
|
301
|
+
onFileTypesChange(listener: (types: string[]) => void): Disposable;
|
|
302
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import type { PlayerState } from "./playback.ts";
|
|
2
|
+
import type { SubtitleStyle } from "../../subtitles.ts";
|
|
3
|
+
import type { Disposable } from "./base.ts";
|
|
4
|
+
import type { Text } from "./ui-locale.ts";
|
|
5
|
+
/**
|
|
6
|
+
* A subtitle track of the current source.
|
|
7
|
+
*
|
|
8
|
+
* @since 1.0.0
|
|
9
|
+
* @category Subtitles
|
|
10
|
+
*/
|
|
11
|
+
export interface SubtitleTrack {
|
|
12
|
+
/** Stable while the track exists; compare tracks by id. */
|
|
13
|
+
id: string;
|
|
14
|
+
/** Inside the container, or loaded from a file. */
|
|
15
|
+
kind: "embedded" | "external";
|
|
16
|
+
/** The container's subtitle track number, for embedded tracks only. */
|
|
17
|
+
embeddedId?: number;
|
|
18
|
+
/** Track title. */
|
|
19
|
+
title: string;
|
|
20
|
+
/** Language tag, `null` when unknown. */
|
|
21
|
+
language: string | null;
|
|
22
|
+
/** {@link Subtitles.setStyle} applies to this track. */
|
|
23
|
+
styleSupported: boolean;
|
|
24
|
+
/** Why the style does not apply, `null` when it does. */
|
|
25
|
+
styleReason: string | null;
|
|
26
|
+
/** Loaded by this plugin, so `remove()` may delete it. */
|
|
27
|
+
owned: boolean;
|
|
28
|
+
/** The backend's codec name, e.g. "subrip", "ass", "hdmv_pgs_subtitle". */
|
|
29
|
+
codec: string | null;
|
|
30
|
+
/** Text cues (subrip, ass, ssa, webvtt, mov_text, text), not bitmaps. */
|
|
31
|
+
text: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* The container stream number (`ffmpeg -map 0:<n>`) of an embedded track,
|
|
34
|
+
* when the player can vouch for it; `null` for external tracks and network sources.
|
|
35
|
+
*/
|
|
36
|
+
streamIndex: number | null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The subtitle state of the current source.
|
|
40
|
+
*
|
|
41
|
+
* @see {@link Subtitles.state}
|
|
42
|
+
* @since 1.0.0
|
|
43
|
+
* @category Subtitles
|
|
44
|
+
*/
|
|
45
|
+
export interface SubtitlesState {
|
|
46
|
+
/** The source it belongs to ({@link PlayerState.sourceId}). */
|
|
47
|
+
readonly sourceId: number;
|
|
48
|
+
/** The source phase. */
|
|
49
|
+
readonly phase: string;
|
|
50
|
+
/** Every track. */
|
|
51
|
+
readonly tracks: SubtitleTrack[];
|
|
52
|
+
/** The primary subtitle, `null` when off. */
|
|
53
|
+
readonly selected: SubtitleTrack | null;
|
|
54
|
+
/** The secondary subtitle, shown together with `selected`. */
|
|
55
|
+
readonly secondary: SubtitleTrack | null;
|
|
56
|
+
/** Fonts a style can use (`fontId`). */
|
|
57
|
+
readonly fonts: {
|
|
58
|
+
/** Pass as {@link SubtitleStyle.fontId}. */
|
|
59
|
+
id: string;
|
|
60
|
+
/** Font family name for display. */
|
|
61
|
+
family: string;
|
|
62
|
+
}[];
|
|
63
|
+
/**
|
|
64
|
+
* The effective style: among the plugins that set a layer, the one whose
|
|
65
|
+
* manifest id sorts last (not the most recent call); `null` without one.
|
|
66
|
+
*/
|
|
67
|
+
readonly style: SubtitleStyle | null;
|
|
68
|
+
/** Whether the renderer confirmed the selection. */
|
|
69
|
+
readonly trackConfirmation: "waiting" | "applied" | "uncertain";
|
|
70
|
+
/** Whether the renderer confirmed the style. */
|
|
71
|
+
readonly styleConfirmation: "waiting" | "applied" | "uncertain";
|
|
72
|
+
/** The last error, `null` without one. */
|
|
73
|
+
readonly error: string | null;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Subtitle calls act on the selection you see; pass `ifCurrent` to pin an older one.
|
|
77
|
+
*
|
|
78
|
+
* @since 1.0.0
|
|
79
|
+
* @category Subtitles
|
|
80
|
+
*/
|
|
81
|
+
export interface SubtitleConditional {
|
|
82
|
+
/** The subtitle state the call is conditional on; `stale` otherwise. */
|
|
83
|
+
ifCurrent?: SubtitlesState;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* `plugin.subtitles`: tracks, uploads and style. Reading needs
|
|
87
|
+
* `subtitles.read`; changes need `subtitles.control` and also
|
|
88
|
+
* `subtitles.read`, since they read the current selection first.
|
|
89
|
+
*
|
|
90
|
+
* @example Load an SRT file as the secondary subtitle
|
|
91
|
+
* An English SRT file shows as a second subtitle line next to the
|
|
92
|
+
* film's own subtitles, in white with an outline. The plugin reads the
|
|
93
|
+
* file and uploads its bytes with `load`, which adds a track to the
|
|
94
|
+
* current source and selects it as the secondary subtitle; `refresh`
|
|
95
|
+
* reads the subtitle state for its font list, and `setStyle` sends this
|
|
96
|
+
* plugin's style layer naming one of those fonts.
|
|
97
|
+
* ```ts
|
|
98
|
+
* import { readFile } from "node:fs/promises";
|
|
99
|
+
* declare const path: string;
|
|
100
|
+
* // ---cut---
|
|
101
|
+
* const bytes = await readFile(path);
|
|
102
|
+
* await plugin.subtitles.load(bytes, { title: "English", select: "secondary" });
|
|
103
|
+
* const { fonts } = await plugin.subtitles.refresh();
|
|
104
|
+
* if (!fonts.length) return;
|
|
105
|
+
* await plugin.subtitles.setStyle({
|
|
106
|
+
* fontId: fonts[0]!.id,
|
|
107
|
+
* fontSize: 40, // at the 1080p reference height
|
|
108
|
+
* color: "white",
|
|
109
|
+
* outline: 2,
|
|
110
|
+
* marginPercent: 5,
|
|
111
|
+
* offsetMs: 0,
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @remarks
|
|
116
|
+
* The subtitle tracks of the current source, the primary and secondary
|
|
117
|
+
* selection, uploaded files and the style. `state` is the SDK's snapshot of
|
|
118
|
+
* the player's subtitle state (`null` until first read). The player has no
|
|
119
|
+
* subtitle event: the SDK reads the state again when the source, its phase
|
|
120
|
+
* or the backend changes (with `events`) and after this plugin's own
|
|
121
|
+
* changes, so a selection the user or another plugin changed shows only
|
|
122
|
+
* after `refresh()`. A change without `ifCurrent` reads the state first
|
|
123
|
+
* and applies to it; pass `ifCurrent` to make it fail with `stale` when the
|
|
124
|
+
* selection changed since that state. Each change is one operation the
|
|
125
|
+
* player confirms; `select`, `remove` and `setStyle` resolve with the new
|
|
126
|
+
* state, `load` with the new track.
|
|
127
|
+
*
|
|
128
|
+
* @capability `subtitles.read` to read; `subtitles.control` and
|
|
129
|
+
* `subtitles.read` to change; `events` to re-read on source changes.
|
|
130
|
+
*
|
|
131
|
+
* @see [Load subtitles from a plugin](../../../docs/how-to/subtitles.md)
|
|
132
|
+
* @since 1.0.0
|
|
133
|
+
* @category Subtitles
|
|
134
|
+
*/
|
|
135
|
+
export interface Subtitles {
|
|
136
|
+
/** `null` until first read. */
|
|
137
|
+
readonly state: SubtitlesState | null;
|
|
138
|
+
/**
|
|
139
|
+
* The subtitle state changed.
|
|
140
|
+
*
|
|
141
|
+
* @capability events and subtitles.read
|
|
142
|
+
*
|
|
143
|
+
* @example Show the subtitle language after a new file opens
|
|
144
|
+
* When a new file starts, the OSD names the language of its primary
|
|
145
|
+
* subtitle. The SDK reads the subtitle state again when the source or its
|
|
146
|
+
* phase changes (there is no subtitle event, so a selection changed in the
|
|
147
|
+
* player shows only after `refresh()`) and then calls the listener;
|
|
148
|
+
* `selected` is `null` when subtitles are off.
|
|
149
|
+
* ```ts
|
|
150
|
+
* plugin.subtitles.onChange((state) => {
|
|
151
|
+
* // A track's language is null when the file does not say.
|
|
152
|
+
* void plugin.osd.show("Subtitles: {}", [state.selected?.language ?? "off"]);
|
|
153
|
+
* });
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* @since 1.0.0
|
|
157
|
+
*/
|
|
158
|
+
onChange(listener: (state: SubtitlesState) => void): Disposable;
|
|
159
|
+
/**
|
|
160
|
+
* Read the state from the player now.
|
|
161
|
+
*
|
|
162
|
+
* @capability subtitles.read
|
|
163
|
+
* @throws `capability` (rejects) The manifest does not declare
|
|
164
|
+
* `subtitles.read`.
|
|
165
|
+
*
|
|
166
|
+
* @example Count the subtitle tracks of the file
|
|
167
|
+
* The plugin reads how many subtitle tracks the file has before building a
|
|
168
|
+
* menu. `refresh` asks the player and resolves with the current state, also
|
|
169
|
+
* without `events`; `state` holds it afterwards.
|
|
170
|
+
* ```ts
|
|
171
|
+
* const { tracks } = await plugin.subtitles.refresh();
|
|
172
|
+
* await plugin.osd.show("{} subtitle tracks", [tracks.length]);
|
|
173
|
+
* ```
|
|
174
|
+
*
|
|
175
|
+
* @since 1.0.0
|
|
176
|
+
*/
|
|
177
|
+
refresh(): Promise<SubtitlesState>;
|
|
178
|
+
/**
|
|
179
|
+
* `role: "secondary"` sets the secondary subtitle: a text track that is not
|
|
180
|
+
* the primary one (`invalid` otherwise). A new source clears it.
|
|
181
|
+
* `track: null` turns the role off.
|
|
182
|
+
*
|
|
183
|
+
* @capability subtitles.control and subtitles.read
|
|
184
|
+
* @throws `stale` (rejects) With `ifCurrent`: the source or the subtitle
|
|
185
|
+
* selection changed since that state.
|
|
186
|
+
* @throws `invalid` (rejects) An unknown track; as secondary, a bitmap
|
|
187
|
+
* track or the primary one; as primary, the current secondary.
|
|
188
|
+
* @throws `missing` (rejects) The track is not in the current source.
|
|
189
|
+
* @throws `unavailable` (rejects) Nothing loaded, or the source is still
|
|
190
|
+
* loading or not yet confirmed.
|
|
191
|
+
* @throws `busy` (rejects) Too many subtitle operations at once.
|
|
192
|
+
* @throws `capability` (rejects) The manifest does not declare
|
|
193
|
+
* `subtitles.control` and `subtitles.read`.
|
|
194
|
+
*
|
|
195
|
+
* @example Turn on the first English subtitle
|
|
196
|
+
* The first English track becomes the primary subtitle, but only in the
|
|
197
|
+
* file the plugin looked at. Embedded tracks are chosen by number, so
|
|
198
|
+
* without `ifCurrent` a select after another file opened would pick that
|
|
199
|
+
* file's track with the same number; with `ifCurrent: state` it fails with
|
|
200
|
+
* `stale` instead. Without `ifCurrent`, `select` reads the newest state
|
|
201
|
+
* itself and almost never fails with `stale`.
|
|
202
|
+
* ```ts
|
|
203
|
+
* const state = await plugin.subtitles.refresh();
|
|
204
|
+
* const english = state.tracks.find((track) => track.language === "en");
|
|
205
|
+
* if (english)
|
|
206
|
+
* await plugin.subtitles.select(english, { ifCurrent: state }).catch((error: PluginError) => {
|
|
207
|
+
* if (error.code !== "stale") throw error; // another file or selection now
|
|
208
|
+
* });
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* @since 1.0.0
|
|
212
|
+
*/
|
|
213
|
+
select(track: SubtitleTrack | null, options?: SubtitleConditional & {
|
|
214
|
+
role?: "primary" | "secondary";
|
|
215
|
+
}): Promise<SubtitlesState>;
|
|
216
|
+
/**
|
|
217
|
+
* Upload a subtitle file's bytes (UTF-8 SRT, or ASS/SSA with
|
|
218
|
+
* `format: "ass"`) for the current source; select it unless
|
|
219
|
+
* `select: "none"`. `title` (1–200 characters) names the track: data, or
|
|
220
|
+
* a {@link Text} the player translates (`text("{} · {}", [text("Simplified
|
|
221
|
+
* Chinese"), file])`, SDK 1.5.11). Aborting
|
|
222
|
+
* `signal` before the commit discards the upload (rejects with AbortError);
|
|
223
|
+
* once the commit was sent it completes.
|
|
224
|
+
*
|
|
225
|
+
* Limits: SRT ≤ 2 MiB and ≤ 10,000 cues; ASS ≤ 2 MiB with `[Script Info]`
|
|
226
|
+
* and `[Events]` and 1–20,000 `Dialogue:` lines. Convert other formats
|
|
227
|
+
* (VTT, SAMI) to SRT first. Per source, a plugin has at most 4 loaded
|
|
228
|
+
* tracks at once and loads at most 16 files (removed ones count), and
|
|
229
|
+
* every plugin together at most 16 tracks; see `SUBTITLE_LIMITS` in
|
|
230
|
+
* `@vestra-player/sdk/testing`.
|
|
231
|
+
*
|
|
232
|
+
* @capability subtitles.control and subtitles.read
|
|
233
|
+
* @throws `invalid` (rejects) A bad `format` or `title`, or a file over the
|
|
234
|
+
* limits.
|
|
235
|
+
* @throws `stale` (rejects) With `ifCurrent`: the source changed since
|
|
236
|
+
* that state.
|
|
237
|
+
* @throws `unavailable` (rejects) Nothing loaded, or the source is still
|
|
238
|
+
* loading.
|
|
239
|
+
* @throws `aborted` (rejects) `signal` aborted before the commit (an
|
|
240
|
+
* `AbortError`); the upload is discarded.
|
|
241
|
+
* @throws `busy` (rejects) Too many subtitle operations at once, or a
|
|
242
|
+
* limit of `SUBTITLE_LIMITS` is reached (4 tracks of this plugin, 16
|
|
243
|
+
* loads of this plugin or 16 tracks in the source, or another of its
|
|
244
|
+
* limits); nothing is loaded.
|
|
245
|
+
* @throws `capability` (rejects) The manifest does not declare
|
|
246
|
+
* `subtitles.control` and `subtitles.read`.
|
|
247
|
+
*
|
|
248
|
+
* @example Load a downloaded SRT and select it
|
|
249
|
+
* A subtitle file the plugin downloaded becomes a track of the current file
|
|
250
|
+
* and is selected. The plugin passes the file's bytes; the player parses
|
|
251
|
+
* them, adds an `external` track for this source only and resolves with
|
|
252
|
+
* it once the upload is committed.
|
|
253
|
+
* ```ts
|
|
254
|
+
* declare const url: string;
|
|
255
|
+
* // ---cut---
|
|
256
|
+
* const response = await fetch(url);
|
|
257
|
+
* if (!response.ok) throw new Error(`subtitles: HTTP ${response.status}`);
|
|
258
|
+
* const bytes = new Uint8Array(await response.arrayBuffer());
|
|
259
|
+
* const track = await plugin.subtitles.load(bytes, { title: "Downloaded" }); // selected
|
|
260
|
+
* await plugin.osd.show("Loaded {}", [track.title]);
|
|
261
|
+
* ```
|
|
262
|
+
*
|
|
263
|
+
* @since 1.0.0
|
|
264
|
+
*/
|
|
265
|
+
load(bytes: Uint8Array, options?: SubtitleConditional & {
|
|
266
|
+
format?: "srt" | "ass";
|
|
267
|
+
title?: string | Text;
|
|
268
|
+
select?: "primary" | "secondary" | "none";
|
|
269
|
+
signal?: AbortSignal;
|
|
270
|
+
}): Promise<SubtitleTrack>;
|
|
271
|
+
/**
|
|
272
|
+
* Remove a track this plugin loaded.
|
|
273
|
+
*
|
|
274
|
+
* @capability subtitles.control and subtitles.read
|
|
275
|
+
* @throws `invalid` (rejects) The track was not loaded by this plugin.
|
|
276
|
+
* @throws `stale` (rejects) With `ifCurrent`: the source changed since
|
|
277
|
+
* that state.
|
|
278
|
+
* @throws `unavailable` (rejects) Nothing is loaded, or the source is
|
|
279
|
+
* still loading.
|
|
280
|
+
* @throws `busy` (rejects) Too many subtitle operations at once.
|
|
281
|
+
* @throws `capability` (rejects) The manifest does not declare
|
|
282
|
+
* `subtitles.control` and `subtitles.read`.
|
|
283
|
+
*
|
|
284
|
+
* @example Remove the subtitle the plugin loaded
|
|
285
|
+
* The plugin's downloaded subtitle disappears from the track list. A plugin
|
|
286
|
+
* can remove only tracks it loaded itself; a new source removes them
|
|
287
|
+
* anyway.
|
|
288
|
+
* ```ts
|
|
289
|
+
* declare const loaded: SubtitleTrack;
|
|
290
|
+
* // ---cut---
|
|
291
|
+
* await plugin.subtitles.remove(loaded);
|
|
292
|
+
* ```
|
|
293
|
+
*
|
|
294
|
+
* @since 1.0.0
|
|
295
|
+
*/
|
|
296
|
+
remove(track: SubtitleTrack, options?: SubtitleConditional): Promise<SubtitlesState>;
|
|
297
|
+
/**
|
|
298
|
+
* Set this plugin's style layer; `null` removes it. The newest call of
|
|
299
|
+
* this plugin replaces its earlier layer. When several plugins have a
|
|
300
|
+
* layer, the player uses the one whose manifest id sorts last, whatever
|
|
301
|
+
* the order of the calls.
|
|
302
|
+
*
|
|
303
|
+
* @capability subtitles.control and subtitles.read
|
|
304
|
+
* @throws `invalid` (rejects) A field out of range.
|
|
305
|
+
* @throws `unsupported` (rejects) A font that is not in `state.fonts`, or a
|
|
306
|
+
* primary subtitle that is a bitmap track.
|
|
307
|
+
* @throws `stale` (rejects) With `ifCurrent`: the subtitle state changed
|
|
308
|
+
* since that state.
|
|
309
|
+
* @throws `unavailable` (rejects) Nothing is loaded, or the source is
|
|
310
|
+
* still loading.
|
|
311
|
+
* @throws `busy` (rejects) Too many subtitle operations at once.
|
|
312
|
+
* @throws `capability` (rejects) The manifest does not declare
|
|
313
|
+
* `subtitles.control` and `subtitles.read`.
|
|
314
|
+
*
|
|
315
|
+
* @example Take the plugin's style off again
|
|
316
|
+
* The plugin removes its style layer, so the subtitles go back to the
|
|
317
|
+
* player's default (or to another plugin's layer). `null` removes only this
|
|
318
|
+
* plugin's layer; the effective layer is the one whose manifest id sorts
|
|
319
|
+
* last among the plugins that still have one.
|
|
320
|
+
* ```ts
|
|
321
|
+
* await plugin.subtitles.setStyle(null);
|
|
322
|
+
* ```
|
|
323
|
+
*
|
|
324
|
+
* @since 1.0.0
|
|
325
|
+
*/
|
|
326
|
+
setStyle(style: SubtitleStyle | null, options?: SubtitleConditional): Promise<SubtitlesState>;
|
|
327
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|