@reactor-team/js-sdk 2.7.0 → 2.8.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/dist/index.d.mts +16 -211
- package/dist/index.d.ts +16 -211
- package/dist/index.js +25 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -58
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -9,10 +9,6 @@ import React, { ReactNode } from 'react';
|
|
|
9
9
|
* Version constants are sourced from package.json via resolveJsonModule.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
declare const TransportDeclarationSchema: z.ZodObject<{
|
|
13
|
-
protocol: z.ZodString;
|
|
14
|
-
version: z.ZodString;
|
|
15
|
-
}, z.core.$strip>;
|
|
16
12
|
declare const TrackCapabilitySchema: z.ZodObject<{
|
|
17
13
|
name: z.ZodString;
|
|
18
14
|
kind: z.ZodEnum<{
|
|
@@ -49,22 +45,22 @@ declare const CapabilitiesSchema: z.ZodObject<{
|
|
|
49
45
|
}, z.core.$strip>>>;
|
|
50
46
|
emission_fps: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
51
47
|
}, z.core.$strip>;
|
|
52
|
-
declare const
|
|
48
|
+
declare const SessionResponseSchema: z.ZodObject<{
|
|
53
49
|
session_id: z.ZodString;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}, z.core.$strip>>;
|
|
50
|
+
state: z.ZodString;
|
|
51
|
+
cluster: z.ZodString;
|
|
57
52
|
model: z.ZodObject<{
|
|
58
53
|
name: z.ZodString;
|
|
59
54
|
version: z.ZodOptional<z.ZodString>;
|
|
60
55
|
}, z.core.$strip>;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
56
|
+
server_info: z.ZodObject<{
|
|
57
|
+
server_version: z.ZodString;
|
|
58
|
+
}, z.core.$strip>;
|
|
59
|
+
selected_transport: z.ZodOptional<z.ZodObject<{
|
|
64
60
|
protocol: z.ZodString;
|
|
65
61
|
version: z.ZodString;
|
|
66
|
-
}, z.core.$strip
|
|
67
|
-
capabilities: z.ZodObject<{
|
|
62
|
+
}, z.core.$strip>>;
|
|
63
|
+
capabilities: z.ZodOptional<z.ZodObject<{
|
|
68
64
|
protocol_version: z.ZodString;
|
|
69
65
|
tracks: z.ZodArray<z.ZodObject<{
|
|
70
66
|
name: z.ZodString;
|
|
@@ -83,12 +79,11 @@ declare const CreateSessionResponseSchema: z.ZodObject<{
|
|
|
83
79
|
schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
84
80
|
}, z.core.$strip>>>;
|
|
85
81
|
emission_fps: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
86
|
-
}, z.core.$strip
|
|
82
|
+
}, z.core.$strip>>;
|
|
87
83
|
}, z.core.$strip>;
|
|
88
|
-
type TransportDeclaration = z.infer<typeof TransportDeclarationSchema>;
|
|
89
84
|
type TrackCapability = z.infer<typeof TrackCapabilitySchema>;
|
|
90
85
|
type CommandCapability = z.infer<typeof CommandCapabilitySchema>;
|
|
91
|
-
type
|
|
86
|
+
type SessionResponse = z.infer<typeof SessionResponseSchema>;
|
|
92
87
|
type Capabilities = z.infer<typeof CapabilitiesSchema>;
|
|
93
88
|
|
|
94
89
|
type ReactorStatus = "disconnected" | "connecting" | "waiting" | "ready";
|
|
@@ -168,7 +163,7 @@ declare const OptionsSchema: z.ZodObject<{
|
|
|
168
163
|
local: z.ZodDefault<z.ZodBoolean>;
|
|
169
164
|
}, z.core.$strip>;
|
|
170
165
|
type Options = z.input<typeof OptionsSchema>;
|
|
171
|
-
type EventHandler
|
|
166
|
+
type EventHandler = (...args: any[]) => void;
|
|
172
167
|
declare class Reactor {
|
|
173
168
|
private coordinatorClient;
|
|
174
169
|
private transportClient;
|
|
@@ -186,8 +181,8 @@ declare class Reactor {
|
|
|
186
181
|
private sessionResponse?;
|
|
187
182
|
constructor(options: Options);
|
|
188
183
|
private eventListeners;
|
|
189
|
-
on(event: ReactorEvent, handler: EventHandler
|
|
190
|
-
off(event: ReactorEvent, handler: EventHandler
|
|
184
|
+
on(event: ReactorEvent, handler: EventHandler): void;
|
|
185
|
+
off(event: ReactorEvent, handler: EventHandler): void;
|
|
191
186
|
emit(event: ReactorEvent, ...args: any[]): void;
|
|
192
187
|
/**
|
|
193
188
|
* Sends a command to the model via the data channel.
|
|
@@ -223,7 +218,7 @@ declare class Reactor {
|
|
|
223
218
|
getState(): ReactorState$1;
|
|
224
219
|
getLastError(): ReactorError | undefined;
|
|
225
220
|
getCapabilities(): Capabilities | undefined;
|
|
226
|
-
getSessionInfo():
|
|
221
|
+
getSessionInfo(): SessionResponse | undefined;
|
|
227
222
|
getStats(): ConnectionStats | undefined;
|
|
228
223
|
private setSessionId;
|
|
229
224
|
private setStatus;
|
|
@@ -233,183 +228,6 @@ declare class Reactor {
|
|
|
233
228
|
private createError;
|
|
234
229
|
}
|
|
235
230
|
|
|
236
|
-
type EventHandler$1 = (...args: any[]) => void;
|
|
237
|
-
interface WebRTCTransportConfig extends TransportClientConfig {
|
|
238
|
-
webrtcVersion?: string;
|
|
239
|
-
maxPollAttempts?: number;
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* WebRTC-specific timing breakdown of the transport connection.
|
|
243
|
-
* Recorded once per connection and accessible via {@link WebRTCTransportClient.getTransportTimings}.
|
|
244
|
-
*/
|
|
245
|
-
interface WebRTCTransportTimings {
|
|
246
|
-
protocol: "webrtc";
|
|
247
|
-
/** Time spent polling for the SDP answer (POST offer → GET answer 200) */
|
|
248
|
-
sdpPollingMs: number;
|
|
249
|
-
/** Number of SDP poll requests made (1 = answered on first try) */
|
|
250
|
-
sdpPollingAttempts: number;
|
|
251
|
-
/** setRemoteDescription → RTCPeerConnection connectionState "connected" */
|
|
252
|
-
iceNegotiationMs: number;
|
|
253
|
-
/** setRemoteDescription → RTCDataChannel "open" */
|
|
254
|
-
dataChannelMs: number;
|
|
255
|
-
}
|
|
256
|
-
declare class WebRTCTransportClient implements TransportClient {
|
|
257
|
-
private eventListeners;
|
|
258
|
-
private peerConnection;
|
|
259
|
-
private dataChannel;
|
|
260
|
-
private status;
|
|
261
|
-
private pingInterval;
|
|
262
|
-
private statsInterval;
|
|
263
|
-
private stats;
|
|
264
|
-
private transceiverMap;
|
|
265
|
-
private publishedTracks;
|
|
266
|
-
private peerConnected;
|
|
267
|
-
private dataChannelOpen;
|
|
268
|
-
private iceStartTime?;
|
|
269
|
-
private iceNegotiationMs?;
|
|
270
|
-
private dataChannelMs?;
|
|
271
|
-
private sdpPollingMs?;
|
|
272
|
-
private sdpPollingAttempts?;
|
|
273
|
-
private readonly baseUrl;
|
|
274
|
-
private readonly sessionId;
|
|
275
|
-
private readonly jwtToken;
|
|
276
|
-
private readonly webrtcVersion;
|
|
277
|
-
private readonly maxPollAttempts;
|
|
278
|
-
private abortController;
|
|
279
|
-
constructor(config: WebRTCTransportConfig);
|
|
280
|
-
on(event: TransportEvent, handler: EventHandler$1): void;
|
|
281
|
-
off(event: TransportEvent, handler: EventHandler$1): void;
|
|
282
|
-
private emit;
|
|
283
|
-
private get signal();
|
|
284
|
-
private get transportBaseUrl();
|
|
285
|
-
private getHeaders;
|
|
286
|
-
private checkVersionMismatch;
|
|
287
|
-
private sleep;
|
|
288
|
-
private fetchIceServers;
|
|
289
|
-
private sendSdpOffer;
|
|
290
|
-
private pollSdpAnswer;
|
|
291
|
-
connect(tracks: TrackCapability[]): Promise<void>;
|
|
292
|
-
reconnect(tracks: TrackCapability[]): Promise<void>;
|
|
293
|
-
disconnect(): Promise<void>;
|
|
294
|
-
abort(): void;
|
|
295
|
-
getStatus(): TransportStatus;
|
|
296
|
-
/**
|
|
297
|
-
* Builds the track_mapping array from capabilities + transceiver MIDs.
|
|
298
|
-
* Must be called after createOffer + setLocalDescription so that
|
|
299
|
-
* transceiver.mid is assigned.
|
|
300
|
-
*/
|
|
301
|
-
private buildTrackMapping;
|
|
302
|
-
private get maxMessageBytes();
|
|
303
|
-
sendCommand(command: string, data: any, scope?: MessageScope): void;
|
|
304
|
-
publishTrack(name: string, track: MediaStreamTrack): Promise<void>;
|
|
305
|
-
unpublishTrack(name: string): Promise<void>;
|
|
306
|
-
getStats(): ConnectionStats | undefined;
|
|
307
|
-
getTransportTimings(): WebRTCTransportTimings | undefined;
|
|
308
|
-
private resetTransportTimings;
|
|
309
|
-
private startStatsPolling;
|
|
310
|
-
private stopStatsPolling;
|
|
311
|
-
private startPing;
|
|
312
|
-
private stopPing;
|
|
313
|
-
private checkFullyConnected;
|
|
314
|
-
private setStatus;
|
|
315
|
-
private setupPeerConnectionHandlers;
|
|
316
|
-
private setupDataChannelHandlers;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* Generic transport interface for connecting to a Reactor session.
|
|
321
|
-
*
|
|
322
|
-
* A TransportClient encapsulates the full transport lifecycle: signaling,
|
|
323
|
-
* connection establishment, media track management, and data channel
|
|
324
|
-
* messaging. Implementations handle protocol specifics (WebRTC, MOQ, etc.)
|
|
325
|
-
* while the Reactor orchestrator works only through this interface.
|
|
326
|
-
*/
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* Discriminated union of all transport-specific timing types.
|
|
330
|
-
* Each member carries a `protocol` tag for narrowing.
|
|
331
|
-
* Extend this union when adding new transport implementations.
|
|
332
|
-
*/
|
|
333
|
-
type TransportTimings = WebRTCTransportTimings;
|
|
334
|
-
type TransportStatus = "disconnected" | "connecting" | "connected" | "error";
|
|
335
|
-
type TransportEvent = "statusChanged" | "trackReceived" | "trackRemoved" | "message" | "statsUpdate";
|
|
336
|
-
type EventHandler = (...args: any[]) => void;
|
|
337
|
-
interface TransportClientConfig {
|
|
338
|
-
baseUrl: string;
|
|
339
|
-
sessionId: string;
|
|
340
|
-
jwtToken: string;
|
|
341
|
-
}
|
|
342
|
-
interface TransportClient {
|
|
343
|
-
/**
|
|
344
|
-
* Establishes the transport connection using server-declared tracks.
|
|
345
|
-
*
|
|
346
|
-
* Internally handles: signaling (ICE servers, SDP offer/answer),
|
|
347
|
-
* connection negotiation, and transceiver setup. For sendonly tracks,
|
|
348
|
-
* no media flows until {@link publishTrack} is called.
|
|
349
|
-
*/
|
|
350
|
-
connect(tracks: TrackCapability[]): Promise<void>;
|
|
351
|
-
/**
|
|
352
|
-
* Reconnects an existing session with a fresh transport negotiation.
|
|
353
|
-
* Uses the same tracks as the original connection.
|
|
354
|
-
*/
|
|
355
|
-
reconnect(tracks: TrackCapability[]): Promise<void>;
|
|
356
|
-
/**
|
|
357
|
-
* Tears down the transport connection and releases all resources.
|
|
358
|
-
*/
|
|
359
|
-
disconnect(): Promise<void>;
|
|
360
|
-
/**
|
|
361
|
-
* Returns the current transport connection status.
|
|
362
|
-
*/
|
|
363
|
-
getStatus(): TransportStatus;
|
|
364
|
-
/**
|
|
365
|
-
* Sends a command to the model via the data channel.
|
|
366
|
-
*
|
|
367
|
-
* @param command The command name.
|
|
368
|
-
* @param data The command payload.
|
|
369
|
-
* @param scope "application" for model commands, "runtime" for platform messages.
|
|
370
|
-
*/
|
|
371
|
-
sendCommand(command: string, data: any, scope: MessageScope): void;
|
|
372
|
-
/**
|
|
373
|
-
* Publishes a MediaStreamTrack to a named sendonly track.
|
|
374
|
-
* The transceiver must already exist (declared by capabilities).
|
|
375
|
-
* Uses replaceTrack() — no renegotiation needed.
|
|
376
|
-
*/
|
|
377
|
-
publishTrack(name: string, track: MediaStreamTrack): Promise<void>;
|
|
378
|
-
/**
|
|
379
|
-
* Stops sending media on a named track.
|
|
380
|
-
*/
|
|
381
|
-
unpublishTrack(name: string): Promise<void>;
|
|
382
|
-
/**
|
|
383
|
-
* Subscribes to transport events.
|
|
384
|
-
*
|
|
385
|
-
* Events:
|
|
386
|
-
* - "statusChanged" (status: TransportStatus)
|
|
387
|
-
* - "trackReceived" (name: string, track: MediaStreamTrack, stream: MediaStream)
|
|
388
|
-
* - "trackRemoved" (name: string)
|
|
389
|
-
* - "message" (message: any, scope: MessageScope)
|
|
390
|
-
* - "statsUpdate" (stats: ConnectionStats)
|
|
391
|
-
*/
|
|
392
|
-
on(event: TransportEvent, handler: EventHandler): void;
|
|
393
|
-
/**
|
|
394
|
-
* Unsubscribes from transport events.
|
|
395
|
-
*/
|
|
396
|
-
off(event: TransportEvent, handler: EventHandler): void;
|
|
397
|
-
/**
|
|
398
|
-
* Returns current connection statistics, or undefined if not connected.
|
|
399
|
-
*/
|
|
400
|
-
getStats(): ConnectionStats | undefined;
|
|
401
|
-
/**
|
|
402
|
-
* Returns transport-specific timing breakdown of the most recent
|
|
403
|
-
* connection attempt. Narrow on the `protocol` discriminant to
|
|
404
|
-
* access implementation-specific fields.
|
|
405
|
-
*/
|
|
406
|
-
getTransportTimings(): TransportTimings | undefined;
|
|
407
|
-
/**
|
|
408
|
-
* Cancels any in-flight signaling (HTTP polling, pending fetches).
|
|
409
|
-
*/
|
|
410
|
-
abort(): void;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
231
|
interface ReactorState {
|
|
414
232
|
status: ReactorStatus;
|
|
415
233
|
/**
|
|
@@ -536,17 +354,4 @@ declare function useReactorInternalMessage(handler: (message: any) => void): voi
|
|
|
536
354
|
*/
|
|
537
355
|
declare function useStats(): ConnectionStats | undefined;
|
|
538
356
|
|
|
539
|
-
|
|
540
|
-
* ⚠️ INSECURE: Fetches a JWT token directly from the client.
|
|
541
|
-
*
|
|
542
|
-
* WARNING: This function exposes your API key in client-side code.
|
|
543
|
-
* Only use this for local development or testing purposes.
|
|
544
|
-
* In production, call /tokens from your server and pass the JWT to your frontend.
|
|
545
|
-
*
|
|
546
|
-
* @param apiKey - Your Reactor API key (will be exposed in client code!)
|
|
547
|
-
* @param apiUrl - Optional API URL, defaults to production
|
|
548
|
-
* @returns string containing the JWT token
|
|
549
|
-
*/
|
|
550
|
-
declare function fetchInsecureToken(apiKey: string, apiUrl?: string): Promise<string>;
|
|
551
|
-
|
|
552
|
-
export { AbortError, type Capabilities, type CommandCapability, ConflictError, type ConnectOptions, type ConnectionStats, type ConnectionTimings, DEFAULT_BASE_URL, type MessageScope, type Options, Reactor, type ReactorConnectOptions, ReactorController, type ReactorControllerProps, type ReactorError, type ReactorEvent, ReactorProvider, type ReactorState$1 as ReactorState, type ReactorStatus, ReactorView, type ReactorViewProps, type CreateSessionResponse as SessionInfo, type TrackCapability, type TransportClient, type TransportClientConfig, type TransportDeclaration, type TransportEvent, type TransportStatus, type TransportTimings, WebRTCTransportClient, type WebRTCTransportConfig, type WebRTCTransportTimings, WebcamStream, type WebcamStreamProps, fetchInsecureToken, isAbortError, useReactor, useReactorInternalMessage, useReactorMessage, useReactorStore, useStats };
|
|
357
|
+
export { AbortError, type Capabilities, type CommandCapability, ConflictError, type ConnectOptions, type ConnectionStats, type ConnectionTimings, DEFAULT_BASE_URL, type MessageScope, type Options, Reactor, type ReactorConnectOptions, ReactorController, type ReactorControllerProps, type ReactorError, type ReactorEvent, ReactorProvider, type ReactorState$1 as ReactorState, type ReactorStatus, type ReactorStore, ReactorView, type ReactorViewProps, type SessionResponse, type TrackCapability, WebcamStream, type WebcamStreamProps, isAbortError, useReactor, useReactorInternalMessage, useReactorMessage, useReactorStore, useStats };
|
package/dist/index.d.ts
CHANGED
|
@@ -9,10 +9,6 @@ import React, { ReactNode } from 'react';
|
|
|
9
9
|
* Version constants are sourced from package.json via resolveJsonModule.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
declare const TransportDeclarationSchema: z.ZodObject<{
|
|
13
|
-
protocol: z.ZodString;
|
|
14
|
-
version: z.ZodString;
|
|
15
|
-
}, z.core.$strip>;
|
|
16
12
|
declare const TrackCapabilitySchema: z.ZodObject<{
|
|
17
13
|
name: z.ZodString;
|
|
18
14
|
kind: z.ZodEnum<{
|
|
@@ -49,22 +45,22 @@ declare const CapabilitiesSchema: z.ZodObject<{
|
|
|
49
45
|
}, z.core.$strip>>>;
|
|
50
46
|
emission_fps: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
51
47
|
}, z.core.$strip>;
|
|
52
|
-
declare const
|
|
48
|
+
declare const SessionResponseSchema: z.ZodObject<{
|
|
53
49
|
session_id: z.ZodString;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}, z.core.$strip>>;
|
|
50
|
+
state: z.ZodString;
|
|
51
|
+
cluster: z.ZodString;
|
|
57
52
|
model: z.ZodObject<{
|
|
58
53
|
name: z.ZodString;
|
|
59
54
|
version: z.ZodOptional<z.ZodString>;
|
|
60
55
|
}, z.core.$strip>;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
56
|
+
server_info: z.ZodObject<{
|
|
57
|
+
server_version: z.ZodString;
|
|
58
|
+
}, z.core.$strip>;
|
|
59
|
+
selected_transport: z.ZodOptional<z.ZodObject<{
|
|
64
60
|
protocol: z.ZodString;
|
|
65
61
|
version: z.ZodString;
|
|
66
|
-
}, z.core.$strip
|
|
67
|
-
capabilities: z.ZodObject<{
|
|
62
|
+
}, z.core.$strip>>;
|
|
63
|
+
capabilities: z.ZodOptional<z.ZodObject<{
|
|
68
64
|
protocol_version: z.ZodString;
|
|
69
65
|
tracks: z.ZodArray<z.ZodObject<{
|
|
70
66
|
name: z.ZodString;
|
|
@@ -83,12 +79,11 @@ declare const CreateSessionResponseSchema: z.ZodObject<{
|
|
|
83
79
|
schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
84
80
|
}, z.core.$strip>>>;
|
|
85
81
|
emission_fps: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
86
|
-
}, z.core.$strip
|
|
82
|
+
}, z.core.$strip>>;
|
|
87
83
|
}, z.core.$strip>;
|
|
88
|
-
type TransportDeclaration = z.infer<typeof TransportDeclarationSchema>;
|
|
89
84
|
type TrackCapability = z.infer<typeof TrackCapabilitySchema>;
|
|
90
85
|
type CommandCapability = z.infer<typeof CommandCapabilitySchema>;
|
|
91
|
-
type
|
|
86
|
+
type SessionResponse = z.infer<typeof SessionResponseSchema>;
|
|
92
87
|
type Capabilities = z.infer<typeof CapabilitiesSchema>;
|
|
93
88
|
|
|
94
89
|
type ReactorStatus = "disconnected" | "connecting" | "waiting" | "ready";
|
|
@@ -168,7 +163,7 @@ declare const OptionsSchema: z.ZodObject<{
|
|
|
168
163
|
local: z.ZodDefault<z.ZodBoolean>;
|
|
169
164
|
}, z.core.$strip>;
|
|
170
165
|
type Options = z.input<typeof OptionsSchema>;
|
|
171
|
-
type EventHandler
|
|
166
|
+
type EventHandler = (...args: any[]) => void;
|
|
172
167
|
declare class Reactor {
|
|
173
168
|
private coordinatorClient;
|
|
174
169
|
private transportClient;
|
|
@@ -186,8 +181,8 @@ declare class Reactor {
|
|
|
186
181
|
private sessionResponse?;
|
|
187
182
|
constructor(options: Options);
|
|
188
183
|
private eventListeners;
|
|
189
|
-
on(event: ReactorEvent, handler: EventHandler
|
|
190
|
-
off(event: ReactorEvent, handler: EventHandler
|
|
184
|
+
on(event: ReactorEvent, handler: EventHandler): void;
|
|
185
|
+
off(event: ReactorEvent, handler: EventHandler): void;
|
|
191
186
|
emit(event: ReactorEvent, ...args: any[]): void;
|
|
192
187
|
/**
|
|
193
188
|
* Sends a command to the model via the data channel.
|
|
@@ -223,7 +218,7 @@ declare class Reactor {
|
|
|
223
218
|
getState(): ReactorState$1;
|
|
224
219
|
getLastError(): ReactorError | undefined;
|
|
225
220
|
getCapabilities(): Capabilities | undefined;
|
|
226
|
-
getSessionInfo():
|
|
221
|
+
getSessionInfo(): SessionResponse | undefined;
|
|
227
222
|
getStats(): ConnectionStats | undefined;
|
|
228
223
|
private setSessionId;
|
|
229
224
|
private setStatus;
|
|
@@ -233,183 +228,6 @@ declare class Reactor {
|
|
|
233
228
|
private createError;
|
|
234
229
|
}
|
|
235
230
|
|
|
236
|
-
type EventHandler$1 = (...args: any[]) => void;
|
|
237
|
-
interface WebRTCTransportConfig extends TransportClientConfig {
|
|
238
|
-
webrtcVersion?: string;
|
|
239
|
-
maxPollAttempts?: number;
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* WebRTC-specific timing breakdown of the transport connection.
|
|
243
|
-
* Recorded once per connection and accessible via {@link WebRTCTransportClient.getTransportTimings}.
|
|
244
|
-
*/
|
|
245
|
-
interface WebRTCTransportTimings {
|
|
246
|
-
protocol: "webrtc";
|
|
247
|
-
/** Time spent polling for the SDP answer (POST offer → GET answer 200) */
|
|
248
|
-
sdpPollingMs: number;
|
|
249
|
-
/** Number of SDP poll requests made (1 = answered on first try) */
|
|
250
|
-
sdpPollingAttempts: number;
|
|
251
|
-
/** setRemoteDescription → RTCPeerConnection connectionState "connected" */
|
|
252
|
-
iceNegotiationMs: number;
|
|
253
|
-
/** setRemoteDescription → RTCDataChannel "open" */
|
|
254
|
-
dataChannelMs: number;
|
|
255
|
-
}
|
|
256
|
-
declare class WebRTCTransportClient implements TransportClient {
|
|
257
|
-
private eventListeners;
|
|
258
|
-
private peerConnection;
|
|
259
|
-
private dataChannel;
|
|
260
|
-
private status;
|
|
261
|
-
private pingInterval;
|
|
262
|
-
private statsInterval;
|
|
263
|
-
private stats;
|
|
264
|
-
private transceiverMap;
|
|
265
|
-
private publishedTracks;
|
|
266
|
-
private peerConnected;
|
|
267
|
-
private dataChannelOpen;
|
|
268
|
-
private iceStartTime?;
|
|
269
|
-
private iceNegotiationMs?;
|
|
270
|
-
private dataChannelMs?;
|
|
271
|
-
private sdpPollingMs?;
|
|
272
|
-
private sdpPollingAttempts?;
|
|
273
|
-
private readonly baseUrl;
|
|
274
|
-
private readonly sessionId;
|
|
275
|
-
private readonly jwtToken;
|
|
276
|
-
private readonly webrtcVersion;
|
|
277
|
-
private readonly maxPollAttempts;
|
|
278
|
-
private abortController;
|
|
279
|
-
constructor(config: WebRTCTransportConfig);
|
|
280
|
-
on(event: TransportEvent, handler: EventHandler$1): void;
|
|
281
|
-
off(event: TransportEvent, handler: EventHandler$1): void;
|
|
282
|
-
private emit;
|
|
283
|
-
private get signal();
|
|
284
|
-
private get transportBaseUrl();
|
|
285
|
-
private getHeaders;
|
|
286
|
-
private checkVersionMismatch;
|
|
287
|
-
private sleep;
|
|
288
|
-
private fetchIceServers;
|
|
289
|
-
private sendSdpOffer;
|
|
290
|
-
private pollSdpAnswer;
|
|
291
|
-
connect(tracks: TrackCapability[]): Promise<void>;
|
|
292
|
-
reconnect(tracks: TrackCapability[]): Promise<void>;
|
|
293
|
-
disconnect(): Promise<void>;
|
|
294
|
-
abort(): void;
|
|
295
|
-
getStatus(): TransportStatus;
|
|
296
|
-
/**
|
|
297
|
-
* Builds the track_mapping array from capabilities + transceiver MIDs.
|
|
298
|
-
* Must be called after createOffer + setLocalDescription so that
|
|
299
|
-
* transceiver.mid is assigned.
|
|
300
|
-
*/
|
|
301
|
-
private buildTrackMapping;
|
|
302
|
-
private get maxMessageBytes();
|
|
303
|
-
sendCommand(command: string, data: any, scope?: MessageScope): void;
|
|
304
|
-
publishTrack(name: string, track: MediaStreamTrack): Promise<void>;
|
|
305
|
-
unpublishTrack(name: string): Promise<void>;
|
|
306
|
-
getStats(): ConnectionStats | undefined;
|
|
307
|
-
getTransportTimings(): WebRTCTransportTimings | undefined;
|
|
308
|
-
private resetTransportTimings;
|
|
309
|
-
private startStatsPolling;
|
|
310
|
-
private stopStatsPolling;
|
|
311
|
-
private startPing;
|
|
312
|
-
private stopPing;
|
|
313
|
-
private checkFullyConnected;
|
|
314
|
-
private setStatus;
|
|
315
|
-
private setupPeerConnectionHandlers;
|
|
316
|
-
private setupDataChannelHandlers;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* Generic transport interface for connecting to a Reactor session.
|
|
321
|
-
*
|
|
322
|
-
* A TransportClient encapsulates the full transport lifecycle: signaling,
|
|
323
|
-
* connection establishment, media track management, and data channel
|
|
324
|
-
* messaging. Implementations handle protocol specifics (WebRTC, MOQ, etc.)
|
|
325
|
-
* while the Reactor orchestrator works only through this interface.
|
|
326
|
-
*/
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* Discriminated union of all transport-specific timing types.
|
|
330
|
-
* Each member carries a `protocol` tag for narrowing.
|
|
331
|
-
* Extend this union when adding new transport implementations.
|
|
332
|
-
*/
|
|
333
|
-
type TransportTimings = WebRTCTransportTimings;
|
|
334
|
-
type TransportStatus = "disconnected" | "connecting" | "connected" | "error";
|
|
335
|
-
type TransportEvent = "statusChanged" | "trackReceived" | "trackRemoved" | "message" | "statsUpdate";
|
|
336
|
-
type EventHandler = (...args: any[]) => void;
|
|
337
|
-
interface TransportClientConfig {
|
|
338
|
-
baseUrl: string;
|
|
339
|
-
sessionId: string;
|
|
340
|
-
jwtToken: string;
|
|
341
|
-
}
|
|
342
|
-
interface TransportClient {
|
|
343
|
-
/**
|
|
344
|
-
* Establishes the transport connection using server-declared tracks.
|
|
345
|
-
*
|
|
346
|
-
* Internally handles: signaling (ICE servers, SDP offer/answer),
|
|
347
|
-
* connection negotiation, and transceiver setup. For sendonly tracks,
|
|
348
|
-
* no media flows until {@link publishTrack} is called.
|
|
349
|
-
*/
|
|
350
|
-
connect(tracks: TrackCapability[]): Promise<void>;
|
|
351
|
-
/**
|
|
352
|
-
* Reconnects an existing session with a fresh transport negotiation.
|
|
353
|
-
* Uses the same tracks as the original connection.
|
|
354
|
-
*/
|
|
355
|
-
reconnect(tracks: TrackCapability[]): Promise<void>;
|
|
356
|
-
/**
|
|
357
|
-
* Tears down the transport connection and releases all resources.
|
|
358
|
-
*/
|
|
359
|
-
disconnect(): Promise<void>;
|
|
360
|
-
/**
|
|
361
|
-
* Returns the current transport connection status.
|
|
362
|
-
*/
|
|
363
|
-
getStatus(): TransportStatus;
|
|
364
|
-
/**
|
|
365
|
-
* Sends a command to the model via the data channel.
|
|
366
|
-
*
|
|
367
|
-
* @param command The command name.
|
|
368
|
-
* @param data The command payload.
|
|
369
|
-
* @param scope "application" for model commands, "runtime" for platform messages.
|
|
370
|
-
*/
|
|
371
|
-
sendCommand(command: string, data: any, scope: MessageScope): void;
|
|
372
|
-
/**
|
|
373
|
-
* Publishes a MediaStreamTrack to a named sendonly track.
|
|
374
|
-
* The transceiver must already exist (declared by capabilities).
|
|
375
|
-
* Uses replaceTrack() — no renegotiation needed.
|
|
376
|
-
*/
|
|
377
|
-
publishTrack(name: string, track: MediaStreamTrack): Promise<void>;
|
|
378
|
-
/**
|
|
379
|
-
* Stops sending media on a named track.
|
|
380
|
-
*/
|
|
381
|
-
unpublishTrack(name: string): Promise<void>;
|
|
382
|
-
/**
|
|
383
|
-
* Subscribes to transport events.
|
|
384
|
-
*
|
|
385
|
-
* Events:
|
|
386
|
-
* - "statusChanged" (status: TransportStatus)
|
|
387
|
-
* - "trackReceived" (name: string, track: MediaStreamTrack, stream: MediaStream)
|
|
388
|
-
* - "trackRemoved" (name: string)
|
|
389
|
-
* - "message" (message: any, scope: MessageScope)
|
|
390
|
-
* - "statsUpdate" (stats: ConnectionStats)
|
|
391
|
-
*/
|
|
392
|
-
on(event: TransportEvent, handler: EventHandler): void;
|
|
393
|
-
/**
|
|
394
|
-
* Unsubscribes from transport events.
|
|
395
|
-
*/
|
|
396
|
-
off(event: TransportEvent, handler: EventHandler): void;
|
|
397
|
-
/**
|
|
398
|
-
* Returns current connection statistics, or undefined if not connected.
|
|
399
|
-
*/
|
|
400
|
-
getStats(): ConnectionStats | undefined;
|
|
401
|
-
/**
|
|
402
|
-
* Returns transport-specific timing breakdown of the most recent
|
|
403
|
-
* connection attempt. Narrow on the `protocol` discriminant to
|
|
404
|
-
* access implementation-specific fields.
|
|
405
|
-
*/
|
|
406
|
-
getTransportTimings(): TransportTimings | undefined;
|
|
407
|
-
/**
|
|
408
|
-
* Cancels any in-flight signaling (HTTP polling, pending fetches).
|
|
409
|
-
*/
|
|
410
|
-
abort(): void;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
231
|
interface ReactorState {
|
|
414
232
|
status: ReactorStatus;
|
|
415
233
|
/**
|
|
@@ -536,17 +354,4 @@ declare function useReactorInternalMessage(handler: (message: any) => void): voi
|
|
|
536
354
|
*/
|
|
537
355
|
declare function useStats(): ConnectionStats | undefined;
|
|
538
356
|
|
|
539
|
-
|
|
540
|
-
* ⚠️ INSECURE: Fetches a JWT token directly from the client.
|
|
541
|
-
*
|
|
542
|
-
* WARNING: This function exposes your API key in client-side code.
|
|
543
|
-
* Only use this for local development or testing purposes.
|
|
544
|
-
* In production, call /tokens from your server and pass the JWT to your frontend.
|
|
545
|
-
*
|
|
546
|
-
* @param apiKey - Your Reactor API key (will be exposed in client code!)
|
|
547
|
-
* @param apiUrl - Optional API URL, defaults to production
|
|
548
|
-
* @returns string containing the JWT token
|
|
549
|
-
*/
|
|
550
|
-
declare function fetchInsecureToken(apiKey: string, apiUrl?: string): Promise<string>;
|
|
551
|
-
|
|
552
|
-
export { AbortError, type Capabilities, type CommandCapability, ConflictError, type ConnectOptions, type ConnectionStats, type ConnectionTimings, DEFAULT_BASE_URL, type MessageScope, type Options, Reactor, type ReactorConnectOptions, ReactorController, type ReactorControllerProps, type ReactorError, type ReactorEvent, ReactorProvider, type ReactorState$1 as ReactorState, type ReactorStatus, ReactorView, type ReactorViewProps, type CreateSessionResponse as SessionInfo, type TrackCapability, type TransportClient, type TransportClientConfig, type TransportDeclaration, type TransportEvent, type TransportStatus, type TransportTimings, WebRTCTransportClient, type WebRTCTransportConfig, type WebRTCTransportTimings, WebcamStream, type WebcamStreamProps, fetchInsecureToken, isAbortError, useReactor, useReactorInternalMessage, useReactorMessage, useReactorStore, useStats };
|
|
357
|
+
export { AbortError, type Capabilities, type CommandCapability, ConflictError, type ConnectOptions, type ConnectionStats, type ConnectionTimings, DEFAULT_BASE_URL, type MessageScope, type Options, Reactor, type ReactorConnectOptions, ReactorController, type ReactorControllerProps, type ReactorError, type ReactorEvent, ReactorProvider, type ReactorState$1 as ReactorState, type ReactorStatus, type ReactorStore, ReactorView, type ReactorViewProps, type SessionResponse, type TrackCapability, WebcamStream, type WebcamStreamProps, isAbortError, useReactor, useReactorInternalMessage, useReactorMessage, useReactorStore, useStats };
|