@reactor-team/js-sdk 2.12.4 → 3.0.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/README.md +211 -172
- package/dist/index.cjs +2478 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1234 -0
- package/dist/index.d.ts +952 -1078
- package/dist/index.js +1644 -4103
- package/dist/index.js.map +1 -1
- package/dist/wasm/README.md +151 -0
- package/dist/wasm/package.json +21 -0
- package/dist/wasm/reactor_wasm.d.ts +422 -0
- package/dist/wasm/reactor_wasm.js +1428 -0
- package/dist/wasm/reactor_wasm_bg.wasm +0 -0
- package/dist/wasm/reactor_wasm_bg.wasm.d.ts +53 -0
- package/package.json +35 -53
- package/LICENSE +0 -201
- package/NOTICE +0 -5
- package/dist/index.d.mts +0 -1360
- package/dist/index.mjs +0 -4805
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# reactor-wasm
|
|
2
|
+
|
|
3
|
+
The browser binding for `reactor-core`. Implements the three host traits with
|
|
4
|
+
browser APIs and exposes one `wasm-bindgen` class, `ReactorClient`, for a
|
|
5
|
+
TypeScript SDK to wrap.
|
|
6
|
+
|
|
7
|
+
Native SDKs reach the core through `reactor-ffi`'s C ABI. A browser has no FFI,
|
|
8
|
+
and its media engine is `RTCPeerConnection` rather than libwebrtc, so the web
|
|
9
|
+
gets its own binding — and the same deal every other SDK gets: session
|
|
10
|
+
lifecycle, signaling, correlation, reconnection and error semantics live in the
|
|
11
|
+
core, once, and the binding stays thin.
|
|
12
|
+
|
|
13
|
+
```text
|
|
14
|
+
JavaScript / TypeScript
|
|
15
|
+
┌───────────────────────────────────────┐
|
|
16
|
+
│ ReactorClient (#[wasm_bindgen]) │
|
|
17
|
+
└──────┬────────────────────────────────┘
|
|
18
|
+
│ owns
|
|
19
|
+
┌───────────────┼─────────────────┬───────────────────┐
|
|
20
|
+
│ │ │ │
|
|
21
|
+
Arc<Reactor> WasmPeerTransport WasmAuthProvider WasmHttpClient
|
|
22
|
+
(reactor-core) RTCPeerConnection JS token source fetch
|
|
23
|
+
│ │
|
|
24
|
+
│ PeerEvent │ unbounded channel
|
|
25
|
+
pump task ◄─────────┘
|
|
26
|
+
│
|
|
27
|
+
ReactorEvent stream ──► registered JS listeners
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Building
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
mise run build:wasm # → crates/reactor-wasm/pkg (ES module + .d.ts + .wasm)
|
|
34
|
+
mise run clippy:wasm # lint the real code (see "Two targets" below)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`pkg/` is generated and not committed. The JS SDK depends on it.
|
|
38
|
+
|
|
39
|
+
## The interface
|
|
40
|
+
|
|
41
|
+
`pkg/reactor_wasm.d.ts` is the contract, generated from this crate. Its object
|
|
42
|
+
shapes are declared in [`src/types.rs`](src/types.rs), so the boundary is typed
|
|
43
|
+
rather than `any`:
|
|
44
|
+
|
|
45
|
+
| Area | Calls |
|
|
46
|
+
| --- | --- |
|
|
47
|
+
| Lifecycle | `connect(options?)`, `disconnect()`, `reconnect()` |
|
|
48
|
+
| Configuration | `setJwt(jwt)` |
|
|
49
|
+
| Messaging | `sendCommand(command, data?, uploads?)`, `requestSchema()` |
|
|
50
|
+
| Tracks | `publishTrack(name, track)`, `unpublishTrack(name)`, `pauseTrack(name)`, `resumeTrack(name)`, `tracks()`, `trackMapping()`, `pausedTracks()` |
|
|
51
|
+
| Recording | `requestClip(seconds)`, `requestRecording()` |
|
|
52
|
+
| Uploads | `uploadFile(file, name?)` |
|
|
53
|
+
| Introspection | `status()`, `sessionId()`, `sessionInfo()`, `capabilities()`, `lastError()` |
|
|
54
|
+
| Browser handles | `getPeerConnection()`, `getTrackByMid(mid)`, `getStreamByMid(mid)`, `getTrackByName(name)`, `getStreamByName(name)` |
|
|
55
|
+
| Events | `onStatusChanged`, `onSessionIdChanged`, `onMessage`, `onRuntimeMessage`, `onTrackReceived`, `onError`, `onCapabilitiesReceived` |
|
|
56
|
+
|
|
57
|
+
Payloads that come out of the core keep their wire names (`protocol_version`,
|
|
58
|
+
`retry_after_ms`, `playlist_url`); the options this crate defines itself are
|
|
59
|
+
camelCase, because nothing on the wire constrains them.
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
import init, { ReactorClient } from "./pkg/reactor_wasm.js";
|
|
63
|
+
|
|
64
|
+
await init();
|
|
65
|
+
const client = new ReactorClient({ modelName: "my-model" }, () => getToken());
|
|
66
|
+
|
|
67
|
+
client.onStatusChanged((status) => console.log(status));
|
|
68
|
+
client.onTrackReceived((name, mid) => {
|
|
69
|
+
if (name === "output") video.srcObject = client.getStreamByMid(mid);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
await client.connect();
|
|
73
|
+
await client.sendCommand("set_prompt", { prompt: "a cat" });
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Mapping the existing JS SDK onto it
|
|
77
|
+
|
|
78
|
+
The next `@reactor-team/js-sdk` has to be a drop-in for 2.x, so every v2
|
|
79
|
+
affordance is reachable from here:
|
|
80
|
+
|
|
81
|
+
| `@reactor-team/js-sdk` 2.x | reactor-wasm |
|
|
82
|
+
| --- | --- |
|
|
83
|
+
| `new Reactor({apiUrl, modelName, local})` | `new ReactorClient(options, jwt?)` |
|
|
84
|
+
| `connect(jwt, {sessionId, connectionId, autoResumeTracks, maxAttempts})` | `setJwt(jwt)` then `connect(options)` |
|
|
85
|
+
| `disconnect(recoverable)` | `disconnect()` (recoverable teardown is `reconnect()`) |
|
|
86
|
+
| `sendCommand(cmd, data)` with `FileRef` values | `sendCommand(cmd, data, uploads)` — the SDK splits the two |
|
|
87
|
+
| `uploadFile(File \| Blob, {name})` | `uploadFile(file, name?)` |
|
|
88
|
+
| `publishTrack` / `unpublishTrack` / `pauseTrack` / `resumeTrack` | same |
|
|
89
|
+
| `requestClip` / `requestRecording` | same |
|
|
90
|
+
| `getStatus` / `getSessionId` / `getLastError` | `status()` / `sessionId()` / `lastError()` |
|
|
91
|
+
| `getSessionInfo()` | `sessionInfo()` |
|
|
92
|
+
| `getSchema()` + `schemaReceived` | `requestSchema()`, which the SDK calls on ready |
|
|
93
|
+
| `trackReceived(name, track, stream)` | `onTrackReceived(name, mid)` + `getTrackByMid` / `getStreamByMid` |
|
|
94
|
+
| `getStats()` + `statsUpdate` | computed in TS from `getPeerConnection()` |
|
|
95
|
+
| `sessionExpirationChanged` | emitted by the SDK; v2 only ever fired it with `undefined` on teardown |
|
|
96
|
+
|
|
97
|
+
`scope: "runtime"` commands have no equivalent and need none: what used to be a
|
|
98
|
+
runtime-scoped data-channel command is now a typed control-channel request, so
|
|
99
|
+
clip and recording requests are the methods above.
|
|
100
|
+
|
|
101
|
+
## Design notes
|
|
102
|
+
|
|
103
|
+
**Two targets.** Off a wasm target this crate compiles to nothing — every module
|
|
104
|
+
is `#[cfg(target_family = "wasm")]` and the browser dependencies are declared
|
|
105
|
+
per-target. So `cargo check --workspace` on Linux or macOS stays fast and green,
|
|
106
|
+
and `clippy:wasm` is what actually lints the code. CI runs both.
|
|
107
|
+
|
|
108
|
+
**No `Send`.** `reactor-core` drops its `Send + Sync` bounds under
|
|
109
|
+
`target_family = "wasm"`. Browser handles belong to the agent that made them and
|
|
110
|
+
are not `Send`; wasm is single-threaded, so the bound protects nothing there.
|
|
111
|
+
Native builds are untouched.
|
|
112
|
+
|
|
113
|
+
**Binary channels.** The wire is `reactor_wire.v1` protobuf, so both data
|
|
114
|
+
channels are opened with `binaryType = "arraybuffer"` — otherwise frames arrive
|
|
115
|
+
as `Blob`s and would need an async read before the core could decode them.
|
|
116
|
+
|
|
117
|
+
**No SDP munging.** The offer goes out as the browser wrote it. The JS SDK
|
|
118
|
+
rewrites its own offer today — payload types remapped into [96,127],
|
|
119
|
+
telephone-event stripped, attributes reordered — but that exists for a GStreamer
|
|
120
|
+
runtime that mishandled H265 on payload type 45, which is not the runtime this
|
|
121
|
+
client talks to. Rewriting an offer that needs no rewriting is a way to break
|
|
122
|
+
codec negotiation, so the new SDK should drop `utils/sdp.ts` rather than port
|
|
123
|
+
it. If some future runtime needs it back, it belongs behind a hook here, not as
|
|
124
|
+
an unconditional transform.
|
|
125
|
+
|
|
126
|
+
**Errors.** A rejected call throws an `Error` with `name === "ReactorError"`
|
|
127
|
+
carrying the core's `code`, `recoverable`, `status`, `operation` and
|
|
128
|
+
`retry_after_ms` — the same fields, under the same names, as the `onError`
|
|
129
|
+
event. Codes are open-ended: the platform can send its own, so unknown values
|
|
130
|
+
must be tolerated rather than treated as a parse failure.
|
|
131
|
+
|
|
132
|
+
**Token sources.** `jwt` takes a string or a `() => string | Promise<string>`
|
|
133
|
+
resolver called before every authenticated request, which is what short-lived
|
|
134
|
+
tokens need. `""` sends no `Authorization` header.
|
|
135
|
+
|
|
136
|
+
**Keep-alive.** `connect()` and `reconnect()` spawn the core's heartbeat; it
|
|
137
|
+
exits on its own when the connection ends or another connect starts.
|
|
138
|
+
|
|
139
|
+
**Lifetime.** A JS holder should `disconnect()` and then `free()` the client (or
|
|
140
|
+
use `Symbol.dispose`) when it is done. `free()` cancels the pump, the dispatcher
|
|
141
|
+
and the heartbeat, and closes the peer connection, which is what lets the whole
|
|
142
|
+
graph be collected — the tasks hold the reactor, and the reactor holds the
|
|
143
|
+
transport whose sender feeds the pump, so nothing else can break that cycle.
|
|
144
|
+
Ending the session stays `disconnect()`'s job: tearing one down because a handle
|
|
145
|
+
was collected would be a surprising thing for a `free()` to do over the network.
|
|
146
|
+
|
|
147
|
+
## What lives above this crate
|
|
148
|
+
|
|
149
|
+
Stats collection, the React surface, clip playback and download, the v2
|
|
150
|
+
compatibility shim, and the store — all TypeScript, all in the SDK. This crate
|
|
151
|
+
draws the line at the protocol.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "reactor-wasm",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "WebAssembly binding for reactor-core: implements the host traits with browser APIs and exposes a wasm-bindgen client to JavaScript",
|
|
5
|
+
"version": "0.1.0",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/reactor-team/reactor-client-sdks"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"reactor_wasm_bg.wasm",
|
|
13
|
+
"reactor_wasm.js",
|
|
14
|
+
"reactor_wasm.d.ts"
|
|
15
|
+
],
|
|
16
|
+
"main": "reactor_wasm.js",
|
|
17
|
+
"types": "reactor_wasm.d.ts",
|
|
18
|
+
"sideEffects": [
|
|
19
|
+
"./snippets/*"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
export type ReactorStatus = "disconnected" | "connecting" | "waiting" | "ready";
|
|
5
|
+
export type TrackKind = "audio" | "video";
|
|
6
|
+
export type TrackDirection = "recvonly" | "sendonly";
|
|
7
|
+
|
|
8
|
+
/** Construction options. Only `modelName` is required. */
|
|
9
|
+
export interface ClientOptions {
|
|
10
|
+
modelName: string;
|
|
11
|
+
/** Coordinator base URL. Defaults to the cloud coordinator, or to
|
|
12
|
+
* http://localhost:8080 when `local` is set. */
|
|
13
|
+
apiUrl?: string;
|
|
14
|
+
/** Talk to a local runtime's HTTP API instead of the cloud coordinator. */
|
|
15
|
+
local?: boolean;
|
|
16
|
+
/** Reported to the coordinator in `client_info`. Defaults to "js". */
|
|
17
|
+
sdkType?: string;
|
|
18
|
+
sdkVersion?: string;
|
|
19
|
+
/** Resume every recvonly track on connect. Default true. */
|
|
20
|
+
autoResumeTracks?: boolean;
|
|
21
|
+
/** Free-form model arguments, sent on session creation. */
|
|
22
|
+
extraArgs?: Record<string, unknown>;
|
|
23
|
+
/** Keep-alive period. 0 disables the heartbeat. Default 10000. */
|
|
24
|
+
heartbeatIntervalMs?: number;
|
|
25
|
+
/** How long to wait for the transport to come up. Default 30000. */
|
|
26
|
+
readyTimeoutMs?: number;
|
|
27
|
+
controlRequestTimeoutMs?: number;
|
|
28
|
+
clipRequestTimeoutMs?: number;
|
|
29
|
+
/** Session-readiness poll attempts. Default 20. */
|
|
30
|
+
maxSessionAttempts?: number;
|
|
31
|
+
/** SDP-answer poll attempts. Default 6. */
|
|
32
|
+
maxSdpAttempts?: number;
|
|
33
|
+
/** Initial delay before the first SDP-answer poll retry, in ms. Default 200. */
|
|
34
|
+
sdpBackoffInitialMs?: number;
|
|
35
|
+
/** Cap on the exponential backoff between SDP-answer poll retries, in ms. Default 15000. */
|
|
36
|
+
sdpBackoffMaxMs?: number;
|
|
37
|
+
/** Growth factor applied to the delay between SDP-answer poll retries. Default 2. */
|
|
38
|
+
sdpBackoffMultiplier?: number;
|
|
39
|
+
/** Preset tracks, when known ahead of time — builds the SDP offer
|
|
40
|
+
* concurrently with the session-ready poll rather than after. */
|
|
41
|
+
modelTracks?: TrackCapability[];
|
|
42
|
+
/** Console log level. Default "warn". */
|
|
43
|
+
logLevel?: "off" | "error" | "warn" | "info" | "debug" | "trace";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Per-connect options. Every field optional. Also accepted by `reconnect()`,
|
|
47
|
+
* which only honors `maxAttempts` — the rest only make sense when
|
|
48
|
+
* establishing a session in the first place. */
|
|
49
|
+
export interface ConnectOptions {
|
|
50
|
+
/** Adopt an existing session instead of creating one. An adopting client
|
|
51
|
+
* never ends the session it joined. */
|
|
52
|
+
sessionId?: string;
|
|
53
|
+
/** Use a connection id already registered under that session. */
|
|
54
|
+
connectionId?: number;
|
|
55
|
+
/** Override `ClientOptions.autoResumeTracks` for this connection and the
|
|
56
|
+
* reconnects that follow it. */
|
|
57
|
+
autoResumeTracks?: boolean;
|
|
58
|
+
/** SDP-answer poll attempts before giving up. */
|
|
59
|
+
maxAttempts?: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** A token, or a resolver called before every authenticated request.
|
|
63
|
+
* Returning "" sends no Authorization header. */
|
|
64
|
+
export type JwtSource = string | (() => string | Promise<string>);
|
|
65
|
+
|
|
66
|
+
export interface TrackCapability {
|
|
67
|
+
name: string;
|
|
68
|
+
kind: TrackKind;
|
|
69
|
+
direction: TrackDirection;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface TrackMappingEntry extends TrackCapability {
|
|
73
|
+
/** The SDP media-section id this track negotiated onto. */
|
|
74
|
+
mid: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface CommandCapability {
|
|
78
|
+
name: string;
|
|
79
|
+
description?: string;
|
|
80
|
+
schema?: unknown;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface Capabilities {
|
|
84
|
+
protocol_version: string;
|
|
85
|
+
tracks: TrackCapability[];
|
|
86
|
+
commands?: CommandCapability[];
|
|
87
|
+
emission_fps?: number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The session resource, as the coordinator reports it. */
|
|
91
|
+
export interface SessionInfo {
|
|
92
|
+
session_id: string;
|
|
93
|
+
state: string;
|
|
94
|
+
model?: { name: string; version?: string };
|
|
95
|
+
cluster?: string;
|
|
96
|
+
server_info?: { server_version: string };
|
|
97
|
+
selected_transport?: { protocol: string; version: string };
|
|
98
|
+
capabilities?: Capabilities;
|
|
99
|
+
/** Fields newer servers add are preserved rather than dropped. */
|
|
100
|
+
[key: string]: unknown;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** A completed upload, to pass in a command's `uploads`. */
|
|
104
|
+
export interface FileRef {
|
|
105
|
+
upload_id: string;
|
|
106
|
+
name: string;
|
|
107
|
+
mime_type: string;
|
|
108
|
+
size: number;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** A captured clip or recording. */
|
|
112
|
+
export interface Clip {
|
|
113
|
+
session_id: string;
|
|
114
|
+
/** "snap" for requestClip, "recording" for requestRecording. */
|
|
115
|
+
kind: string;
|
|
116
|
+
start_marker: number;
|
|
117
|
+
end_marker: number;
|
|
118
|
+
now_marker: number;
|
|
119
|
+
predicted_ready_at_ms: number;
|
|
120
|
+
/** Absolute HLS manifest URL. */
|
|
121
|
+
playlist_url: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface ReactorMessage {
|
|
125
|
+
type: string;
|
|
126
|
+
data: unknown;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** A failure, in the terms a caller can act on. Rejected calls throw an `Error`
|
|
130
|
+
* carrying these same fields, with `name === "ReactorError"`. */
|
|
131
|
+
export interface ReactorError {
|
|
132
|
+
/** A stable code — DISCONNECTED, REQUEST_TIMEOUT, UNAUTHORIZED, … — or one
|
|
133
|
+
* the platform sent, so unknown values must be tolerated. */
|
|
134
|
+
code: string;
|
|
135
|
+
message: string;
|
|
136
|
+
/** Whether the same call could succeed later. */
|
|
137
|
+
recoverable: boolean;
|
|
138
|
+
/** The HTTP status, when the failure came from one. */
|
|
139
|
+
status?: number;
|
|
140
|
+
/** Which call failed, e.g. "connect", "sendCommand". */
|
|
141
|
+
operation?: string;
|
|
142
|
+
/** Backoff hint the platform sent. */
|
|
143
|
+
retry_after_ms?: number;
|
|
144
|
+
timestamp_ms: number;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export type StatusListener = (status: ReactorStatus) => void;
|
|
148
|
+
export type SessionIdListener = (sessionId: string | undefined) => void;
|
|
149
|
+
export type MessageListener = (message: ReactorMessage) => void;
|
|
150
|
+
export type TrackListener = (name: string, mid: string | undefined) => void;
|
|
151
|
+
export type ErrorListener = (error: ReactorError) => void;
|
|
152
|
+
export type CapabilitiesListener = (capabilities: Capabilities) => void;
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* The Reactor client, as JavaScript sees it.
|
|
158
|
+
*
|
|
159
|
+
* ```js
|
|
160
|
+
* import init, { ReactorClient } from "@reactor-team/reactor-wasm";
|
|
161
|
+
*
|
|
162
|
+
* await init();
|
|
163
|
+
* const client = new ReactorClient({ modelName: "my-model" }, () => getToken());
|
|
164
|
+
* client.onStatusChanged((status) => console.log(status));
|
|
165
|
+
* client.onTrackReceived((name, mid) => {
|
|
166
|
+
* video.srcObject = client.getStreamByMid(mid);
|
|
167
|
+
* });
|
|
168
|
+
* await client.connect();
|
|
169
|
+
* await client.sendCommand("set_prompt", { prompt: "a cat" });
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export class ReactorClient {
|
|
173
|
+
free(): void;
|
|
174
|
+
[Symbol.dispose](): void;
|
|
175
|
+
/**
|
|
176
|
+
* The runtime's capabilities, or `undefined` before they arrive.
|
|
177
|
+
*/
|
|
178
|
+
capabilities(): Capabilities | undefined;
|
|
179
|
+
/**
|
|
180
|
+
* Create (or adopt) a session and bring up the transport.
|
|
181
|
+
*/
|
|
182
|
+
connect(options?: ConnectOptions | null): Promise<void>;
|
|
183
|
+
/**
|
|
184
|
+
* Tear down the transport and end the session server-side — unless this
|
|
185
|
+
* client only adopted the session, in which case it stays alive for
|
|
186
|
+
* whoever created it.
|
|
187
|
+
*/
|
|
188
|
+
disconnect(): Promise<void>;
|
|
189
|
+
/**
|
|
190
|
+
* The live `RTCPeerConnection` — for `getStats()`, or anything else the
|
|
191
|
+
* binding does not wrap. `undefined` before the first connect.
|
|
192
|
+
*/
|
|
193
|
+
getPeerConnection(): RTCPeerConnection | undefined;
|
|
194
|
+
/**
|
|
195
|
+
* The `MediaStream` a received track arrived on — what a `<video>` or
|
|
196
|
+
* `<audio>` element's `srcObject` wants.
|
|
197
|
+
*/
|
|
198
|
+
getStreamByMid(mid: string): MediaStream | undefined;
|
|
199
|
+
/**
|
|
200
|
+
* The stream of a received track, by declared name.
|
|
201
|
+
*/
|
|
202
|
+
getStreamByName(name: string): MediaStream | undefined;
|
|
203
|
+
/**
|
|
204
|
+
* A received track by its SDP mid, as reported by `onTrackReceived`.
|
|
205
|
+
*/
|
|
206
|
+
getTrackByMid(mid: string): MediaStreamTrack | undefined;
|
|
207
|
+
/**
|
|
208
|
+
* A received track by its declared name.
|
|
209
|
+
*
|
|
210
|
+
* Useful when the track arrived before the listener was registered — a
|
|
211
|
+
* component that mounts mid-connect misses the event but not the track.
|
|
212
|
+
*/
|
|
213
|
+
getTrackByName(name: string): MediaStreamTrack | undefined;
|
|
214
|
+
/**
|
|
215
|
+
* The last error, in the shape the `onError` listener receives.
|
|
216
|
+
*/
|
|
217
|
+
lastError(): ReactorError | undefined;
|
|
218
|
+
/**
|
|
219
|
+
* Create a client.
|
|
220
|
+
*
|
|
221
|
+
* * `options` — see the `ClientOptions` fields; `modelName` is required.
|
|
222
|
+
* * `jwt` — a token string, a `() => string | Promise<string>` resolver
|
|
223
|
+
* called before every authenticated request, or `null` for an
|
|
224
|
+
* unauthenticated local runtime. Replaceable later with `setJwt`.
|
|
225
|
+
*/
|
|
226
|
+
constructor(options: ClientOptions, jwt?: JwtSource | null);
|
|
227
|
+
/**
|
|
228
|
+
* `(capabilities: { protocolVersion, tracks, commands? }) => void`
|
|
229
|
+
*/
|
|
230
|
+
onCapabilitiesReceived(listener: CapabilitiesListener): void;
|
|
231
|
+
/**
|
|
232
|
+
* `(error: { code, message, recoverable, timestampMs, status?, operation?,
|
|
233
|
+
* retryAfterMs? }) => void`
|
|
234
|
+
*/
|
|
235
|
+
onError(listener: ErrorListener): void;
|
|
236
|
+
/**
|
|
237
|
+
* `(message: { type, data }) => void` — application messages from the model.
|
|
238
|
+
*/
|
|
239
|
+
onMessage(listener: MessageListener): void;
|
|
240
|
+
/**
|
|
241
|
+
* `(message: { type, data }) => void` — platform messages: moderation,
|
|
242
|
+
* recording lifecycle, and the rest of the runtime's own traffic.
|
|
243
|
+
*/
|
|
244
|
+
onRuntimeMessage(listener: MessageListener): void;
|
|
245
|
+
/**
|
|
246
|
+
* `(sessionId: string | undefined) => void`
|
|
247
|
+
*/
|
|
248
|
+
onSessionIdChanged(listener: SessionIdListener): void;
|
|
249
|
+
/**
|
|
250
|
+
* `(status: string) => void`
|
|
251
|
+
*/
|
|
252
|
+
onStatusChanged(listener: StatusListener): void;
|
|
253
|
+
/**
|
|
254
|
+
* `(name: string, mid: string | undefined) => void` — a remote track
|
|
255
|
+
* arrived. Fetch the media with `getTrackByMid` / `getStreamByMid`.
|
|
256
|
+
*/
|
|
257
|
+
onTrackReceived(listener: TrackListener): void;
|
|
258
|
+
/**
|
|
259
|
+
* Stop receiving a track: the receiver goes inactive and the runtime stops
|
|
260
|
+
* producing it.
|
|
261
|
+
*/
|
|
262
|
+
pauseTrack(name: string): Promise<void>;
|
|
263
|
+
/**
|
|
264
|
+
* Names of the tracks currently paused.
|
|
265
|
+
*/
|
|
266
|
+
pausedTracks(): string[];
|
|
267
|
+
/**
|
|
268
|
+
* Claim a sendonly track and start sending `track` on it.
|
|
269
|
+
*/
|
|
270
|
+
publishTrack(name: string, track: MediaStreamTrack): Promise<void>;
|
|
271
|
+
/**
|
|
272
|
+
* Rebuild the transport on the same session, without ending it.
|
|
273
|
+
*
|
|
274
|
+
* Only `maxAttempts` applies here — the rest of `ConnectOptions` (session
|
|
275
|
+
* adoption, connection id, auto-resume) only makes sense at initial
|
|
276
|
+
* connect time, same as the JS SDK's own `reconnect()` always ignored
|
|
277
|
+
* them.
|
|
278
|
+
*/
|
|
279
|
+
reconnect(options?: ConnectOptions | null): Promise<void>;
|
|
280
|
+
/**
|
|
281
|
+
* Capture the last `durationSeconds` of the session.
|
|
282
|
+
*/
|
|
283
|
+
requestClip(duration_seconds: number): Promise<Clip>;
|
|
284
|
+
/**
|
|
285
|
+
* Capture the session in full.
|
|
286
|
+
*/
|
|
287
|
+
requestRecording(): Promise<Clip>;
|
|
288
|
+
/**
|
|
289
|
+
* Request the model's command schema (an OpenAPI document).
|
|
290
|
+
*/
|
|
291
|
+
requestSchema(): Promise<unknown>;
|
|
292
|
+
/**
|
|
293
|
+
* Resume a paused track.
|
|
294
|
+
*/
|
|
295
|
+
resumeTrack(name: string): Promise<void>;
|
|
296
|
+
/**
|
|
297
|
+
* Send a command to the model and resolve with its reply.
|
|
298
|
+
*
|
|
299
|
+
* * `data` — a JSON-serializable object.
|
|
300
|
+
* * `uploads` — optional `{ param: FileRef }` map, from `uploadFile`.
|
|
301
|
+
*
|
|
302
|
+
* Resolves with `{ type, data }`, or `undefined` when the model's handler
|
|
303
|
+
* acknowledged the command without answering.
|
|
304
|
+
*/
|
|
305
|
+
sendCommand(command: string, data?: Record<string, unknown> | null, uploads?: Record<string, FileRef> | null): Promise<ReactorMessage | undefined>;
|
|
306
|
+
/**
|
|
307
|
+
* The current session id, or `undefined`.
|
|
308
|
+
*/
|
|
309
|
+
sessionId(): string | undefined;
|
|
310
|
+
/**
|
|
311
|
+
* The session resource from the coordinator, or `undefined` when
|
|
312
|
+
* disconnected: model, cluster, server info, selected transport.
|
|
313
|
+
*/
|
|
314
|
+
sessionInfo(): SessionInfo | undefined;
|
|
315
|
+
/**
|
|
316
|
+
* Replace the token source. Takes effect on the next request, so this is
|
|
317
|
+
* how a client built before sign-in gets its token.
|
|
318
|
+
*/
|
|
319
|
+
setJwt(jwt?: JwtSource | null): void;
|
|
320
|
+
/**
|
|
321
|
+
* `"disconnected"` | `"connecting"` | `"waiting"` | `"ready"`.
|
|
322
|
+
*/
|
|
323
|
+
status(): ReactorStatus;
|
|
324
|
+
/**
|
|
325
|
+
* The negotiated `name` → `mid` mapping: `[{ name, kind, direction, mid }]`.
|
|
326
|
+
*/
|
|
327
|
+
trackMapping(): TrackMappingEntry[];
|
|
328
|
+
/**
|
|
329
|
+
* The tracks the runtime declared for this session:
|
|
330
|
+
* `[{ name, kind, direction }]`. Empty until capabilities arrive.
|
|
331
|
+
*/
|
|
332
|
+
tracks(): TrackCapability[];
|
|
333
|
+
/**
|
|
334
|
+
* Stop sending on a published track and release it.
|
|
335
|
+
*/
|
|
336
|
+
unpublishTrack(name: string): Promise<void>;
|
|
337
|
+
/**
|
|
338
|
+
* Upload a `File` or `Blob` to the session's object store and resolve with
|
|
339
|
+
* a `FileRef` to pass in a command's `uploads`.
|
|
340
|
+
*
|
|
341
|
+
* `name` overrides the file name; a `Blob` has none, so it needs one.
|
|
342
|
+
*/
|
|
343
|
+
uploadFile(file: Blob, name?: string | null): Promise<FileRef>;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
347
|
+
|
|
348
|
+
export interface InitOutput {
|
|
349
|
+
readonly memory: WebAssembly.Memory;
|
|
350
|
+
readonly __wbg_reactorclient_free: (a: number, b: number) => void;
|
|
351
|
+
readonly reactorclient_capabilities: (a: number) => [number, number, number];
|
|
352
|
+
readonly reactorclient_connect: (a: number, b: number) => any;
|
|
353
|
+
readonly reactorclient_disconnect: (a: number) => any;
|
|
354
|
+
readonly reactorclient_getPeerConnection: (a: number) => any;
|
|
355
|
+
readonly reactorclient_getStreamByMid: (a: number, b: number, c: number) => any;
|
|
356
|
+
readonly reactorclient_getStreamByName: (a: number, b: number, c: number) => any;
|
|
357
|
+
readonly reactorclient_getTrackByMid: (a: number, b: number, c: number) => any;
|
|
358
|
+
readonly reactorclient_getTrackByName: (a: number, b: number, c: number) => any;
|
|
359
|
+
readonly reactorclient_lastError: (a: number) => [number, number, number];
|
|
360
|
+
readonly reactorclient_new: (a: any, b: number) => [number, number, number];
|
|
361
|
+
readonly reactorclient_onCapabilitiesReceived: (a: number, b: any) => void;
|
|
362
|
+
readonly reactorclient_onError: (a: number, b: any) => void;
|
|
363
|
+
readonly reactorclient_onMessage: (a: number, b: any) => void;
|
|
364
|
+
readonly reactorclient_onRuntimeMessage: (a: number, b: any) => void;
|
|
365
|
+
readonly reactorclient_onSessionIdChanged: (a: number, b: any) => void;
|
|
366
|
+
readonly reactorclient_onStatusChanged: (a: number, b: any) => void;
|
|
367
|
+
readonly reactorclient_onTrackReceived: (a: number, b: any) => void;
|
|
368
|
+
readonly reactorclient_pauseTrack: (a: number, b: number, c: number) => any;
|
|
369
|
+
readonly reactorclient_pausedTracks: (a: number) => [number, number, number];
|
|
370
|
+
readonly reactorclient_publishTrack: (a: number, b: number, c: number, d: any) => any;
|
|
371
|
+
readonly reactorclient_reconnect: (a: number, b: number) => any;
|
|
372
|
+
readonly reactorclient_requestClip: (a: number, b: number) => any;
|
|
373
|
+
readonly reactorclient_requestRecording: (a: number) => any;
|
|
374
|
+
readonly reactorclient_requestSchema: (a: number) => any;
|
|
375
|
+
readonly reactorclient_resumeTrack: (a: number, b: number, c: number) => any;
|
|
376
|
+
readonly reactorclient_sendCommand: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
377
|
+
readonly reactorclient_sessionId: (a: number) => [number, number];
|
|
378
|
+
readonly reactorclient_sessionInfo: (a: number) => [number, number, number];
|
|
379
|
+
readonly reactorclient_setJwt: (a: number, b: number) => [number, number];
|
|
380
|
+
readonly reactorclient_status: (a: number) => any;
|
|
381
|
+
readonly reactorclient_trackMapping: (a: number) => [number, number, number];
|
|
382
|
+
readonly reactorclient_tracks: (a: number) => [number, number, number];
|
|
383
|
+
readonly reactorclient_unpublishTrack: (a: number, b: number, c: number) => any;
|
|
384
|
+
readonly reactorclient_uploadFile: (a: number, b: any, c: number, d: number) => any;
|
|
385
|
+
readonly wasm_bindgen_85f920685b213f97___convert__closures_____invoke___wasm_bindgen_85f920685b213f97___JsValue__core_9b3796e30d99ddb7___result__Result_____wasm_bindgen_85f920685b213f97___JsError___true_: (a: number, b: number, c: any) => [number, number];
|
|
386
|
+
readonly wasm_bindgen_85f920685b213f97___convert__closures_____invoke___js_sys_17f5e83adf9a2bda___Function_fn_wasm_bindgen_85f920685b213f97___JsValue_____wasm_bindgen_85f920685b213f97___sys__Undefined___js_sys_17f5e83adf9a2bda___Function_fn_wasm_bindgen_85f920685b213f97___JsValue_____wasm_bindgen_85f920685b213f97___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
|
|
387
|
+
readonly wasm_bindgen_85f920685b213f97___convert__closures_____invoke___web_sys_43688100395f4fe3___features__gen_MessageEvent__MessageEvent______true_: (a: number, b: number, c: any) => void;
|
|
388
|
+
readonly wasm_bindgen_85f920685b213f97___convert__closures_____invoke___web_sys_43688100395f4fe3___features__gen_MessageEvent__MessageEvent______true__2: (a: number, b: number, c: any) => void;
|
|
389
|
+
readonly wasm_bindgen_85f920685b213f97___convert__closures_____invoke___web_sys_43688100395f4fe3___features__gen_MessageEvent__MessageEvent______true__3: (a: number, b: number, c: any) => void;
|
|
390
|
+
readonly wasm_bindgen_85f920685b213f97___convert__closures_____invoke_______true_: (a: number, b: number) => void;
|
|
391
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
392
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
393
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
394
|
+
readonly __externref_table_alloc: () => number;
|
|
395
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
396
|
+
readonly __wbindgen_destroy_closure: (a: number, b: number) => void;
|
|
397
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
398
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
399
|
+
readonly __wbindgen_start: () => void;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
406
|
+
* a precompiled `WebAssembly.Module`.
|
|
407
|
+
*
|
|
408
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
409
|
+
*
|
|
410
|
+
* @returns {InitOutput}
|
|
411
|
+
*/
|
|
412
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
416
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
417
|
+
*
|
|
418
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
419
|
+
*
|
|
420
|
+
* @returns {Promise<InitOutput>}
|
|
421
|
+
*/
|
|
422
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|