@vestra-player/sdk 1.8.0 → 1.10.0
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 +64 -2
- package/README.md +2 -2
- package/bin/vestra-plugin.mjs +98 -106
- package/capability-scan.json +21 -1
- package/dist/api-requests.d.ts +15 -39
- package/dist/api-requests.js +28 -50
- package/dist/capability-scan.d.ts +1 -1
- package/dist/capability-scan.js +8 -9
- package/dist/condition-table.d.ts +1889 -0
- package/dist/condition-table.js +562 -0
- package/dist/docs-tree.json.gz +0 -0
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +1 -1
- package/dist/i18n-tools.d.ts +7 -0
- package/dist/i18n-tools.js +66 -3
- package/dist/index.d.ts +4 -5
- package/dist/manifest.d.ts +5 -0
- package/dist/manifest.js +9 -24
- package/dist/member-uses.d.ts +61 -0
- package/dist/member-uses.js +160 -0
- package/dist/player-runtime.d.ts +4 -2
- package/dist/player-runtime.js +4 -2
- package/dist/plugin/appearance.d.ts +1 -1
- package/dist/plugin/appearance.js +2 -2
- package/dist/plugin/bindings.d.ts +1 -1
- package/dist/plugin/bindings.js +2 -2
- package/dist/plugin/commands.js +1 -12
- package/dist/plugin/connection.d.ts +38 -8
- package/dist/plugin/connection.js +126 -37
- package/dist/plugin/drops.js +1 -1
- package/dist/plugin/index.d.ts +7 -0
- package/dist/plugin/index.js +22 -15
- package/dist/plugin/media.js +0 -12
- package/dist/plugin/mpv.js +39 -12
- package/dist/plugin/packages.js +1 -2
- package/dist/plugin/player/events.d.ts +17 -7
- package/dist/plugin/player/events.js +26 -9
- package/dist/plugin/player.d.ts +37 -13
- package/dist/plugin/player.js +133 -22
- package/dist/plugin/scope.d.ts +4 -1
- package/dist/plugin/scope.js +8 -0
- package/dist/plugin/services.d.ts +4 -4
- package/dist/plugin/services.js +7 -29
- package/dist/plugin/settings.js +1 -1
- package/dist/plugin/shaders.js +0 -2
- package/dist/plugin/stream.d.ts +2 -1
- package/dist/plugin/stream.js +2 -2
- package/dist/plugin/testing/commands.d.ts +3 -10
- package/dist/plugin/testing/commands.js +24 -37
- package/dist/plugin/testing/index.d.ts +133 -116
- package/dist/plugin/testing/index.js +198 -125
- package/dist/plugin/testing/media.d.ts +6 -0
- package/dist/plugin/testing/media.js +15 -2
- package/dist/plugin/testing/processing.js +1 -1
- package/dist/plugin/testing/services.js +0 -1
- package/dist/plugin/testing/source-events.d.ts +28 -0
- package/dist/plugin/testing/source-events.js +66 -0
- package/dist/plugin/testing/transport.js +5 -0
- package/dist/plugin/testing/triggers.d.ts +82 -0
- package/dist/plugin/testing/triggers.js +448 -0
- package/dist/plugin/timeline.d.ts +5 -6
- package/dist/plugin/timeline.js +7 -11
- package/dist/plugin/triggers.d.ts +55 -0
- package/dist/plugin/triggers.js +233 -0
- package/dist/plugin/types/base.d.ts +77 -87
- package/dist/plugin/types/commands.d.ts +384 -68
- package/dist/plugin/types/packages.d.ts +17 -55
- package/dist/plugin/types/playback.d.ts +382 -152
- package/dist/plugin/types/plugin-wire.d.ts +6 -36
- package/dist/plugin/types/processing.d.ts +10 -49
- package/dist/plugin/types/services.d.ts +11 -70
- package/dist/plugin/types/snapshots.d.ts +7 -60
- package/dist/plugin/types/sources.d.ts +2 -11
- package/dist/plugin/types/subtitles.d.ts +5 -26
- package/dist/plugin/types/ui-content.d.ts +1 -16
- package/dist/plugin/types/ui-layout.d.ts +53 -79
- package/dist/plugin/types/ui-locale.d.ts +5 -23
- package/dist/plugin/types/ui-shell.d.ts +13 -59
- package/dist/plugin/view/layout.js +1 -1
- package/dist/plugin/view.js +0 -2
- package/dist/plugin/when.d.ts +78 -4
- package/dist/plugin/when.js +182 -14
- package/dist/plugin/window.d.ts +1 -1
- package/dist/plugin/window.js +1 -1
- package/dist/plugin/wire-facade.js +1 -2
- package/dist/processing.d.ts +2 -3
- package/dist/protocol.d.ts +14 -0
- package/dist/protocol.js +14 -0
- package/dist/request-queue.js +1 -1
- package/dist/slint-version.d.ts +7 -0
- package/dist/slint-version.js +7 -0
- package/dist/subtitles.d.ts +1 -1
- package/dist/ts-plugin.d.ts +8 -15
- package/dist/ts-plugin.js +3 -141
- package/dist/wire.d.ts +22 -12
- package/dist/wire.js +17 -8
- package/llms.txt +6 -6
- package/package.json +1 -2
- package/dist/capabilities.d.ts +0 -107
- package/dist/capabilities.js +0 -69
- package/dist/capability-check.d.ts +0 -176
- package/dist/capability-check.js +0 -461
- package/dist/capability-rules.d.ts +0 -125
- package/dist/capability-rules.js +0 -192
- package/dist/host-capabilities.d.ts +0 -10
- package/dist/host-capabilities.js +0 -492
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `plugin.trigger(name?)` (1.10.0, events-and-triggers.md §3.1, §4.1):
|
|
3
|
+
* triggers declared in the synchronous part of `activate()`, their
|
|
4
|
+
* conditions handed to the player (`triggers.set`, `triggers.off`), and the
|
|
5
|
+
* player's `triggers.fired` notifications routed to their `enter` and
|
|
6
|
+
* `leave`.
|
|
7
|
+
*
|
|
8
|
+
* Identity: an unnamed trigger is its place among the unnamed ones (the
|
|
9
|
+
* order `activate()` declares them in), a named one its name. At the end of
|
|
10
|
+
* the synchronous part the player is told which names and how many unnamed
|
|
11
|
+
* ones were declared (`triggers.declare`), so it can drop a kept condition
|
|
12
|
+
* nobody declares any more (T14).
|
|
13
|
+
*
|
|
14
|
+
* Sequence numbers (T6): each `set` and `off` answers one; a notification
|
|
15
|
+
* with an older one than the trigger's newest answer is dropped, and one
|
|
16
|
+
* that arrives while a `set` or `off` is in flight waits for its answer.
|
|
17
|
+
*/
|
|
18
|
+
import { HostError } from "../wire.js";
|
|
19
|
+
import { failure } from "./errors.js";
|
|
20
|
+
import { playerOf } from "./player.js";
|
|
21
|
+
import { conditionJson, positionLists } from "./when.js";
|
|
22
|
+
/**
|
|
23
|
+
* The player's limits on triggers (`plugin.trigger`): how many a plugin
|
|
24
|
+
* declares and the player keeps conditions for, and how long a name is.
|
|
25
|
+
* A 65th trigger throws `limit`; the player refuses a 65th kept condition
|
|
26
|
+
* with `limit` too. A position list holds at most `TIMELINE_LIMITS.ranges`
|
|
27
|
+
* ranges.
|
|
28
|
+
*
|
|
29
|
+
* @example Stay within the limit
|
|
30
|
+
* A plugin that makes one trigger per item of a list keeps the list
|
|
31
|
+
* within the number of triggers the player allows.
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { TRIGGER_LIMITS } from "@vestra-player/sdk/testing";
|
|
34
|
+
*
|
|
35
|
+
* const names = ["sleep", "wake"].slice(0, TRIGGER_LIMITS.triggers);
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @since 1.10.0
|
|
39
|
+
*
|
|
40
|
+
* @category Testing
|
|
41
|
+
*/
|
|
42
|
+
export const TRIGGER_LIMITS = Object.freeze({
|
|
43
|
+
/** Triggers a plugin declares, and conditions the player keeps for it. */
|
|
44
|
+
triggers: 64,
|
|
45
|
+
/** Characters of a trigger's name. */
|
|
46
|
+
nameChars: 64,
|
|
47
|
+
});
|
|
48
|
+
class TriggerImpl {
|
|
49
|
+
id;
|
|
50
|
+
#registry;
|
|
51
|
+
#scope;
|
|
52
|
+
#enter;
|
|
53
|
+
#leave;
|
|
54
|
+
/** The newest sequence number the player answered. */
|
|
55
|
+
#known = 0;
|
|
56
|
+
/** `set` and `off` requests without an answer yet. */
|
|
57
|
+
#inFlight = 0;
|
|
58
|
+
/** Notifications that came while one was in flight. */
|
|
59
|
+
#held = [];
|
|
60
|
+
/** The handlers run one after another (T9). */
|
|
61
|
+
#chain = Promise.resolve();
|
|
62
|
+
constructor(registry, scope, id) {
|
|
63
|
+
this.#registry = registry;
|
|
64
|
+
this.#scope = scope;
|
|
65
|
+
this.id = id;
|
|
66
|
+
}
|
|
67
|
+
get handled() {
|
|
68
|
+
return this.#enter !== undefined || this.#leave !== undefined;
|
|
69
|
+
}
|
|
70
|
+
firesOn(condition) {
|
|
71
|
+
const when = conditionJson(condition);
|
|
72
|
+
if (positionLists(when) > 1)
|
|
73
|
+
throw new TypeError("a condition has at most one position list");
|
|
74
|
+
this.#send(this.#registry.runtime.host.triggers.set(this.id, when));
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
enter(fn) {
|
|
78
|
+
if (typeof fn !== "function")
|
|
79
|
+
throw new TypeError("enter takes a function");
|
|
80
|
+
this.#enter = fn;
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
leave(fn) {
|
|
84
|
+
if (typeof fn !== "function")
|
|
85
|
+
throw new TypeError("leave takes a function");
|
|
86
|
+
this.#leave = fn;
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
off() {
|
|
90
|
+
this.#send(this.#registry.runtime.host.triggers.off(this.id));
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
#send(request) {
|
|
94
|
+
this.#inFlight++;
|
|
95
|
+
request.then(({ seq }) => {
|
|
96
|
+
this.#known = Math.max(this.#known, seq);
|
|
97
|
+
this.#settled();
|
|
98
|
+
}, (error) => {
|
|
99
|
+
this.#settled();
|
|
100
|
+
if (!(error instanceof HostError && error.code === "disabled"))
|
|
101
|
+
this.#scope.report(error);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
#settled() {
|
|
105
|
+
this.#inFlight--;
|
|
106
|
+
if (this.#inFlight > 0)
|
|
107
|
+
return;
|
|
108
|
+
for (const fired of this.#held.splice(0))
|
|
109
|
+
this.fired(fired);
|
|
110
|
+
}
|
|
111
|
+
/** A notification for this trigger. */
|
|
112
|
+
fired(fired) {
|
|
113
|
+
if (this.#inFlight > 0) {
|
|
114
|
+
this.#held.push(fired);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (fired.seq < this.#known)
|
|
118
|
+
return;
|
|
119
|
+
if (!this.handled) {
|
|
120
|
+
this.#registry.unhandled(fired.trigger);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const fn = fired.edge === "enter" ? this.#enter : this.#leave;
|
|
124
|
+
if (!fn)
|
|
125
|
+
return;
|
|
126
|
+
const state = playerOf(this.#registry.runtime).sourceEvent("triggers.fired", { state: fired.state });
|
|
127
|
+
const event = Object.freeze(fired.range
|
|
128
|
+
? { state: state.state, range: Object.freeze({ ...fired.range }) }
|
|
129
|
+
: { state: state.state });
|
|
130
|
+
const scope = this.#scope;
|
|
131
|
+
this.#chain = this.#chain.then(async () => {
|
|
132
|
+
if (scope.disposed)
|
|
133
|
+
return;
|
|
134
|
+
try {
|
|
135
|
+
await fn(event);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
scope.report(error);
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
scope.update();
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/** One plugin's triggers (a runtime service). */
|
|
147
|
+
export class TriggerRegistry {
|
|
148
|
+
runtime;
|
|
149
|
+
/** `activate()`'s synchronous part runs (`PluginInstance.activate`). */
|
|
150
|
+
#declaring = false;
|
|
151
|
+
/** That part is over: notifications go to their triggers. */
|
|
152
|
+
#declared = false;
|
|
153
|
+
#byId = new Map();
|
|
154
|
+
#unnamed = 0;
|
|
155
|
+
/** Notifications that came before the triggers were declared. */
|
|
156
|
+
#early = [];
|
|
157
|
+
constructor(runtime) {
|
|
158
|
+
this.runtime = runtime;
|
|
159
|
+
runtime.raw("triggers.fired", (data) => this.#fired(data));
|
|
160
|
+
}
|
|
161
|
+
/** `activate()` begins: triggers may be declared until `end`. */
|
|
162
|
+
begin() {
|
|
163
|
+
this.#declaring = true;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The synchronous part of `activate()` is over: the player learns what
|
|
167
|
+
* was declared (only when something was), and what came early is
|
|
168
|
+
* delivered.
|
|
169
|
+
*/
|
|
170
|
+
end() {
|
|
171
|
+
this.#declaring = false;
|
|
172
|
+
this.#declared = true;
|
|
173
|
+
if (this.#byId.size) {
|
|
174
|
+
const names = [...this.#byId.keys()].filter((id) => typeof id === "string");
|
|
175
|
+
this.runtime.host.triggers
|
|
176
|
+
.declare(names, this.#unnamed)
|
|
177
|
+
.catch((error) => {
|
|
178
|
+
if (!(error instanceof HostError && error.code === "disabled"))
|
|
179
|
+
console.error(`[${this.runtime.manifest.id}] triggers.declare:`, error);
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
for (const fired of this.#early.splice(0))
|
|
183
|
+
this.#fired(fired);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* `plugin.trigger(name?)` of `scope`. Only the plugin itself declares
|
|
187
|
+
* triggers, not a sub-scope (`plugin.scope()`): a trigger's condition is
|
|
188
|
+
* the plugin's, kept by the player beyond any one run, while a sub-scope
|
|
189
|
+
* is disposed within a run, and a kept condition whose functions went
|
|
190
|
+
* with it would go on waking the plugin for nothing.
|
|
191
|
+
*/
|
|
192
|
+
declare(scope, name) {
|
|
193
|
+
if (!this.#declaring)
|
|
194
|
+
throw new Error("plugin.trigger() is called only in the synchronous part of activate(), before its first await");
|
|
195
|
+
if (!scope.root)
|
|
196
|
+
throw new Error("plugin.trigger() is called on the plugin, not on a scope made with plugin.scope()");
|
|
197
|
+
if (this.#byId.size >= TRIGGER_LIMITS.triggers)
|
|
198
|
+
throw failure("limit", `a plugin has at most ${TRIGGER_LIMITS.triggers} triggers`);
|
|
199
|
+
let id;
|
|
200
|
+
if (name === undefined)
|
|
201
|
+
id = this.#unnamed++;
|
|
202
|
+
else {
|
|
203
|
+
if (typeof name !== "string" ||
|
|
204
|
+
name.length === 0 ||
|
|
205
|
+
[...name].length > TRIGGER_LIMITS.nameChars ||
|
|
206
|
+
/\p{Cc}/u.test(name))
|
|
207
|
+
throw failure("invalid", `a trigger's name is 1–${TRIGGER_LIMITS.nameChars} characters`);
|
|
208
|
+
if (this.#byId.has(name))
|
|
209
|
+
throw failure("invalid", `a trigger named "${name}" exists already`);
|
|
210
|
+
id = name;
|
|
211
|
+
}
|
|
212
|
+
const trigger = new TriggerImpl(this, scope, id);
|
|
213
|
+
this.#byId.set(id, trigger);
|
|
214
|
+
return trigger;
|
|
215
|
+
}
|
|
216
|
+
/** Nobody handles `trigger`'s notifications (T14): the player drops its condition. */
|
|
217
|
+
unhandled(trigger) {
|
|
218
|
+
this.runtime.host.triggers.off(trigger, true).catch(() => { });
|
|
219
|
+
}
|
|
220
|
+
#fired(fired) {
|
|
221
|
+
if (!this.#declared) {
|
|
222
|
+
this.#early.push(fired);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const trigger = this.#byId.get(fired.trigger);
|
|
226
|
+
if (trigger)
|
|
227
|
+
trigger.fired(fired);
|
|
228
|
+
else
|
|
229
|
+
this.unhandled(fired.trigger);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/** The triggers of `runtime`'s plugin. */
|
|
233
|
+
export const triggersOf = (runtime) => runtime.service("triggers", () => new TriggerRegistry(runtime));
|