@reactor-models/fast-h3 1.0.2

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/dist/index.js ADDED
@@ -0,0 +1,683 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ FastH3MainVideoView: () => FastH3MainVideoView,
24
+ FastH3Model: () => FastH3Model,
25
+ FastH3Provider: () => FastH3Provider,
26
+ FastH3Tracks: () => FastH3Tracks,
27
+ FileRef: () => import_js_sdk.FileRef,
28
+ MODEL_NAME: () => MODEL_NAME,
29
+ MODEL_VERSION: () => MODEL_VERSION,
30
+ useFastH3: () => useFastH3,
31
+ useFastH3AutoplayAccepted: () => useFastH3AutoplayAccepted,
32
+ useFastH3CanvasAccepted: () => useFastH3CanvasAccepted,
33
+ useFastH3ClipFailed: () => useFastH3ClipFailed,
34
+ useFastH3ClipFinished: () => useFastH3ClipFinished,
35
+ useFastH3ClipGenerated: () => useFastH3ClipGenerated,
36
+ useFastH3ClipLengthAccepted: () => useFastH3ClipLengthAccepted,
37
+ useFastH3ClipMoved: () => useFastH3ClipMoved,
38
+ useFastH3ClipPopped: () => useFastH3ClipPopped,
39
+ useFastH3ClipQueued: () => useFastH3ClipQueued,
40
+ useFastH3ClipStarted: () => useFastH3ClipStarted,
41
+ useFastH3ClipStopped: () => useFastH3ClipStopped,
42
+ useFastH3CommandError: () => useFastH3CommandError,
43
+ useFastH3FlushAccepted: () => useFastH3FlushAccepted,
44
+ useFastH3Message: () => useFastH3Message,
45
+ useFastH3QueueUpdate: () => useFastH3QueueUpdate,
46
+ useFastH3SeedAccepted: () => useFastH3SeedAccepted,
47
+ useFastH3SessionReset: () => useFastH3SessionReset,
48
+ useFastH3StateUpdate: () => useFastH3StateUpdate,
49
+ useFastH3Track: () => useFastH3Track
50
+ });
51
+ module.exports = __toCommonJS(index_exports);
52
+
53
+ // src/core.ts
54
+ var import_js_sdk = require("@reactor-team/js-sdk");
55
+ var MODEL_NAME = "reactor/fast-h3";
56
+ var MODEL_VERSION = "v1.0.2";
57
+ var FastH3Tracks = [
58
+ { name: "main_video", kind: "video", direction: "recvonly" },
59
+ { name: "main_audio", kind: "audio", direction: "recvonly" }
60
+ ];
61
+ function _unwrapMessage(raw) {
62
+ const env = raw;
63
+ if (env && typeof env === "object" && env.data && typeof env.data === "object") {
64
+ return { ...env.data, type: env.type };
65
+ }
66
+ return raw;
67
+ }
68
+ var FastH3Model = class extends import_js_sdk.Reactor {
69
+ constructor(options) {
70
+ super({
71
+ ...options,
72
+ modelName: MODEL_NAME,
73
+ modelTracks: [...FastH3Tracks]
74
+ });
75
+ }
76
+ /** @deprecated The model client now extends `Reactor` directly — call methods on `this` instead. This accessor returns `this` for backwards compatibility and will be removed in a future major release. */
77
+ get reactor() {
78
+ return this;
79
+ }
80
+ /**
81
+ * Remove one clip by its UUID from whichever queue holds it, freeing its slot. Works on generating and built clips alike; a build already running for it is discarded when it completes. The clip that is playing is in neither queue — `stop` is the command that cuts it. A built clip stays in `queue_update.history` after popping, so clips continued from it are unaffected; an unbuilt clip that queued clips continue from is refused, since popping it would leave them nothing to open from — pop those first. Emits `clip_popped`, `queue_update` and `state_update`, or `command_error` when no queued clip has that id or queued clips still continue from it.
82
+ * @param params - Remove one clip by its UUID from whichever queue holds it, freeing its slot. Works on generating and built clips alike; a build already running for it is discarded when it completes. The clip that is playing is in neither queue — `stop` is the command that cuts it. A built clip stays in `queue_update.history` after popping, so clips continued from it are unaffected; an unbuilt clip that queued clips continue from is refused, since popping it would leave them nothing to open from — pop those first. Emits `clip_popped`, `queue_update` and `state_update`, or `command_error` when no queued clip has that id or queued clips still continue from it.
83
+ * @returns The correlated {@link FastH3ClipPoppedMessage} reply, or `undefined` when the send fails (the SDK never rejects — see `getLastError()`).
84
+ */
85
+ async pop(params) {
86
+ const reply = await this.sendCommand("pop", params);
87
+ return reply === void 0 ? void 0 : _unwrapMessage(reply);
88
+ }
89
+ /**
90
+ * Reposition one clip within the queue that holds it — the generation queue for a clip still to build, the playout queue for a built one; clips never move between queues except by building. `position` 0 is the front: the next build, or what bare `play` and autoplay take next. Values past the end mean the back. Replies `clip_moved` with the queue and the resulting position, and emits `queue_update`; `command_error` when no queued clip has that id.
91
+ * @param params - Reposition one clip within the queue that holds it — the generation queue for a clip still to build, the playout queue for a built one; clips never move between queues except by building. `position` 0 is the front: the next build, or what bare `play` and autoplay take next. Values past the end mean the back. Replies `clip_moved` with the queue and the resulting position, and emits `queue_update`; `command_error` when no queued clip has that id.
92
+ * @returns The correlated {@link FastH3ClipMovedMessage} reply, or `undefined` when the send fails (the SDK never rejects — see `getLastError()`).
93
+ */
94
+ async move(params) {
95
+ const reply = await this.sendCommand("move", params);
96
+ return reply === void 0 ? void 0 : _unwrapMessage(reply);
97
+ }
98
+ /**
99
+ * Play one clip from the playout queue. Blank `clip_id` plays the front clip; a UUID plays that specific one. Playing consumes the entry: it leaves the queue, `clip_started` marks its first frames, and when it ends the stream holds on black until the next `play`. Emits `queue_update` and `state_update`, or `command_error` when a clip is already playing, the id is unknown, or the clip is still generating.
100
+ * @param params - Play one clip from the playout queue. Blank `clip_id` plays the front clip; a UUID plays that specific one. Playing consumes the entry: it leaves the queue, `clip_started` marks its first frames, and when it ends the stream holds on black until the next `play`. Emits `queue_update` and `state_update`, or `command_error` when a clip is already playing, the id is unknown, or the clip is still generating.
101
+ * @returns Resolves once the model's handler has completed; this command declares no reply payload.
102
+ */
103
+ async play(params) {
104
+ await this.sendCommand("play", params);
105
+ return void 0;
106
+ }
107
+ /**
108
+ * Cut the clip that is playing. Whatever is queued on the output tracks is dropped and the picture goes to black within a fraction of a second (with `set_flush_on_clip_end` off, the transport drains what it holds and freezes on the last frame instead), and the session is back where a finished clip leaves it — the queue is untouched and the next `play` starts clean. With autoplay on this acts as a skip: the next ready clip starts on its own, so send `set_autoplay` off first to hold the stream. Emits `clip_stopped` and `state_update`, or `command_error` when no clip is playing.
109
+ * @returns Resolves once the model's handler has completed; this command declares no reply payload.
110
+ */
111
+ async stop() {
112
+ await this.sendCommand("stop", {});
113
+ return void 0;
114
+ }
115
+ /**
116
+ * Return every condition to its default, drop both queues' clips and the retained history, and clear the output tracks. A clip that is playing is cut, with a `clip_stopped` to mark it. Valid at any time. Replies `session_reset` and emits `queue_update` and `state_update`.
117
+ * @returns The correlated {@link FastH3SessionResetMessage} reply, or `undefined` when the send fails (the SDK never rejects — see `getLastError()`).
118
+ */
119
+ async reset() {
120
+ const reply = await this.sendCommand("reset", {});
121
+ return reply === void 0 ? void 0 : _unwrapMessage(reply);
122
+ }
123
+ /**
124
+ * Queue one clip generation. The clip enters the generation queue (at `position`, or the back), builds when its turn comes, and then joins the back of the playout queue, announced by `clip_generated`. The prompt is what the clip will show; the metadata is an opaque string echoed back on every message that references the clip, for frontends to carry their own tracking data. The clip opens from text alone, from an uploaded still (`starting_frame` — the image animates forward), or from an existing clip's last frame (`continue_from_clip_id` — any clip in the queues or in `queue_update.history`); a continued clip simply waits its turn until its source is built, wherever the two sit in the queue. The clip's canvas is the session's; its length is the `seconds` passed here (snapped to what the model can produce) or the session default, and its seed is the one passed here or the session's advancing default. Builds run through the queue in order; watch `queue_update` for the clip turning ready. Replies `clip_queued` with the clip's UUID and emits `queue_update` and `state_update`, or `command_error` when the queue is full, the prompt is empty, both a starting frame and a source clip are given, the source clip is unknown or no longer retained, or the upload is not a decodable image.
125
+ * @param params - Queue one clip generation. The clip enters the generation queue (at `position`, or the back), builds when its turn comes, and then joins the back of the playout queue, announced by `clip_generated`. The prompt is what the clip will show; the metadata is an opaque string echoed back on every message that references the clip, for frontends to carry their own tracking data. The clip opens from text alone, from an uploaded still (`starting_frame` — the image animates forward), or from an existing clip's last frame (`continue_from_clip_id` — any clip in the queues or in `queue_update.history`); a continued clip simply waits its turn until its source is built, wherever the two sit in the queue. The clip's canvas is the session's; its length is the `seconds` passed here (snapped to what the model can produce) or the session default, and its seed is the one passed here or the session's advancing default. Builds run through the queue in order; watch `queue_update` for the clip turning ready. Replies `clip_queued` with the clip's UUID and emits `queue_update` and `state_update`, or `command_error` when the queue is full, the prompt is empty, both a starting frame and a source clip are given, the source clip is unknown or no longer retained, or the upload is not a decodable image.
126
+ * @returns The correlated {@link FastH3ClipQueuedMessage} reply, or `undefined` when the send fails (the SDK never rejects — see `getLastError()`).
127
+ */
128
+ async enqueue(params) {
129
+ const reply = await this.sendCommand("enqueue", params);
130
+ return reply === void 0 ? void 0 : _unwrapMessage(reply);
131
+ }
132
+ /**
133
+ * Set the default seed — the one an `enqueue` without a seed of its own uses, advancing it by one, so re-enqueuing the same prompts in the same order reproduces the same clips. Clips already in the queue keep the seed they were enqueued with. Valid at any time. Emits `seed_accepted` and `state_update`.
134
+ * @param params - Set the default seed — the one an `enqueue` without a seed of its own uses, advancing it by one, so re-enqueuing the same prompts in the same order reproduces the same clips. Clips already in the queue keep the seed they were enqueued with. Valid at any time. Emits `seed_accepted` and `state_update`.
135
+ * @returns The correlated {@link FastH3SeedAcceptedMessage} reply, or `undefined` when the send fails (the SDK never rejects — see `getLastError()`).
136
+ */
137
+ async setSeed(params) {
138
+ const reply = await this.sendCommand("set_seed", params);
139
+ return reply === void 0 ? void 0 : _unwrapMessage(reply);
140
+ }
141
+ /**
142
+ * Return both queues' contents — `generation` (waiting to build) and `playout` (built, playable) — plus `history`, the built clips no longer queued that `continue_from_clip_id` can still name, every clip as its full structure. The same payload the model broadcasts as `queue_update`. Valid at any time.
143
+ * @returns The correlated {@link FastH3QueueUpdateMessage} reply, or `undefined` when the send fails (the SDK never rejects — see `getLastError()`).
144
+ */
145
+ async getQueue() {
146
+ const reply = await this.sendCommand("get_queue", {});
147
+ return reply === void 0 ? void 0 : _unwrapMessage(reply);
148
+ }
149
+ /**
150
+ * Return a snapshot of everything the session exposes except the queue's contents (`get_queue` carries those): the conditions in force, what is playing, progress counters, and the commands that are valid right now. The same payload the model broadcasts as `state_update`. Valid at any time.
151
+ * @returns The correlated {@link FastH3StateUpdateMessage} reply, or `undefined` when the send fails (the SDK never rejects — see `getLastError()`).
152
+ */
153
+ async getState() {
154
+ const reply = await this.sendCommand("get_state", {});
155
+ return reply === void 0 ? void 0 : _unwrapMessage(reply);
156
+ }
157
+ /**
158
+ * Choose the aspect ratio of `main_video`. The video track keeps one size and queued clips are built at it, so this is only valid while the queue is empty and nothing is playing. Emits `canvas_accepted`, carrying the exact pixel size, and `state_update`, or `command_error` while clips are queued or playing, or when the ratio is not one this model offers.
159
+ * @param params - Choose the aspect ratio of `main_video`. The video track keeps one size and queued clips are built at it, so this is only valid while the queue is empty and nothing is playing. Emits `canvas_accepted`, carrying the exact pixel size, and `state_update`, or `command_error` while clips are queued or playing, or when the ratio is not one this model offers.
160
+ * @returns The correlated {@link FastH3CanvasAcceptedMessage} reply, or `undefined` when the send fails (the SDK never rejects — see `getLastError()`).
161
+ */
162
+ async setCanvas(params) {
163
+ const reply = await this.sendCommand("set_canvas", params);
164
+ return reply === void 0 ? void 0 : _unwrapMessage(reply);
165
+ }
166
+ /**
167
+ * Turn autoplay on or off. On, the playout queue's front clip starts on its own whenever nothing is playing — right after a clip finishes, or the moment a build completes while the stream is idle — so a steadily fed queue plays through without a `play` per clip. Off (the default), the stream holds on black until an explicit `play`. Takes effect immediately and lasts for the session. Emits `autoplay_accepted` and `state_update`.
168
+ * @param params - Turn autoplay on or off. On, the playout queue's front clip starts on its own whenever nothing is playing — right after a clip finishes, or the moment a build completes while the stream is idle — so a steadily fed queue plays through without a `play` per clip. Off (the default), the stream holds on black until an explicit `play`. Takes effect immediately and lasts for the session. Emits `autoplay_accepted` and `state_update`.
169
+ * @returns The correlated {@link FastH3AutoplayAcceptedMessage} reply, or `undefined` when the send fails (the SDK never rejects — see `getLastError()`).
170
+ */
171
+ async setAutoplay(params) {
172
+ const reply = await this.sendCommand("set_autoplay", params);
173
+ return reply === void 0 ? void 0 : _unwrapMessage(reply);
174
+ }
175
+ /**
176
+ * Set the default length for enqueues that carry no `seconds` of their own. The value is snapped to the nearest length the model can produce, so read the effective one back from `clip_length_accepted`. Clips already in the queue keep the length they were enqueued with. Longer clips carry a scene further; shorter ones build faster. Valid at any time. Emits `clip_length_accepted` and `state_update`.
177
+ * @param params - Set the default length for enqueues that carry no `seconds` of their own. The value is snapped to the nearest length the model can produce, so read the effective one back from `clip_length_accepted`. Clips already in the queue keep the length they were enqueued with. Longer clips carry a scene further; shorter ones build faster. Valid at any time. Emits `clip_length_accepted` and `state_update`.
178
+ * @returns The correlated {@link FastH3ClipLengthAcceptedMessage} reply, or `undefined` when the send fails (the SDK never rejects — see `getLastError()`).
179
+ */
180
+ async setClipSeconds(params) {
181
+ const reply = await this.sendCommand("set_clip_seconds", params);
182
+ return reply === void 0 ? void 0 : _unwrapMessage(reply);
183
+ }
184
+ /**
185
+ * Set whether the stream cuts to black when a clip ends, is stopped, or a non-continuing clip follows it. On (the default) those boundaries flush to black at once. Off, the stream holds the last frame instead — `stop` then drains what the transport already holds (up to a couple of seconds) before the picture freezes, rather than snapping to black. Either way, autoplay chains a clip whose `continue_from_clip_id` names the clip just finished with no cut at all, and `reset` always clears the tracks. Takes effect at the next boundary and lasts for the session. Emits `flush_accepted` and `state_update`.
186
+ * @param params - Set whether the stream cuts to black when a clip ends, is stopped, or a non-continuing clip follows it. On (the default) those boundaries flush to black at once. Off, the stream holds the last frame instead — `stop` then drains what the transport already holds (up to a couple of seconds) before the picture freezes, rather than snapping to black. Either way, autoplay chains a clip whose `continue_from_clip_id` names the clip just finished with no cut at all, and `reset` always clears the tracks. Takes effect at the next boundary and lasts for the session. Emits `flush_accepted` and `state_update`.
187
+ * @returns The correlated {@link FastH3FlushAcceptedMessage} reply, or `undefined` when the send fails (the SDK never rejects — see `getLastError()`).
188
+ */
189
+ async setFlushOnClipEnd(params) {
190
+ const reply = await this.sendCommand("set_flush_on_clip_end", params);
191
+ return reply === void 0 ? void 0 : _unwrapMessage(reply);
192
+ }
193
+ /**
194
+ * Subscribe to typed model messages.
195
+ * @param handler - Called with a discriminated FastH3Message
196
+ * @returns Unsubscribe function
197
+ */
198
+ onMessage(handler) {
199
+ const wrappedHandler = (raw) => {
200
+ handler(_unwrapMessage(raw));
201
+ };
202
+ this.on("message", wrappedHandler);
203
+ return () => this.off("message", wrappedHandler);
204
+ }
205
+ /**
206
+ * Subscribe to "clip_moved" messages only.
207
+ * @returns Unsubscribe function
208
+ */
209
+ onClipMoved(handler) {
210
+ return this.onMessage((msg) => {
211
+ if (msg.type === "clip_moved") handler(msg);
212
+ });
213
+ }
214
+ /**
215
+ * Subscribe to "clip_failed" messages only.
216
+ * @returns Unsubscribe function
217
+ */
218
+ onClipFailed(handler) {
219
+ return this.onMessage((msg) => {
220
+ if (msg.type === "clip_failed") handler(msg);
221
+ });
222
+ }
223
+ /**
224
+ * Subscribe to "clip_popped" messages only.
225
+ * @returns Unsubscribe function
226
+ */
227
+ onClipPopped(handler) {
228
+ return this.onMessage((msg) => {
229
+ if (msg.type === "clip_popped") handler(msg);
230
+ });
231
+ }
232
+ /**
233
+ * Subscribe to "clip_queued" messages only.
234
+ * @returns Unsubscribe function
235
+ */
236
+ onClipQueued(handler) {
237
+ return this.onMessage((msg) => {
238
+ if (msg.type === "clip_queued") handler(msg);
239
+ });
240
+ }
241
+ /**
242
+ * Subscribe to "clip_started" messages only.
243
+ * @returns Unsubscribe function
244
+ */
245
+ onClipStarted(handler) {
246
+ return this.onMessage((msg) => {
247
+ if (msg.type === "clip_started") handler(msg);
248
+ });
249
+ }
250
+ /**
251
+ * Subscribe to "clip_stopped" messages only.
252
+ * @returns Unsubscribe function
253
+ */
254
+ onClipStopped(handler) {
255
+ return this.onMessage((msg) => {
256
+ if (msg.type === "clip_stopped") handler(msg);
257
+ });
258
+ }
259
+ /**
260
+ * Subscribe to "queue_update" messages only.
261
+ * @returns Unsubscribe function
262
+ */
263
+ onQueueUpdate(handler) {
264
+ return this.onMessage((msg) => {
265
+ if (msg.type === "queue_update") handler(msg);
266
+ });
267
+ }
268
+ /**
269
+ * Subscribe to "state_update" messages only.
270
+ * @returns Unsubscribe function
271
+ */
272
+ onStateUpdate(handler) {
273
+ return this.onMessage((msg) => {
274
+ if (msg.type === "state_update") handler(msg);
275
+ });
276
+ }
277
+ /**
278
+ * Subscribe to "clip_finished" messages only.
279
+ * @returns Unsubscribe function
280
+ */
281
+ onClipFinished(handler) {
282
+ return this.onMessage((msg) => {
283
+ if (msg.type === "clip_finished") handler(msg);
284
+ });
285
+ }
286
+ /**
287
+ * Subscribe to "command_error" messages only.
288
+ * @returns Unsubscribe function
289
+ */
290
+ onCommandError(handler) {
291
+ return this.onMessage((msg) => {
292
+ if (msg.type === "command_error") handler(msg);
293
+ });
294
+ }
295
+ /**
296
+ * Subscribe to "seed_accepted" messages only.
297
+ * @returns Unsubscribe function
298
+ */
299
+ onSeedAccepted(handler) {
300
+ return this.onMessage((msg) => {
301
+ if (msg.type === "seed_accepted") handler(msg);
302
+ });
303
+ }
304
+ /**
305
+ * Subscribe to "session_reset" messages only.
306
+ * @returns Unsubscribe function
307
+ */
308
+ onSessionReset(handler) {
309
+ return this.onMessage((msg) => {
310
+ if (msg.type === "session_reset") handler(msg);
311
+ });
312
+ }
313
+ /**
314
+ * Subscribe to "clip_generated" messages only.
315
+ * @returns Unsubscribe function
316
+ */
317
+ onClipGenerated(handler) {
318
+ return this.onMessage((msg) => {
319
+ if (msg.type === "clip_generated") handler(msg);
320
+ });
321
+ }
322
+ /**
323
+ * Subscribe to "flush_accepted" messages only.
324
+ * @returns Unsubscribe function
325
+ */
326
+ onFlushAccepted(handler) {
327
+ return this.onMessage((msg) => {
328
+ if (msg.type === "flush_accepted") handler(msg);
329
+ });
330
+ }
331
+ /**
332
+ * Subscribe to "canvas_accepted" messages only.
333
+ * @returns Unsubscribe function
334
+ */
335
+ onCanvasAccepted(handler) {
336
+ return this.onMessage((msg) => {
337
+ if (msg.type === "canvas_accepted") handler(msg);
338
+ });
339
+ }
340
+ /**
341
+ * Subscribe to "autoplay_accepted" messages only.
342
+ * @returns Unsubscribe function
343
+ */
344
+ onAutoplayAccepted(handler) {
345
+ return this.onMessage((msg) => {
346
+ if (msg.type === "autoplay_accepted") handler(msg);
347
+ });
348
+ }
349
+ /**
350
+ * Subscribe to "clip_length_accepted" messages only.
351
+ * @returns Unsubscribe function
352
+ */
353
+ onClipLengthAccepted(handler) {
354
+ return this.onMessage((msg) => {
355
+ if (msg.type === "clip_length_accepted") handler(msg);
356
+ });
357
+ }
358
+ /**
359
+ * Subscribe to the "main_video" recvonly video track the model publishes.
360
+ *
361
+ * The handler fires once the model starts publishing this track; it receives the live MediaStreamTrack and the parent MediaStream (useful for attaching to a `<video>` / `<audio>` element via `srcObject`).
362
+ * @param handler - Called with the received track and its stream
363
+ * @returns Unsubscribe function
364
+ */
365
+ onMainVideo(handler) {
366
+ const wrapped = (name, t, s) => {
367
+ if (name === "main_video") handler(t, s);
368
+ };
369
+ this.on("trackReceived", wrapped);
370
+ return () => this.off("trackReceived", wrapped);
371
+ }
372
+ /**
373
+ * Subscribe to the "main_audio" recvonly audio track the model publishes.
374
+ *
375
+ * The handler fires once the model starts publishing this track; it receives the live MediaStreamTrack and the parent MediaStream (useful for attaching to a `<video>` / `<audio>` element via `srcObject`).
376
+ * @param handler - Called with the received track and its stream
377
+ * @returns Unsubscribe function
378
+ */
379
+ onMainAudio(handler) {
380
+ const wrapped = (name, t, s) => {
381
+ if (name === "main_audio") handler(t, s);
382
+ };
383
+ this.on("trackReceived", wrapped);
384
+ return () => this.off("trackReceived", wrapped);
385
+ }
386
+ };
387
+
388
+ // src/react.tsx
389
+ var import_js_sdk2 = require("@reactor-team/js-sdk");
390
+ var import_jsx_runtime = require("react/jsx-runtime");
391
+ function _unwrapMessage2(raw) {
392
+ const env = raw;
393
+ if (env && typeof env === "object" && env.data && typeof env.data === "object") {
394
+ return { ...env.data, type: env.type };
395
+ }
396
+ return raw;
397
+ }
398
+ function FastH3Provider({
399
+ children,
400
+ ...rest
401
+ }) {
402
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
403
+ import_js_sdk2.ReactorProvider,
404
+ {
405
+ ...rest,
406
+ modelName: MODEL_NAME,
407
+ modelTracks: [...FastH3Tracks],
408
+ children
409
+ }
410
+ );
411
+ }
412
+ function useFastH3() {
413
+ const connect = (0, import_js_sdk2.useReactor)((s) => s.connect);
414
+ const connectOptions = (0, import_js_sdk2.useReactor)((s) => s.connectOptions);
415
+ const disconnect = (0, import_js_sdk2.useReactor)((s) => s.disconnect);
416
+ const downloadClipAsFile = (0, import_js_sdk2.useReactor)((s) => s.downloadClipAsFile);
417
+ const jwtToken = (0, import_js_sdk2.useReactor)((s) => s.jwtToken);
418
+ const lastError = (0, import_js_sdk2.useReactor)((s) => s.lastError);
419
+ const lastMessage = (0, import_js_sdk2.useReactor)((s) => s.lastMessage);
420
+ const pauseTrack = (0, import_js_sdk2.useReactor)((s) => s.pauseTrack);
421
+ const publish = (0, import_js_sdk2.useReactor)((s) => s.publish);
422
+ const reconnect = (0, import_js_sdk2.useReactor)((s) => s.reconnect);
423
+ const requestClip = (0, import_js_sdk2.useReactor)((s) => s.requestClip);
424
+ const requestRecording = (0, import_js_sdk2.useReactor)((s) => s.requestRecording);
425
+ const resumeTrack = (0, import_js_sdk2.useReactor)((s) => s.resumeTrack);
426
+ const sendCommand = (0, import_js_sdk2.useReactor)((s) => s.sendCommand);
427
+ const sessionId = (0, import_js_sdk2.useReactor)((s) => s.sessionId);
428
+ const status = (0, import_js_sdk2.useReactor)((s) => s.status);
429
+ const tracks = (0, import_js_sdk2.useReactor)((s) => s.tracks);
430
+ const unpublish = (0, import_js_sdk2.useReactor)((s) => s.unpublish);
431
+ const uploadFile = (0, import_js_sdk2.useReactor)((s) => s.uploadFile);
432
+ return {
433
+ connect,
434
+ connectOptions,
435
+ disconnect,
436
+ downloadClipAsFile,
437
+ jwtToken,
438
+ lastError,
439
+ lastMessage,
440
+ pauseTrack,
441
+ publish,
442
+ reconnect,
443
+ requestClip,
444
+ requestRecording,
445
+ resumeTrack,
446
+ sendCommand,
447
+ sessionId,
448
+ status,
449
+ tracks,
450
+ unpublish,
451
+ uploadFile,
452
+ pop: async (params) => {
453
+ const reply = await sendCommand("pop", params);
454
+ return reply === void 0 ? void 0 : _unwrapMessage2(reply);
455
+ },
456
+ move: async (params) => {
457
+ const reply = await sendCommand("move", params);
458
+ return reply === void 0 ? void 0 : _unwrapMessage2(reply);
459
+ },
460
+ play: async (params) => {
461
+ await sendCommand("play", params);
462
+ return void 0;
463
+ },
464
+ stop: async () => {
465
+ await sendCommand("stop", {});
466
+ return void 0;
467
+ },
468
+ reset: async () => {
469
+ const reply = await sendCommand("reset", {});
470
+ return reply === void 0 ? void 0 : _unwrapMessage2(reply);
471
+ },
472
+ enqueue: async (params) => {
473
+ const reply = await sendCommand("enqueue", params);
474
+ return reply === void 0 ? void 0 : _unwrapMessage2(reply);
475
+ },
476
+ setSeed: async (params) => {
477
+ const reply = await sendCommand("set_seed", params);
478
+ return reply === void 0 ? void 0 : _unwrapMessage2(reply);
479
+ },
480
+ getQueue: async () => {
481
+ const reply = await sendCommand("get_queue", {});
482
+ return reply === void 0 ? void 0 : _unwrapMessage2(reply);
483
+ },
484
+ getState: async () => {
485
+ const reply = await sendCommand("get_state", {});
486
+ return reply === void 0 ? void 0 : _unwrapMessage2(reply);
487
+ },
488
+ setCanvas: async (params) => {
489
+ const reply = await sendCommand("set_canvas", params);
490
+ return reply === void 0 ? void 0 : _unwrapMessage2(reply);
491
+ },
492
+ setAutoplay: async (params) => {
493
+ const reply = await sendCommand("set_autoplay", params);
494
+ return reply === void 0 ? void 0 : _unwrapMessage2(reply);
495
+ },
496
+ setClipSeconds: async (params) => {
497
+ const reply = await sendCommand("set_clip_seconds", params);
498
+ return reply === void 0 ? void 0 : _unwrapMessage2(reply);
499
+ },
500
+ setFlushOnClipEnd: async (params) => {
501
+ const reply = await sendCommand("set_flush_on_clip_end", params);
502
+ return reply === void 0 ? void 0 : _unwrapMessage2(reply);
503
+ }
504
+ };
505
+ }
506
+ function useFastH3Message(handler) {
507
+ (0, import_js_sdk2.useReactorMessage)(
508
+ (msg) => handler(_unwrapMessage2(msg))
509
+ );
510
+ }
511
+ function useFastH3ClipMoved(handler) {
512
+ (0, import_js_sdk2.useReactorMessage)((msg) => {
513
+ const m = _unwrapMessage2(msg);
514
+ if (m.type === "clip_moved") {
515
+ handler(m);
516
+ }
517
+ });
518
+ }
519
+ function useFastH3ClipFailed(handler) {
520
+ (0, import_js_sdk2.useReactorMessage)((msg) => {
521
+ const m = _unwrapMessage2(msg);
522
+ if (m.type === "clip_failed") {
523
+ handler(m);
524
+ }
525
+ });
526
+ }
527
+ function useFastH3ClipPopped(handler) {
528
+ (0, import_js_sdk2.useReactorMessage)((msg) => {
529
+ const m = _unwrapMessage2(msg);
530
+ if (m.type === "clip_popped") {
531
+ handler(m);
532
+ }
533
+ });
534
+ }
535
+ function useFastH3ClipQueued(handler) {
536
+ (0, import_js_sdk2.useReactorMessage)((msg) => {
537
+ const m = _unwrapMessage2(msg);
538
+ if (m.type === "clip_queued") {
539
+ handler(m);
540
+ }
541
+ });
542
+ }
543
+ function useFastH3ClipStarted(handler) {
544
+ (0, import_js_sdk2.useReactorMessage)((msg) => {
545
+ const m = _unwrapMessage2(msg);
546
+ if (m.type === "clip_started") {
547
+ handler(m);
548
+ }
549
+ });
550
+ }
551
+ function useFastH3ClipStopped(handler) {
552
+ (0, import_js_sdk2.useReactorMessage)((msg) => {
553
+ const m = _unwrapMessage2(msg);
554
+ if (m.type === "clip_stopped") {
555
+ handler(m);
556
+ }
557
+ });
558
+ }
559
+ function useFastH3QueueUpdate(handler) {
560
+ (0, import_js_sdk2.useReactorMessage)((msg) => {
561
+ const m = _unwrapMessage2(msg);
562
+ if (m.type === "queue_update") {
563
+ handler(m);
564
+ }
565
+ });
566
+ }
567
+ function useFastH3StateUpdate(handler) {
568
+ (0, import_js_sdk2.useReactorMessage)((msg) => {
569
+ const m = _unwrapMessage2(msg);
570
+ if (m.type === "state_update") {
571
+ handler(m);
572
+ }
573
+ });
574
+ }
575
+ function useFastH3ClipFinished(handler) {
576
+ (0, import_js_sdk2.useReactorMessage)((msg) => {
577
+ const m = _unwrapMessage2(msg);
578
+ if (m.type === "clip_finished") {
579
+ handler(m);
580
+ }
581
+ });
582
+ }
583
+ function useFastH3CommandError(handler) {
584
+ (0, import_js_sdk2.useReactorMessage)((msg) => {
585
+ const m = _unwrapMessage2(msg);
586
+ if (m.type === "command_error") {
587
+ handler(m);
588
+ }
589
+ });
590
+ }
591
+ function useFastH3SeedAccepted(handler) {
592
+ (0, import_js_sdk2.useReactorMessage)((msg) => {
593
+ const m = _unwrapMessage2(msg);
594
+ if (m.type === "seed_accepted") {
595
+ handler(m);
596
+ }
597
+ });
598
+ }
599
+ function useFastH3SessionReset(handler) {
600
+ (0, import_js_sdk2.useReactorMessage)((msg) => {
601
+ const m = _unwrapMessage2(msg);
602
+ if (m.type === "session_reset") {
603
+ handler(m);
604
+ }
605
+ });
606
+ }
607
+ function useFastH3ClipGenerated(handler) {
608
+ (0, import_js_sdk2.useReactorMessage)((msg) => {
609
+ const m = _unwrapMessage2(msg);
610
+ if (m.type === "clip_generated") {
611
+ handler(m);
612
+ }
613
+ });
614
+ }
615
+ function useFastH3FlushAccepted(handler) {
616
+ (0, import_js_sdk2.useReactorMessage)((msg) => {
617
+ const m = _unwrapMessage2(msg);
618
+ if (m.type === "flush_accepted") {
619
+ handler(m);
620
+ }
621
+ });
622
+ }
623
+ function useFastH3CanvasAccepted(handler) {
624
+ (0, import_js_sdk2.useReactorMessage)((msg) => {
625
+ const m = _unwrapMessage2(msg);
626
+ if (m.type === "canvas_accepted") {
627
+ handler(m);
628
+ }
629
+ });
630
+ }
631
+ function useFastH3AutoplayAccepted(handler) {
632
+ (0, import_js_sdk2.useReactorMessage)((msg) => {
633
+ const m = _unwrapMessage2(msg);
634
+ if (m.type === "autoplay_accepted") {
635
+ handler(m);
636
+ }
637
+ });
638
+ }
639
+ function useFastH3ClipLengthAccepted(handler) {
640
+ (0, import_js_sdk2.useReactorMessage)((msg) => {
641
+ const m = _unwrapMessage2(msg);
642
+ if (m.type === "clip_length_accepted") {
643
+ handler(m);
644
+ }
645
+ });
646
+ }
647
+ function useFastH3Track(name) {
648
+ return (0, import_js_sdk2.useReactor)((s) => s.tracks[name]);
649
+ }
650
+ function FastH3MainVideoView(props) {
651
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_js_sdk2.ReactorView, { ...props, track: "main_video" });
652
+ }
653
+ // Annotate the CommonJS export names for ESM import in node:
654
+ 0 && (module.exports = {
655
+ FastH3MainVideoView,
656
+ FastH3Model,
657
+ FastH3Provider,
658
+ FastH3Tracks,
659
+ FileRef,
660
+ MODEL_NAME,
661
+ MODEL_VERSION,
662
+ useFastH3,
663
+ useFastH3AutoplayAccepted,
664
+ useFastH3CanvasAccepted,
665
+ useFastH3ClipFailed,
666
+ useFastH3ClipFinished,
667
+ useFastH3ClipGenerated,
668
+ useFastH3ClipLengthAccepted,
669
+ useFastH3ClipMoved,
670
+ useFastH3ClipPopped,
671
+ useFastH3ClipQueued,
672
+ useFastH3ClipStarted,
673
+ useFastH3ClipStopped,
674
+ useFastH3CommandError,
675
+ useFastH3FlushAccepted,
676
+ useFastH3Message,
677
+ useFastH3QueueUpdate,
678
+ useFastH3SeedAccepted,
679
+ useFastH3SessionReset,
680
+ useFastH3StateUpdate,
681
+ useFastH3Track
682
+ });
683
+ //# sourceMappingURL=index.js.map