@xmaxai/web-sdk 1.0.5 → 1.0.6

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 CHANGED
@@ -214,10 +214,8 @@ The following JavaScript snippet creates a camera stream, starts real-time gener
214
214
  and binds the output to a video view. Run this within an async function in the browser,
215
215
  after a user action such as clicking a Start button.
216
216
 
217
- Choose a model with `RealtimeModel.x2_0` (`x2.0`) or
218
- `RealtimeModel.x2_0_trtc` (`x2.0-trtc`). For Agora, use
219
- `RealtimeModel.x2_0_agora` (`x2.0-agora`) with `RtcProvider.agora`. For VeRTC, use
220
- `RealtimeModel.x2_1_preview` (`x2.1-preview`) with `RtcProvider.vertc`.
217
+ For Agora, use `RealtimeModel.x2_1_preview` (`x2.1-preview`). For TRTC, use
218
+ `RealtimeModel.x2_0_trtc` (`x2.0-trtc`). `RealtimeModel.x2_0` (`x2.0`) uses VeRTC.
221
219
 
222
220
  ```javascript
223
221
  import {
@@ -272,11 +270,11 @@ videoView.remoteTrack = remoteStream.videoTrack;
272
270
  Add a `video-container` element with an explicit width and height to your page.
273
271
  The view displays a local camera preview until the first generated frame arrives.
274
272
 
275
- Use `updateVideoFormat` after creating the local camera stream, including during
273
+ Use `updateUplinkVideoFormat` after creating the local camera stream, including during
276
274
  generation, to change upstream encoding without reconnecting or restarting the task:
277
275
 
278
276
  ```javascript
279
- await realtime.updateVideoFormat(new RealtimeVideoFormat({
277
+ await realtime.updateUplinkVideoFormat(new RealtimeVideoFormat({
280
278
  width: 1024,
281
279
  height: 1920,
282
280
  fps: 20,
@@ -292,6 +290,58 @@ resolution, frame rate, and bitrate depend on the device, browser, and network;
292
290
  use the statistics callbacks to observe them. Await each operation before starting
293
291
  another configuration or lifecycle operation.
294
292
 
293
+ For a frame-rate-only experiment after connecting a local camera or file stream:
294
+
295
+ ```javascript
296
+ await realtime.updateUplinkFrameRate(24);
297
+ ```
298
+
299
+ This preserves the last successfully applied width, height, resolved bitrate limits,
300
+ and encoding preference. It does not recalculate default bitrates for the new frame
301
+ rate or copy measured send statistics into the configuration. The complete encoder
302
+ configuration is still resubmitted, so preservation of RTC's internal adaptation
303
+ state is not guaranteed. Validate actual send statistics under weak networks.
304
+
305
+ **Agora camera sender-only experiment:** camera capture stays at its initial settings.
306
+ Camera updates use `RTCRtpSender.setParameters()` (`scaleResolutionDownBy`,
307
+ `maxFramerate`, `maxBitrate` in bps), not Agora's `setEncoderConfiguration()`.
308
+ Only the maximum bitrate is applied; the standard sender API cannot enforce the
309
+ configured minimum bitrate. Pre-publish updates are queued and applied immediately
310
+ after publication, so the very first transmitted frames may use the initial profile.
311
+ Scaling uses the actual captured dimensions, preserves aspect ratio, and does not upscale.
312
+ Sender replacement/rejoin reapplies the latest target. Unsupported or silently ignored
313
+ parameters are reported as errors, without falling back to camera constraints.
314
+ Read-back confirms accepted parameters, not actual frame dimensions or persistent
315
+ ownership against Agora's later adjustments; validate Chrome/Safari using RTC statistics.
316
+ Search `Agora Sender Parameters` for accepted limits and `Agora RTC Statistics` for
317
+ capture/send dimensions. File-video encoding and other RTC providers are unchanged.
318
+
319
+ Agora uplink and downlink adaptation are always enabled; no configuration flag or manual
320
+ selector is needed. Other RTC providers are not yet integrated. After generation
321
+ starts, three consecutive poor uplink quality samples lower one tier, and five good
322
+ samples probe an upgrade. Five tiers jointly change resolution and frame rate:
323
+ 1024×1920/30, 768×1440/24, 640×1200/24, 512×960/20, and 384×720/16.
324
+ Landscape dimensions are swapped; custom sources scale proportionally from their
325
+ initial or most recently manually applied format, with even dimensions and FPS
326
+ capped by that baseline. Automatic updates preserve this baseline across reconnects.
327
+ Default bitrate limits are recalculated for each tier; explicit limits and encoding
328
+ preference are preserved. Uplink changes do not alter generation or result-stream sizes.
329
+ Downlink independently uses the same quality thresholds and five resolution tiers,
330
+ relative to the generation's original dimensions. It sends only `change_target_size`
331
+ with `[width, height]`, without changing FPS, bitrate limits, or model inference.
332
+ The protocol has no application ACK: a successful send records a requested tier,
333
+ not a confirmed output size; use remote RTC statistics to verify actual dimensions.
334
+ New Agora local tracks read the last applied uplink tier before publishing
335
+ (the camera sender-only experiment applies it immediately after publication);
336
+ new generation tasks restore the last requested downlink tier via `start.params.target_size`.
337
+ Each direction falls back to L2 when no valid history is available. History is stored
338
+ in `localStorage`, separately by model and direction, with no expiry or stability window
339
+ in this first version. Storage failures never block generation. The original L1 baseline
340
+ is retained for recovery; reconnecting the same local track keeps its in-memory uplink tier.
341
+ Downlink changes only resolution, not FPS. Interpolation follows the requested dimensions,
342
+ showing raw video while frame sizes do not match. See
343
+ [the strategy and weak-network test steps](docs/realtime-adaptive-quality.md).
344
+
295
345
  Each model declares its supported RTC providers. The SDK selects the model's
296
346
  default provider when `provider` is omitted. To use Agora, replace the manager
297
347
  configuration above; camera capture, generation, rendering, and cleanup use the same APIs:
@@ -299,33 +349,33 @@ configuration above; camera capture, generation, rendering, and cleanup use the
299
349
  ```javascript
300
350
  const realtime = client.createRealtimeManager(
301
351
  new RealtimeConfiguration({
302
- model: RealtimeModel.x2_0_agora,
352
+ model: RealtimeModel.x2_1_preview,
303
353
  })
304
354
  );
305
355
  ```
306
356
 
307
- To use VeRTC, select the preview model:
357
+ To use VeRTC, select `x2.0`:
308
358
 
309
359
  ```javascript
310
360
  const realtime = client.createRealtimeManager(
311
361
  new RealtimeConfiguration({
312
- model: RealtimeModel.x2_1_preview,
362
+ model: RealtimeModel.x2_0,
313
363
  })
314
364
  );
315
365
  ```
316
366
 
317
- The provider is fixed for each manager: `x2.0` and `x2.0-trtc` use
318
- `RtcProvider.trtc`, `x2.0-agora` uses `RtcProvider.agora`, and
319
- `x2.1-preview` uses `RtcProvider.vertc`.
367
+ The provider is fixed for each manager: `x2.0-trtc` uses `RtcProvider.trtc`,
368
+ `x2.1-preview` uses `RtcProvider.agora`, and `x2.0` uses `RtcProvider.vertc`.
320
369
  Import `RtcProvider` to specify it explicitly; unsupported known-model/provider
321
370
  combinations are rejected during configuration. Use the exported
322
371
  `supportedRtcProviders(model)` to inspect model capabilities. The SDK does not read
323
372
  `modelExtra.provider` from the backend; the resolved configuration determines how
324
373
  RTC credentials are parsed.
325
374
 
326
- The `x2.0-agora` and `x2.1-preview` models use
327
- `https://dev.xmaxai.com/open/api/v1` in both environments.
328
- The other built-in models and file uploads use the configured environment's API endpoint.
375
+ The `x2.1-preview` model uses `https://cloud.xmax.22duck.cn/open/api/v1` in both environments.
376
+ The other built-in models and file uploads use the configured
377
+ environment's production API endpoint: `https://cloud.xmax.22duck.cn/open/api/v1`
378
+ for China and `https://api.xmax.cloud/open/api/v1` for Global.
329
379
 
330
380
  Custom realtime model names are also accepted without an SDK update:
331
381
 
@@ -336,11 +386,11 @@ const realtime = client.createRealtimeManager(
336
386
  ```
337
387
 
338
388
  The model name is sent unchanged; the server determines whether it is available.
339
- Unknown models inherit the `x2.1-preview` defaults: VeRTC, the dev session API above
389
+ Unknown models inherit the `x2.1-preview` defaults: Agora, the production session API above
340
390
  (in both client environments), a 1024 × 1920 camera at 30 fps, and the same
341
391
  1024 × 1920 / 1920 × 1024 input resolution buckets and media rules.
342
392
  You may explicitly choose another supported `RtcProvider` for a custom model;
343
- `supportedRtcProviders` lists all SDK adapters for custom models, with VeRTC first,
393
+ `supportedRtcProviders` lists all SDK adapters for custom models, with Agora first,
344
394
  but this does not guarantee server-side support. `modelDisplayName` returns the
345
395
  custom name unchanged. Empty/blank or non-string model names, invalid RTC providers,
346
396
  and invalid video parameters are still rejected locally.
@@ -422,6 +472,14 @@ For camera input, bind the returned video track to a preview view. The SDK enter
422
472
  `ready` after it has received a valid frame and the preview view is bound; observe
423
473
  this through `setStateListener`.
424
474
 
475
+ At generation start, the SDK sends `params.mirror: true` for the front camera
476
+ and `false` for the rear camera, local files, and network videos. The backend
477
+ mirrors the input; generated results are not automatically mirrored in the
478
+ browser. The front-camera local preview remains mirrored independently.
479
+ This flag is sent only with `start`: switching cameras during an active generation
480
+ does not update it. Disconnect and start generation again to apply the new camera
481
+ position to the backend.
482
+
425
483
  <br>
426
484
 
427
485
  ### Resource Cleanup
@@ -480,7 +538,7 @@ Preparation stops at the first frame. After the connection is established and th
480
538
 
481
539
  For local files, requested dimensions automatically select the model resolution with the closest aspect ratio, preferring landscape on ties; exact matches are preserved. For example, `1280×720` selects `1920×1024`. Models without fixed resolutions retain their existing pixel-budget sizing rules. The file is scaled proportionally into the resulting Canvas, with black bars where needed, and the returned track's `videoFormat` reflects that target size. This does not change camera or network-video size validation. Local preview is always silent; `localAudioVolume` does not alter the file's uplink audio. File audio is enabled by default; a file without an audio track produces silence. Set `includeAudio: false` to omit the audio track entirely. Use `setRemoteAudioVolume` to hear the generated result (muted by default).
482
540
 
483
- `disconnect()` pauses playback and retains the source. A new generation after reconnecting starts from the beginning; updating conditions during generation does not restart playback. With looping disabled, file completion holds the final frame and leaves the RTC connection open so remote tail frames can play. `close()` releases all file resources and tracks. `updateVideoFormat()` can adjust uplink encoding without changing the original model input format.
541
+ `disconnect()` pauses playback and retains the source. A new generation after reconnecting starts from the beginning; updating conditions during generation does not restart playback. With looping disabled, file completion holds the final frame and leaves the RTC connection open so remote tail frames can play. `close()` releases all file resources and tracks. `updateUplinkVideoFormat()` can adjust uplink encoding without changing the original model input format.
484
542
 
485
543
  File codecs must be supported by the browser, and Canvas capture and Web Audio must be available. Keep the page foregrounded for stable frame delivery; browser background throttling can reduce the upload frame rate. Playback restrictions, decode errors and preparation timeouts are reported rather than silently sending an empty stream.
486
544
 
@@ -512,7 +570,7 @@ The URL must be directly accessible to the server. Browser cookies and custom au
512
570
 
513
571
  `onFinish` is delivered once for the current task after the server's `video_stopped` message and generation readiness. It does not mean the last remote frame has finished playing, so the SDK does not automatically disconnect. Local preview completion does not trigger this callback. Remote audio follows `setRemoteAudioVolume` (muted by default).
514
572
 
515
- `disconnect()` retains the source and preview for reconnection; `close()` releases them. Close the current source before creating another. `updateVideoFormat()` adjusts camera uplink encoding and is not available for a network video source.
573
+ `disconnect()` retains the source and preview for reconnection; `close()` releases them. Close the current source before creating another. `updateUplinkVideoFormat()` adjusts camera uplink encoding and is not available for a network video source.
516
574
 
517
575
  ### Non-realtime video tasks
518
576
 
@@ -190,4 +190,26 @@ declare enum VideoContentMode {
190
190
  fill = "fill"
191
191
  }
192
192
 
193
- export { CameraPosition as C, RealtimeVideoFormat as R, VideoContentMode as V, RealtimeVideoTrack as a, RealtimeVideoEncoderPreference as b, type RealtimeVideoFormatInit as c };
193
+ /**
194
+ * 单个视频视图最近采样窗口的呈现帧率,不代表屏幕实际刷新帧率。
195
+ */
196
+ interface VideoRenderStatistics {
197
+ /**
198
+ * video 按浏览器 presentedFrames 增量计数;canvas 按实际呈现提交计数。
199
+ */
200
+ readonly source: "video" | "canvas";
201
+ /**
202
+ * 原帧与插值帧的总呈现帧率,单位 fps。
203
+ */
204
+ readonly frameRate: number;
205
+ /**
206
+ * 原帧呈现帧率,单位 fps。
207
+ */
208
+ readonly originalFrameRate: number;
209
+ /**
210
+ * 插值帧呈现帧率,单位 fps;未开启插帧时为 0。
211
+ */
212
+ readonly interpolatedFrameRate: number;
213
+ }
214
+
215
+ export { CameraPosition as C, RealtimeVideoFormat as R, VideoContentMode as V, RealtimeVideoTrack as a, type VideoRenderStatistics as b, RealtimeVideoEncoderPreference as c, type RealtimeVideoFormatInit as d };
@@ -190,4 +190,26 @@ declare enum VideoContentMode {
190
190
  fill = "fill"
191
191
  }
192
192
 
193
- export { CameraPosition as C, RealtimeVideoFormat as R, VideoContentMode as V, RealtimeVideoTrack as a, RealtimeVideoEncoderPreference as b, type RealtimeVideoFormatInit as c };
193
+ /**
194
+ * 单个视频视图最近采样窗口的呈现帧率,不代表屏幕实际刷新帧率。
195
+ */
196
+ interface VideoRenderStatistics {
197
+ /**
198
+ * video 按浏览器 presentedFrames 增量计数;canvas 按实际呈现提交计数。
199
+ */
200
+ readonly source: "video" | "canvas";
201
+ /**
202
+ * 原帧与插值帧的总呈现帧率,单位 fps。
203
+ */
204
+ readonly frameRate: number;
205
+ /**
206
+ * 原帧呈现帧率,单位 fps。
207
+ */
208
+ readonly originalFrameRate: number;
209
+ /**
210
+ * 插值帧呈现帧率,单位 fps;未开启插帧时为 0。
211
+ */
212
+ readonly interpolatedFrameRate: number;
213
+ }
214
+
215
+ export { CameraPosition as C, RealtimeVideoFormat as R, VideoContentMode as V, RealtimeVideoTrack as a, type VideoRenderStatistics as b, RealtimeVideoEncoderPreference as c, type RealtimeVideoFormatInit as d };