@reactor-team/js-sdk 3.0.2 → 3.2.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.
@@ -59,9 +59,17 @@ export interface ConnectOptions {
59
59
  maxAttempts?: number;
60
60
  }
61
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>);
62
+ /** What a token is being resolved for. `sessionId` is set for every request
63
+ * that targets an existing session and unset for session creation. A
64
+ * resolver that mints a replacement token must bind it to that session
65
+ * (`resources.sessions.bind`), or the token cannot reach the session. */
66
+ export interface JwtRequestContext {
67
+ sessionId?: string;
68
+ }
69
+
70
+ /** A token, or a resolver called before every authenticated request with a
71
+ * `JwtRequestContext`. Returning "" sends no Authorization header. */
72
+ export type JwtSource = string | ((context?: JwtRequestContext) => string | Promise<string>);
65
73
 
66
74
  export interface TrackCapability {
67
75
  name: string;
@@ -144,6 +152,36 @@ export interface ReactorError {
144
152
  timestamp_ms: number;
145
153
  }
146
154
 
155
+ /** One track's WebRTC quality reading taken from `getStats()`, for
156
+ * `sendClientStats`. */
157
+ export interface ClientTrackStat {
158
+ /** When this reading was taken, epoch milliseconds (e.g. `Date.now()`). */
159
+ timestamp: number;
160
+ trackName: string;
161
+ kind: TrackKind;
162
+ direction: TrackDirection;
163
+ /** The codec in use for this track, e.g. "vp9", "h264", "opus". */
164
+ codec: string;
165
+ /** Whether the client currently has this track paused. */
166
+ paused: boolean;
167
+ /** Named numeric readings, keyed by W3C webrtc-stats names in snake_case,
168
+ * e.g. bitrate_bps, frames_per_second, packets_lost, packets_received,
169
+ * jitter_ms, round_trip_time_ms, frames_decoded, frames_dropped,
170
+ * frame_width, frame_height, nack_count, keyframe_requests. A reading the
171
+ * client couldn't take is left out, never sent as 0. */
172
+ metrics: Record<string, number>;
173
+ }
174
+
175
+ /** A connection-wide reading, not tied to any one track — for
176
+ * `sendClientStats`. Sent on every batch; one-time facts such as
177
+ * time_to_connect_ms ride only the first batch after connecting. */
178
+ export interface ClientConnectionStat {
179
+ timestamp: number;
180
+ /** Named numeric readings, e.g. available_outgoing_bitrate_bps,
181
+ * connection_rtt_ms, time_to_connect_ms. */
182
+ metrics: Record<string, number>;
183
+ }
184
+
147
185
  export type StatusListener = (status: ReactorStatus) => void;
148
186
  export type SessionIdListener = (sessionId: string | undefined) => void;
149
187
  export type MessageListener = (message: ReactorMessage) => void;
@@ -219,9 +257,10 @@ export class ReactorClient {
219
257
  * Create a client.
220
258
  *
221
259
  * * `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`.
260
+ * * `jwt` — a token string, a `(context) => string | Promise<string>`
261
+ * resolver called before every authenticated request with the session
262
+ * it is for, or `null` for an unauthenticated local runtime.
263
+ * Replaceable later with `setJwt`.
225
264
  */
226
265
  constructor(options: ClientOptions, jwt?: JwtSource | null);
227
266
  /**
@@ -293,6 +332,17 @@ export class ReactorClient {
293
332
  * Resume a paused track.
294
333
  */
295
334
  resumeTrack(name: string): Promise<void>;
335
+ /**
336
+ * Report a batch of client-observed WebRTC quality readings to the runtime.
337
+ *
338
+ * Fire-and-forget, like the automatic heartbeat: this returns once the
339
+ * frame is handed to the control channel, not once the runtime has
340
+ * processed it. The runtime attaches this connection's own session and
341
+ * connection identity to the batch — nothing here needs to (or can)
342
+ * carry that itself. `connectionStat` carries the connection-wide
343
+ * readings and is normally present on every batch.
344
+ */
345
+ sendClientStats(track_stats: ClientTrackStat[], connection_stat: ClientConnectionStat | undefined): void;
296
346
  /**
297
347
  * Send a command to the model and resolve with its reply.
298
348
  *
@@ -389,6 +439,7 @@ export interface InitOutput {
389
439
  readonly reactorclient_requestRecording: (a: number) => any;
390
440
  readonly reactorclient_requestSchema: (a: number) => any;
391
441
  readonly reactorclient_resumeTrack: (a: number, b: number, c: number) => any;
442
+ readonly reactorclient_sendClientStats: (a: number, b: any, c: any) => [number, number];
392
443
  readonly reactorclient_sendCommand: (a: number, b: number, c: number, d: number, e: number) => any;
393
444
  readonly reactorclient_sessionId: (a: number) => [number, number];
394
445
  readonly reactorclient_sessionInfo: (a: number) => [number, number, number];