@vestra-player/sdk 1.11.2 → 1.11.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 +4 -0
- package/dist/docs-tree.json.gz +0 -0
- package/dist/plugin/connection.d.ts +7 -0
- package/dist/plugin/connection.js +9 -0
- package/dist/plugin/media.js +4 -2
- package/dist/plugin/player.d.ts +32 -3
- package/dist/plugin/player.js +88 -29
- package/dist/plugin/subtitles.js +25 -10
- package/dist/plugin/types/playback.d.ts +20 -15
- package/llms.txt +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.11.3
|
|
4
|
+
|
|
5
|
+
Nobody must change anything. A control without `ifCurrent` (pause, seek, speed, restart, close, a step, a loop, an audio track), a capture and a scrub now act on the current state: while a stream (or anything else that holds `source.state`) keeps `player.state` current, nothing changes; otherwise the SDK reads the state first, so a plugin that read the state once and keeps no stream is no longer refused with `stale` after any pause, seek or new file by someone else. Calls made together share one read and go out in the order they were made; `stale` still comes when the source changes between that read and the call, and an explicit `ifCurrent` is sent as given. The `stale` todos of the `menus`, `adjust-panel` and `three-ways` examples pass, and the golden traces of `examples/menus` and `examples/adjust-panel` gain that read (with the speed now applied) instead of listing `stale`.
|
|
6
|
+
|
|
3
7
|
## 1.11.2
|
|
4
8
|
|
|
5
9
|
Additions and fixes only; nobody must change anything except a plugin test that relies on a host error the plugin does not handle (below).
|
package/dist/docs-tree.json.gz
CHANGED
|
Binary file
|
|
@@ -194,6 +194,13 @@ export declare class Connection {
|
|
|
194
194
|
* once more here.
|
|
195
195
|
*/
|
|
196
196
|
follow(event: string, why?: Why): Disposable;
|
|
197
|
+
/**
|
|
198
|
+
* Whether `event` is subscribed at the player now: something holds it
|
|
199
|
+
* (a listener, a hold, a stream, a handle that follows the source), so a
|
|
200
|
+
* state copy kept by it follows the player's events. False while a
|
|
201
|
+
* held-only group waits for a holder, and when nothing started it.
|
|
202
|
+
*/
|
|
203
|
+
following(event: string): boolean;
|
|
197
204
|
/**
|
|
198
205
|
* A binding (or a command's function field) reads `event`'s state: its
|
|
199
206
|
* reason joins what the player is told while a plugin listener, hold or
|
|
@@ -452,6 +452,15 @@ export class Connection {
|
|
|
452
452
|
follow(event, why) {
|
|
453
453
|
return this.#hold(event, why, "never");
|
|
454
454
|
}
|
|
455
|
+
/**
|
|
456
|
+
* Whether `event` is subscribed at the player now: something holds it
|
|
457
|
+
* (a listener, a hold, a stream, a handle that follows the source), so a
|
|
458
|
+
* state copy kept by it follows the player's events. False while a
|
|
459
|
+
* held-only group waits for a holder, and when nothing started it.
|
|
460
|
+
*/
|
|
461
|
+
following(event) {
|
|
462
|
+
return this.#events.get(event)?.off !== undefined;
|
|
463
|
+
}
|
|
455
464
|
#hold(event, why, catchUp, listens = true) {
|
|
456
465
|
const group = this.#events.get(event);
|
|
457
466
|
if (!group)
|
package/dist/plugin/media.js
CHANGED
|
@@ -261,7 +261,8 @@ export function mediaCapture(scope) {
|
|
|
261
261
|
const service = serviceOf(runtime);
|
|
262
262
|
const player = playerOf(runtime);
|
|
263
263
|
// The source now: a capture needs one, even from a plugin that never
|
|
264
|
-
// read the state
|
|
264
|
+
// read the state; read first when the copy does not follow the
|
|
265
|
+
// player (`PlayerService.current`).
|
|
265
266
|
const at = options.ifCurrent ?? (await player.current());
|
|
266
267
|
const { expected } = player.expected(at);
|
|
267
268
|
if (!expected)
|
|
@@ -444,7 +445,8 @@ function mediaSources(scope) {
|
|
|
444
445
|
const expected = options?.ifCurrent === undefined
|
|
445
446
|
? undefined
|
|
446
447
|
: playerOf(scope.runtime).expected(options.ifCurrent).expected;
|
|
447
|
-
|
|
448
|
+
// In its turn among the plugin's calls on the source.
|
|
449
|
+
return playerOf(scope.runtime).inTurn(() => host().remember(expected));
|
|
448
450
|
},
|
|
449
451
|
get: async (value) => host().get(token(value)),
|
|
450
452
|
locate: async (value) => host().locate(token(value)),
|
package/dist/plugin/player.d.ts
CHANGED
|
@@ -42,8 +42,6 @@ export declare class PlayerService implements StreamSource {
|
|
|
42
42
|
* a read that failed is tried again by the next call.
|
|
43
43
|
*/
|
|
44
44
|
read(): Promise<void>;
|
|
45
|
-
/** Whether the mirror is registered yet. */
|
|
46
|
-
get started(): boolean;
|
|
47
45
|
/**
|
|
48
46
|
* Register the SDK's copy of the state (a mirror of `source.state`; a
|
|
49
47
|
* plugin listens through `watch`, `follow` and `player.on`). It hears
|
|
@@ -52,8 +50,23 @@ export declare class PlayerService implements StreamSource {
|
|
|
52
50
|
* starts. Resolves at once.
|
|
53
51
|
*/
|
|
54
52
|
start(): Promise<void>;
|
|
55
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* The state as the player has it now, for a call that acts on the
|
|
55
|
+
* current state (a capture): the copy as it is while it follows the
|
|
56
|
+
* player's events, else read first ({@link fresh}).
|
|
57
|
+
*/
|
|
56
58
|
current(): Promise<PlayerState>;
|
|
59
|
+
/**
|
|
60
|
+
* Wait until the copy is the player's current state, for a call that
|
|
61
|
+
* acts on it (a control, a step, a capture, a scrub). While something
|
|
62
|
+
* holds `source.state` the copy follows the player's events: nothing to
|
|
63
|
+
* wait for. Otherwise it is the newest snapshot the plugin has, which an
|
|
64
|
+
* admitted intent since (a pause, a seek, a new file, by anyone) made
|
|
65
|
+
* stale: it is read first. Calls in a burst share one read ({@link inTurn}
|
|
66
|
+
* keeps their order). A read that fails leaves the copy as it was; the
|
|
67
|
+
* call goes on with it.
|
|
68
|
+
*/
|
|
69
|
+
fresh(): Promise<void> | undefined;
|
|
57
70
|
/** Drop anything older than what was already delivered. */
|
|
58
71
|
accept(raw: SourceState): void;
|
|
59
72
|
/**
|
|
@@ -113,6 +126,22 @@ export declare class PlayerService implements StreamSource {
|
|
|
113
126
|
expected(state: PlayerState | undefined): {
|
|
114
127
|
expected?: SourceStamp;
|
|
115
128
|
};
|
|
129
|
+
/**
|
|
130
|
+
* Send a call in its turn among the plugin's calls on the source: at
|
|
131
|
+
* once (in the same tick) when no read is on its way, else right after
|
|
132
|
+
* that read, with the calls that waited for it in the order they were
|
|
133
|
+
* made. `read`: the call acts on the current state, so a read starts
|
|
134
|
+
* first when the copy does not follow the player ({@link fresh}).
|
|
135
|
+
*/
|
|
136
|
+
inTurn<T>(send: () => Promise<T>, read?: boolean): Promise<T>;
|
|
137
|
+
/**
|
|
138
|
+
* `send` with the stamp a call sends, in its turn ({@link inTurn}):
|
|
139
|
+
* `ifCurrent`'s when given (as it is), else the current state's, read
|
|
140
|
+
* first when the copy does not follow the player.
|
|
141
|
+
*/
|
|
142
|
+
withStamp<T>(ifCurrent: PlayerState | undefined, send: (stamp: {
|
|
143
|
+
expected?: SourceStamp;
|
|
144
|
+
}) => Promise<T>): Promise<T>;
|
|
116
145
|
control(intent: SourceIntent, options?: Conditional): Promise<void>;
|
|
117
146
|
/** Close only if `generation` is still the player's source. */
|
|
118
147
|
closeIfCurrent(generation: number): Promise<void>;
|
package/dist/plugin/player.js
CHANGED
|
@@ -175,6 +175,10 @@ export class PlayerService {
|
|
|
175
175
|
#started = false;
|
|
176
176
|
/** `read()`'s one read, once asked for. */
|
|
177
177
|
#read;
|
|
178
|
+
/** The read that calls acting on the current state wait for (`fresh`). */
|
|
179
|
+
#fresh;
|
|
180
|
+
/** The sends waiting for that read, in the order they were made (`inTurn`). */
|
|
181
|
+
#waiting = [];
|
|
178
182
|
output;
|
|
179
183
|
constructor(runtime) {
|
|
180
184
|
this.runtime = runtime;
|
|
@@ -211,10 +215,6 @@ export class PlayerService {
|
|
|
211
215
|
}
|
|
212
216
|
})());
|
|
213
217
|
}
|
|
214
|
-
/** Whether the mirror is registered yet. */
|
|
215
|
-
get started() {
|
|
216
|
-
return this.#started;
|
|
217
|
-
}
|
|
218
218
|
/**
|
|
219
219
|
* Register the SDK's copy of the state (a mirror of `source.state`; a
|
|
220
220
|
* plugin listens through `watch`, `follow` and `player.on`). It hears
|
|
@@ -229,11 +229,45 @@ export class PlayerService {
|
|
|
229
229
|
this.runtime.on("source.state", (data) => this.accept(data), "held", true);
|
|
230
230
|
return Promise.resolve();
|
|
231
231
|
}
|
|
232
|
-
/**
|
|
232
|
+
/**
|
|
233
|
+
* The state as the player has it now, for a call that acts on the
|
|
234
|
+
* current state (a capture): the copy as it is while it follows the
|
|
235
|
+
* player's events, else read first ({@link fresh}).
|
|
236
|
+
*/
|
|
233
237
|
async current() {
|
|
234
238
|
await this.start();
|
|
239
|
+
const fresh = this.fresh();
|
|
240
|
+
if (fresh)
|
|
241
|
+
await fresh;
|
|
235
242
|
return this.state;
|
|
236
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* Wait until the copy is the player's current state, for a call that
|
|
246
|
+
* acts on it (a control, a step, a capture, a scrub). While something
|
|
247
|
+
* holds `source.state` the copy follows the player's events: nothing to
|
|
248
|
+
* wait for. Otherwise it is the newest snapshot the plugin has, which an
|
|
249
|
+
* admitted intent since (a pause, a seek, a new file, by anyone) made
|
|
250
|
+
* stale: it is read first. Calls in a burst share one read ({@link inTurn}
|
|
251
|
+
* keeps their order). A read that fails leaves the copy as it was; the
|
|
252
|
+
* call goes on with it.
|
|
253
|
+
*/
|
|
254
|
+
fresh() {
|
|
255
|
+
if (this.#fresh)
|
|
256
|
+
return this.#fresh;
|
|
257
|
+
// Note: `following` stays true when the subscription failed (its
|
|
258
|
+
// `off` is then a rejected promise); the copy is then sent as it is.
|
|
259
|
+
if (this.runtime.following("source.state"))
|
|
260
|
+
return undefined;
|
|
261
|
+
const fresh = this.refresh().then(() => { }, () => { });
|
|
262
|
+
// Once read: cleared, then the waiting sends go out in one go, in the
|
|
263
|
+
// order they were made; a call after them starts a read of its own.
|
|
264
|
+
this.#fresh = fresh.then(() => {
|
|
265
|
+
this.#fresh = undefined;
|
|
266
|
+
for (const send of this.#waiting.splice(0))
|
|
267
|
+
send();
|
|
268
|
+
});
|
|
269
|
+
return this.#fresh;
|
|
270
|
+
}
|
|
237
271
|
/** Drop anything older than what was already delivered. */
|
|
238
272
|
accept(raw) {
|
|
239
273
|
if (raw.eventSequence < this.raw.eventSequence)
|
|
@@ -394,12 +428,38 @@ export class PlayerService {
|
|
|
394
428
|
const raw = raws.get(state ?? this.state);
|
|
395
429
|
return raw && raw.eventSequence >= 0 ? { expected: raw.stamp } : {};
|
|
396
430
|
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
431
|
+
/**
|
|
432
|
+
* Send a call in its turn among the plugin's calls on the source: at
|
|
433
|
+
* once (in the same tick) when no read is on its way, else right after
|
|
434
|
+
* that read, with the calls that waited for it in the order they were
|
|
435
|
+
* made. `read`: the call acts on the current state, so a read starts
|
|
436
|
+
* first when the copy does not follow the player ({@link fresh}).
|
|
437
|
+
*/
|
|
438
|
+
inTurn(send, read = false) {
|
|
439
|
+
if (!(read ? this.fresh() : this.#fresh))
|
|
440
|
+
return send();
|
|
441
|
+
return new Promise((resolve, reject) => {
|
|
442
|
+
this.#waiting.push(() => {
|
|
443
|
+
try {
|
|
444
|
+
resolve(send());
|
|
445
|
+
}
|
|
446
|
+
catch (error) {
|
|
447
|
+
reject(error);
|
|
448
|
+
}
|
|
449
|
+
});
|
|
401
450
|
});
|
|
402
451
|
}
|
|
452
|
+
/**
|
|
453
|
+
* `send` with the stamp a call sends, in its turn ({@link inTurn}):
|
|
454
|
+
* `ifCurrent`'s when given (as it is), else the current state's, read
|
|
455
|
+
* first when the copy does not follow the player.
|
|
456
|
+
*/
|
|
457
|
+
withStamp(ifCurrent, send) {
|
|
458
|
+
return this.inTurn(() => send(this.expected(ifCurrent)), !ifCurrent);
|
|
459
|
+
}
|
|
460
|
+
async control(intent, options) {
|
|
461
|
+
await this.withStamp(options?.ifCurrent, (stamp) => this.submit({ ...intent, ...stamp }));
|
|
462
|
+
}
|
|
403
463
|
/** Close only if `generation` is still the player's source. */
|
|
404
464
|
async closeIfCurrent(generation) {
|
|
405
465
|
const raw = this.runtime.reads
|
|
@@ -500,14 +560,14 @@ class ScrubHandle {
|
|
|
500
560
|
#service;
|
|
501
561
|
constructor(service) {
|
|
502
562
|
this.#service = service;
|
|
503
|
-
// A scrub follows the source. When
|
|
504
|
-
//
|
|
505
|
-
//
|
|
506
|
-
|
|
507
|
-
const fresh = service.
|
|
508
|
-
let ready = !
|
|
563
|
+
// A scrub follows the source. When the copy did not follow it yet (the
|
|
564
|
+
// mirror starts now, or nothing held `source.state`), the gesture
|
|
565
|
+
// starts from the state read now, not from the plugin's old copy.
|
|
566
|
+
void service.start();
|
|
567
|
+
const fresh = service.fresh();
|
|
568
|
+
let ready = !fresh;
|
|
509
569
|
this.#allowed = { ...service.raw.stamp };
|
|
510
|
-
if (
|
|
570
|
+
if (fresh)
|
|
511
571
|
void fresh.then(() => {
|
|
512
572
|
ready = true;
|
|
513
573
|
if (this.#active && !this.#pending)
|
|
@@ -521,7 +581,7 @@ class ScrubHandle {
|
|
|
521
581
|
this.end();
|
|
522
582
|
});
|
|
523
583
|
this.#queue = new Latest(async ({ seconds, keyframes }) => {
|
|
524
|
-
if (
|
|
584
|
+
if (fresh)
|
|
525
585
|
await fresh;
|
|
526
586
|
if (!this.#active)
|
|
527
587
|
throw superseded;
|
|
@@ -743,12 +803,15 @@ export function player(scope) {
|
|
|
743
803
|
throw abortError();
|
|
744
804
|
let ticket;
|
|
745
805
|
try {
|
|
746
|
-
|
|
806
|
+
// In its turn: after a read on its way for earlier controls.
|
|
807
|
+
ticket = await service().inTurn(() => service().submit({
|
|
747
808
|
kind: "open",
|
|
748
809
|
source,
|
|
749
810
|
startPaused: options.paused ?? false,
|
|
750
|
-
...(options.ifCurrent
|
|
751
|
-
|
|
811
|
+
...(options.ifCurrent
|
|
812
|
+
? service().expected(options.ifCurrent)
|
|
813
|
+
: {}),
|
|
814
|
+
}, { signal, accepted: (accepted) => (ticket = accepted) }));
|
|
752
815
|
}
|
|
753
816
|
catch (error) {
|
|
754
817
|
// Cancelling a pending open (e.g. a URL still being resolved) closes it.
|
|
@@ -815,8 +878,7 @@ export function player(scope) {
|
|
|
815
878
|
};
|
|
816
879
|
},
|
|
817
880
|
async addAudioTrack(path, options = {}) {
|
|
818
|
-
const
|
|
819
|
-
const added = await scope.runtime.host.audio.add(path, options.select ?? true, expected);
|
|
881
|
+
const added = await service().withStamp(options.ifCurrent, ({ expected }) => scope.runtime.host.audio.add(path, options.select ?? true, expected));
|
|
820
882
|
await service()
|
|
821
883
|
.refresh()
|
|
822
884
|
.catch(() => { });
|
|
@@ -827,8 +889,7 @@ export function player(scope) {
|
|
|
827
889
|
throw failure("invalid", "unit is frame or keyframe");
|
|
828
890
|
if (direction !== "backward" && direction !== "forward")
|
|
829
891
|
throw failure("invalid", "direction is backward or forward");
|
|
830
|
-
|
|
831
|
-
await scope.runtime.host.step.step(unit, direction, expected);
|
|
892
|
+
await service().withStamp(options.ifCurrent, ({ expected }) => scope.runtime.host.step.step(unit, direction, expected));
|
|
832
893
|
await service()
|
|
833
894
|
.refresh()
|
|
834
895
|
.catch(() => { });
|
|
@@ -868,19 +929,17 @@ export function player(scope) {
|
|
|
868
929
|
(!Number.isInteger(count) || count < 1 || count > 1_000_000))
|
|
869
930
|
throw failure("invalid", "count must be an integer 1–1000000");
|
|
870
931
|
}
|
|
871
|
-
|
|
872
|
-
await scope.runtime.host.marks.setLoop(loop && {
|
|
932
|
+
await service().withStamp(options.ifCurrent, ({ expected }) => scope.runtime.host.marks.setLoop(loop && {
|
|
873
933
|
a: loop.a,
|
|
874
934
|
b: loop.b,
|
|
875
935
|
...(loop.count === undefined ? {} : { count: loop.count }),
|
|
876
|
-
}, expected);
|
|
936
|
+
}, expected));
|
|
877
937
|
await service()
|
|
878
938
|
.refresh()
|
|
879
939
|
.catch(() => { });
|
|
880
940
|
},
|
|
881
941
|
async selectAudioTrack(id, options = {}) {
|
|
882
|
-
|
|
883
|
-
await scope.runtime.host.audio.select(id, expected);
|
|
942
|
+
await service().withStamp(options.ifCurrent, ({ expected }) => scope.runtime.host.audio.select(id, expected));
|
|
884
943
|
return service().refresh();
|
|
885
944
|
},
|
|
886
945
|
};
|
package/dist/plugin/subtitles.js
CHANGED
|
@@ -3,6 +3,7 @@ import { createHash } from "node:crypto";
|
|
|
3
3
|
import { isTextValue, textProblem } from "../i18n.js";
|
|
4
4
|
import { Latest } from "./latest.js";
|
|
5
5
|
import { abortError, failure, sleep, uncertain } from "./errors.js";
|
|
6
|
+
import { playerOf } from "./player.js";
|
|
6
7
|
/**
|
|
7
8
|
* The player's limits on subtitle files a plugin loads with
|
|
8
9
|
* {@link Subtitles.load}, which `TestHost` enforces with the player's codes.
|
|
@@ -98,13 +99,12 @@ class SubtitleService {
|
|
|
98
99
|
}, "held", true);
|
|
99
100
|
runtime.on("playback.backend", () => void this.refresh().catch(() => { }), "held", true);
|
|
100
101
|
this.style = new Latest(async ({ style, options }) => {
|
|
101
|
-
|
|
102
|
-
await this.#mutate(++this.#operation, (operationId) => runtime.host.subtitles.style({
|
|
102
|
+
await this.inTurn(options, (expected) => this.#mutate(++this.#operation, (operationId) => runtime.host.subtitles.style({
|
|
103
103
|
operationId,
|
|
104
104
|
revision: ++this.#styleRevision,
|
|
105
105
|
expected,
|
|
106
106
|
style,
|
|
107
|
-
}));
|
|
107
|
+
})));
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
110
|
watch(watcher) {
|
|
@@ -208,12 +208,28 @@ class SubtitleService {
|
|
|
208
208
|
}
|
|
209
209
|
/** Default: the selection as it is now. `ifCurrent` pins an older one. */
|
|
210
210
|
async expected(options) {
|
|
211
|
-
const pinned =
|
|
211
|
+
const pinned = this.#pinned(options);
|
|
212
212
|
if (pinned)
|
|
213
|
-
return pinned
|
|
213
|
+
return pinned;
|
|
214
214
|
await this.refresh();
|
|
215
215
|
return this.raw.selection.stamp;
|
|
216
216
|
}
|
|
217
|
+
#pinned(options) {
|
|
218
|
+
const pinned = options?.ifCurrent && raws.get(options.ifCurrent);
|
|
219
|
+
return pinned ? pinned.selection.stamp : undefined;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* `send` with the selection stamp ({@link expected}), in its turn among
|
|
223
|
+
* the plugin's calls on the source (`PlayerService.inTurn`): its first
|
|
224
|
+
* request goes out in the same tick, or right after a read of the source
|
|
225
|
+
* on its way for an earlier control.
|
|
226
|
+
*/
|
|
227
|
+
inTurn(options, send) {
|
|
228
|
+
return playerOf(this.#runtime).inTurn(() => {
|
|
229
|
+
const pinned = this.#pinned(options);
|
|
230
|
+
return pinned ? send(pinned) : this.expected(options).then(send);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
217
233
|
nextOperation() {
|
|
218
234
|
return ++this.#operation;
|
|
219
235
|
}
|
|
@@ -302,9 +318,8 @@ export function subtitles(scope) {
|
|
|
302
318
|
const role = options?.role ?? "primary";
|
|
303
319
|
if (role !== "primary" && role !== "secondary")
|
|
304
320
|
throw failure("invalid", 'role must be "primary" or "secondary"');
|
|
305
|
-
const expected = await service().expected(options);
|
|
306
321
|
const chosen = track && target(track);
|
|
307
|
-
return service().mutate((id) => host().select(chosen, expected, id, role));
|
|
322
|
+
return service().inTurn(options, (expected) => service().mutate((id) => host().select(chosen, expected, id, role)));
|
|
308
323
|
},
|
|
309
324
|
async load(srt, options) {
|
|
310
325
|
const format = options?.format ?? "srt";
|
|
@@ -327,7 +342,8 @@ export function subtitles(scope) {
|
|
|
327
342
|
[...title].length > 200))
|
|
328
343
|
throw failure("invalid", "title needs 1–200 characters");
|
|
329
344
|
const svc = service();
|
|
330
|
-
|
|
345
|
+
// In its turn among the plugin's calls on the source.
|
|
346
|
+
const current = await playerOf(scope.runtime).inTurn(() => svc.refresh());
|
|
331
347
|
const expected = await svc.expected(options);
|
|
332
348
|
const uploadId = svc.nextUpload();
|
|
333
349
|
const resourceId = `external-${uploadId}`;
|
|
@@ -390,8 +406,7 @@ export function subtitles(scope) {
|
|
|
390
406
|
const chosen = target(track);
|
|
391
407
|
if (chosen.kind !== "external" || !service().owned.has(chosen.resourceId))
|
|
392
408
|
throw failure("invalid", "只能移除本插件加载的字幕");
|
|
393
|
-
const
|
|
394
|
-
const state = await service().mutate((id) => host().remove(chosen.resourceId, expected, id));
|
|
409
|
+
const state = await service().inTurn(options, (expected) => service().mutate((id) => host().remove(chosen.resourceId, expected, id)));
|
|
395
410
|
service().owned.delete(chosen.resourceId);
|
|
396
411
|
return state;
|
|
397
412
|
},
|
|
@@ -386,10 +386,14 @@ export interface Chapter {
|
|
|
386
386
|
start: number;
|
|
387
387
|
}
|
|
388
388
|
/**
|
|
389
|
-
* Controls act on the state
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
*
|
|
389
|
+
* Controls act on the current state by default. While a
|
|
390
|
+
* {@link Player.stream} (or anything else that follows the source) keeps
|
|
391
|
+
* `player.state` current, that is the state they act on; otherwise the SDK
|
|
392
|
+
* reads the state first (calls made together share one read). If another
|
|
393
|
+
* plugin or the user changed the source in between, the call fails with
|
|
394
|
+
* code `stale` and nothing happens. Pass `ifCurrent` to pin the call to an
|
|
395
|
+
* older snapshot instead (for example the state when a dialog opened); it
|
|
396
|
+
* is sent as given.
|
|
393
397
|
*
|
|
394
398
|
* The SDK refreshes `player.state` after its own operations, so a plugin's
|
|
395
399
|
* consecutive calls do not make each other stale. {@link Player.open} is
|
|
@@ -419,7 +423,7 @@ export interface Chapter {
|
|
|
419
423
|
* @category Playback
|
|
420
424
|
*/
|
|
421
425
|
export interface Conditional {
|
|
422
|
-
/** The state the call is conditional on; default: the current `player.state
|
|
426
|
+
/** The state the call is conditional on; default: the current state (read first when no stream keeps `player.state` current). */
|
|
423
427
|
ifCurrent?: PlayerState;
|
|
424
428
|
}
|
|
425
429
|
/**
|
|
@@ -939,8 +943,9 @@ export interface StateStream {
|
|
|
939
943
|
* has: from `read()`, `refresh()`, an event's data and this plugin's own
|
|
940
944
|
* calls, and while a {@link Player.stream} is open, every change. Every
|
|
941
945
|
* control is
|
|
942
|
-
* conditional: it acts on the state
|
|
943
|
-
* `
|
|
946
|
+
* conditional: it acts on the current state (read first when no stream
|
|
947
|
+
* keeps `state` current) or on the one given as `ifCurrent`, and fails
|
|
948
|
+
* with `stale` when the source changed meanwhile: another file, a close, or any
|
|
944
949
|
* pause, seek or speed change by the user or another plugin (see
|
|
945
950
|
* {@link Conditional}). The player keeps the source when a plugin stops;
|
|
946
951
|
* only the plugin's own handles (a stream, its sequence provider, its
|
|
@@ -1346,8 +1351,8 @@ export interface Player {
|
|
|
1346
1351
|
*
|
|
1347
1352
|
* @example Pause, but only the file the user was watching
|
|
1348
1353
|
* A "pause on lock" helper pauses the current file and does nothing when
|
|
1349
|
-
* another file was opened in between. The call
|
|
1350
|
-
*
|
|
1354
|
+
* another file was opened in between. The call acts on the current state
|
|
1355
|
+
* by default; `stale` means the source changed and the
|
|
1351
1356
|
* pause was not applied, which is the intended outcome here.
|
|
1352
1357
|
* ```ts
|
|
1353
1358
|
* try {
|
|
@@ -1377,13 +1382,13 @@ export interface Player {
|
|
|
1377
1382
|
*
|
|
1378
1383
|
* @example Jump back ten seconds
|
|
1379
1384
|
* Playback jumps ten seconds back, never before the start. The target is
|
|
1380
|
-
* computed from the
|
|
1381
|
-
* opened another file meanwhile the seek
|
|
1382
|
-
* landing in the wrong file.
|
|
1385
|
+
* computed from the state read now, and the seek is pinned to it
|
|
1386
|
+
* (`ifCurrent`), so if the user opened another file meanwhile the seek
|
|
1387
|
+
* fails with `stale` instead of landing in the wrong file.
|
|
1383
1388
|
* ```ts
|
|
1384
|
-
* const
|
|
1385
|
-
* if (position !== null &&
|
|
1386
|
-
* await plugin.player.seek(Math.max(0, position - 10)); // seconds
|
|
1389
|
+
* const now = await plugin.player.refresh();
|
|
1390
|
+
* if (now.position !== null && now.can.seek)
|
|
1391
|
+
* await plugin.player.seek(Math.max(0, now.position - 10), { ifCurrent: now }); // seconds
|
|
1387
1392
|
* ```
|
|
1388
1393
|
*
|
|
1389
1394
|
* @since 1.0.0
|
package/llms.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Vestra Player SDK
|
|
2
2
|
|
|
3
|
-
> @vestra-player/sdk 1.11.
|
|
3
|
+
> @vestra-player/sdk 1.11.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
|
|