@xmaxai/web-sdk 1.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/LICENSE +21 -0
- package/README.md +430 -0
- package/dist/VideoContentMode-BXkqM4XG.d.cts +118 -0
- package/dist/VideoContentMode-BXkqM4XG.d.ts +118 -0
- package/dist/chunk-JJWUZ3AW.cjs +7779 -0
- package/dist/chunk-JJWUZ3AW.cjs.map +1 -0
- package/dist/chunk-MJ72WWQX.js +7779 -0
- package/dist/chunk-MJ72WWQX.js.map +1 -0
- package/dist/index.cjs +59 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +888 -0
- package/dist/index.d.ts +888 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.cjs +116 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +39 -0
- package/dist/react/index.d.ts +39 -0
- package/dist/react/index.js +116 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 XMAX.AI PTE. LTD.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="./docs/images/brand/xmax-sdk.png" alt="XmaxSDK — Realtime Interactive Video Generation" width="880">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript"><img src="https://img.shields.io/badge/JavaScript-ES2020-F7DF1E" alt="JavaScript ES2020"></a>
|
|
7
|
+
<a href="https://platform.xmaxai.com/"><img src="https://img.shields.io/badge/Realtime-AI-FF9500" alt="Realtime AI"></a>
|
|
8
|
+
<a href="./LICENSE"><img src="https://img.shields.io/badge/License-MIT-4C9A2A" alt="MIT License"></a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
We introduce XmaxSDK, a JavaScript SDK designed for real-time interactive video generation via Xmax models. XmaxSDK implements an end-to-end pipeline covering media acquisition, video streaming, frame-by-frame generation, and on-device rendering, enabling developers to seamlessly integrate low-latency, high-fidelity video transformations into creative applications at a much lower cost than alternative solutions.
|
|
12
|
+
|
|
13
|
+
<p align="center"><img src="./docs/images/xlab/generation-demo.gif" alt="X-Lab realtime generation demo" width="33%" /><img src="./docs/images/xlab/index-demo.gif" alt="X-Lab index demo" width="33%" /><img src="./docs/images/xlab/storage-demo.gif" alt="X-Lab storage demo" width="33%" /></p>
|
|
14
|
+
|
|
15
|
+
<br>
|
|
16
|
+
|
|
17
|
+
## What you can build with XmaxSDK
|
|
18
|
+
|
|
19
|
+
<table>
|
|
20
|
+
<tr>
|
|
21
|
+
<th width="24%" align="left">Realtime Use Case</th>
|
|
22
|
+
<th width="60%" align="left">Description</th>
|
|
23
|
+
<th width="16%" align="center">Demo</th>
|
|
24
|
+
</tr>
|
|
25
|
+
<tr>
|
|
26
|
+
<td rowspan="2" width="24%" valign="middle">
|
|
27
|
+
<strong>Character Swapping</strong>
|
|
28
|
+
</td>
|
|
29
|
+
<td width="60%" valign="middle">
|
|
30
|
+
Replace anyone in your live feed with a designated avatar in real-time.
|
|
31
|
+
</td>
|
|
32
|
+
<td rowspan="2" width="16%" align="center" valign="middle">
|
|
33
|
+
<a href="./docs/videos/use-cases/character-swapping.mp4">
|
|
34
|
+
<img src="./docs/images/use-cases/character-swapping-poster.png" alt="Play the Character Swapping demo" width="120">
|
|
35
|
+
<br>
|
|
36
|
+
<sub>▶ Play demo</sub>
|
|
37
|
+
</a>
|
|
38
|
+
</td>
|
|
39
|
+
</tr>
|
|
40
|
+
<tr>
|
|
41
|
+
<td width="60%" valign="middle">
|
|
42
|
+
<strong>Prompt:</strong> <code>视频中角色替换成参考图中角色</code>
|
|
43
|
+
<br><br>
|
|
44
|
+
<strong>Reference image:</strong> Select a clear image of the desired character with a clean background.
|
|
45
|
+
</td>
|
|
46
|
+
</tr>
|
|
47
|
+
<tr>
|
|
48
|
+
<td rowspan="2" width="24%" valign="middle">
|
|
49
|
+
<strong>Virtual Try-On</strong>
|
|
50
|
+
</td>
|
|
51
|
+
<td width="60%" valign="middle">
|
|
52
|
+
Seamlessly change outfits, preserving exact body shape, natural motion, and an
|
|
53
|
+
authentic fit.
|
|
54
|
+
</td>
|
|
55
|
+
<td rowspan="2" width="16%" align="center" valign="middle">
|
|
56
|
+
<a href="./docs/videos/use-cases/virtual-try-on.mp4">
|
|
57
|
+
<img src="./docs/images/use-cases/virtual-try-on-poster.png" alt="Play the Virtual Try-On demo" width="120">
|
|
58
|
+
<br>
|
|
59
|
+
<sub>▶ Play demo</sub>
|
|
60
|
+
</a>
|
|
61
|
+
</td>
|
|
62
|
+
</tr>
|
|
63
|
+
<tr>
|
|
64
|
+
<td width="60%" valign="middle">
|
|
65
|
+
<strong>Prompt:</strong> <code>视频中人物衣服替换成参考图中衣服</code>
|
|
66
|
+
<br><br>
|
|
67
|
+
<strong>Reference image:</strong> Select a clear image of the target outfit with a clean background.
|
|
68
|
+
</td>
|
|
69
|
+
</tr>
|
|
70
|
+
<tr>
|
|
71
|
+
<td rowspan="2" width="24%" valign="middle">
|
|
72
|
+
<strong>Video Restyling</strong>
|
|
73
|
+
</td>
|
|
74
|
+
<td width="60%" valign="middle">
|
|
75
|
+
Reimagine your world in any style with an immersive visual experience.
|
|
76
|
+
</td>
|
|
77
|
+
<td rowspan="2" width="16%" align="center" valign="middle">
|
|
78
|
+
<a href="./docs/videos/use-cases/video-restyling.mp4">
|
|
79
|
+
<img src="./docs/images/use-cases/video-restyling-poster.png" alt="Play the Video Restyling demo" width="120">
|
|
80
|
+
<br>
|
|
81
|
+
<sub>▶ Play demo</sub>
|
|
82
|
+
</a>
|
|
83
|
+
</td>
|
|
84
|
+
</tr>
|
|
85
|
+
<tr>
|
|
86
|
+
<td width="60%" valign="middle">
|
|
87
|
+
<strong>Prompt:</strong> <code>视频风格变为参考图指定的风格</code>
|
|
88
|
+
<br><br>
|
|
89
|
+
<strong>Reference image:</strong> Select an image that captures the artistic style you want to apply.
|
|
90
|
+
</td>
|
|
91
|
+
</tr>
|
|
92
|
+
<tr>
|
|
93
|
+
<td rowspan="2" width="24%" valign="middle">
|
|
94
|
+
<strong>AI Companions</strong>
|
|
95
|
+
</td>
|
|
96
|
+
<td width="60%" valign="middle">
|
|
97
|
+
Summon virtual characters into your live camera feed and interact with them
|
|
98
|
+
through gestures.
|
|
99
|
+
</td>
|
|
100
|
+
<td rowspan="2" width="16%" align="center" valign="middle">
|
|
101
|
+
<a href="./docs/videos/use-cases/ai-companions.mp4">
|
|
102
|
+
<img src="./docs/images/use-cases/ai-companions-poster.png" alt="Play the AI Companions demo" width="120">
|
|
103
|
+
<br>
|
|
104
|
+
<sub>▶ Play demo</sub>
|
|
105
|
+
</a>
|
|
106
|
+
</td>
|
|
107
|
+
</tr>
|
|
108
|
+
<tr>
|
|
109
|
+
<td width="60%" valign="middle">
|
|
110
|
+
<strong>Prompt:</strong> <code>指定角色在场景中互动</code>
|
|
111
|
+
<br><br>
|
|
112
|
+
<strong>Reference image:</strong> Select a clear image of the virtual character you want to summon with a clean background.
|
|
113
|
+
</td>
|
|
114
|
+
</tr>
|
|
115
|
+
<tr>
|
|
116
|
+
<td rowspan="2" width="24%" valign="middle">
|
|
117
|
+
<strong>Live Photo</strong>
|
|
118
|
+
</td>
|
|
119
|
+
<td width="60%" valign="middle">
|
|
120
|
+
Animate and control characters in your images simply by drawing motion
|
|
121
|
+
trajectories.
|
|
122
|
+
</td>
|
|
123
|
+
<td rowspan="2" width="16%" align="center" valign="middle">
|
|
124
|
+
<a href="./docs/videos/use-cases/live-photo.mp4">
|
|
125
|
+
<img src="./docs/images/use-cases/live-photo-poster.png" alt="Play the Live Photo demo" width="120">
|
|
126
|
+
<br>
|
|
127
|
+
<sub>▶ Play demo</sub>
|
|
128
|
+
</a>
|
|
129
|
+
</td>
|
|
130
|
+
</tr>
|
|
131
|
+
<tr>
|
|
132
|
+
<td width="60%" valign="middle">
|
|
133
|
+
<strong>Prompt:</strong> <code>让画面自然动起来</code>
|
|
134
|
+
<br><br>
|
|
135
|
+
<strong>Reference image:</strong> Use the input image as the reference
|
|
136
|
+
</td>
|
|
137
|
+
</tr>
|
|
138
|
+
</table>
|
|
139
|
+
|
|
140
|
+
<br>
|
|
141
|
+
|
|
142
|
+
## Why XmaxSDK?
|
|
143
|
+
|
|
144
|
+
<table>
|
|
145
|
+
<thead>
|
|
146
|
+
<tr>
|
|
147
|
+
<th height="104" align="center" valign="middle">
|
|
148
|
+
<img src="./docs/images/why/low-latency.svg" alt="Low latency" width="36" height="36"><br>Low latency
|
|
149
|
+
</th>
|
|
150
|
+
<th height="104" align="center" valign="middle">
|
|
151
|
+
<img src="./docs/images/why/low-cost.svg" alt="Cost efficiency" width="36" height="36"><br>Cost efficiency
|
|
152
|
+
</th>
|
|
153
|
+
<th height="104" align="center" valign="middle">
|
|
154
|
+
<img src="./docs/images/why/high-fidelity.svg" alt="High fidelity" width="36" height="36"><br>High fidelity
|
|
155
|
+
</th>
|
|
156
|
+
</tr>
|
|
157
|
+
</thead>
|
|
158
|
+
<tbody>
|
|
159
|
+
<tr>
|
|
160
|
+
<td>End-to-end latency is measured in <img src="./docs/images/why/latency-highlight.svg" alt="hundreds of milliseconds" width="192" height="20" align="absmiddle">, ensuring that updates to generation conditions and interaction controls are reflected instantly.</td>
|
|
161
|
+
<td>Run on a <img src="./docs/images/why/gpu-highlight.svg" alt="single RTX 5090" width="126" height="20" align="absmiddle">, reducing inference costs by orders of magnitude versus datacenter GPUs like H100.</td>
|
|
162
|
+
<td>Our models support real-time generation at up to <img src="./docs/images/why/resolution-highlight.svg" alt="1080p" width="48" height="20" align="absmiddle">, delivering production-ready, high-quality video output.</td>
|
|
163
|
+
</tr>
|
|
164
|
+
</tbody>
|
|
165
|
+
</table>
|
|
166
|
+
|
|
167
|
+
<br>
|
|
168
|
+
|
|
169
|
+
## Prerequisites
|
|
170
|
+
|
|
171
|
+
- A WebRTC-enabled browser running on HTTPS or localhost
|
|
172
|
+
- Node.js 18 or later, with pnpm or npm for development
|
|
173
|
+
- An Xmax API key
|
|
174
|
+
|
|
175
|
+
> [!WARNING]
|
|
176
|
+
> Never commit your Xmax API key to version control or embed a long-lived key in
|
|
177
|
+
> client-side bundles. Use short-lived temporary keys issued by your backend
|
|
178
|
+
> through the Xmax API. For step-by-step
|
|
179
|
+
> instructions, see [Authentication](https://platform.xmaxai.com/docs/authentication).
|
|
180
|
+
|
|
181
|
+
<br>
|
|
182
|
+
|
|
183
|
+
## Installation
|
|
184
|
+
|
|
185
|
+
XmaxSDK currently supports [**workspace integration**](#workspace) (pnpm or npm) and
|
|
186
|
+
[**manual integration**](#manual). The packages are not yet published to npm.
|
|
187
|
+
|
|
188
|
+
### Workspace
|
|
189
|
+
|
|
190
|
+
From the root of this repository, install the dependencies and build the SDK.
|
|
191
|
+
Both pnpm and npm workspaces are supported:
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
# pnpm
|
|
195
|
+
pnpm install
|
|
196
|
+
pnpm build
|
|
197
|
+
pnpm dev
|
|
198
|
+
|
|
199
|
+
# npm
|
|
200
|
+
npm install
|
|
201
|
+
npm run build --workspace=@xmaxai/web-sdk
|
|
202
|
+
npm run dev --workspace=xlab-react
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
> The root-level scripts in `package.json` call the pnpm CLI. With npm, use the
|
|
206
|
+
> `npm run <script> --workspace=<name>` equivalents shown above.
|
|
207
|
+
|
|
208
|
+
Add the following to your application's `package.json` within the same workspace:
|
|
209
|
+
|
|
210
|
+
```json
|
|
211
|
+
{
|
|
212
|
+
"dependencies": {
|
|
213
|
+
"@xmaxai/web-sdk": "*"
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Then install the dependencies with `pnpm install` or `npm install`.
|
|
219
|
+
|
|
220
|
+
### Manual
|
|
221
|
+
|
|
222
|
+
After building the SDK, create a local package:
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
cd packages/xmax-sdk
|
|
226
|
+
pnpm pack
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Then install the generated `xmaxai-web-sdk-1.0.0.tgz` in your application:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
npm install /path/to/xmaxai-web-sdk-1.0.0.tgz
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Use a JavaScript bundler to resolve the package and its dependencies.
|
|
236
|
+
The same package includes optional React components at `@xmaxai/web-sdk/react`.
|
|
237
|
+
React applications use their own React installation; non-React applications do not need React.
|
|
238
|
+
|
|
239
|
+
<br>
|
|
240
|
+
|
|
241
|
+
## Quick Start
|
|
242
|
+
|
|
243
|
+
### Configure permissions
|
|
244
|
+
|
|
245
|
+
Serve your application over HTTPS or localhost and allow camera access in the
|
|
246
|
+
browser. When embedding the application in an iframe, allow camera access:
|
|
247
|
+
|
|
248
|
+
```html
|
|
249
|
+
<iframe src="https://your-app.example" allow="camera; microphone; autoplay"></iframe>
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Configure permissions to match your application's user experience. XmaxSDK
|
|
253
|
+
automatically prompts for camera access when creating the video stream and throws
|
|
254
|
+
an `XmaxError` if permission is denied or unavailable.
|
|
255
|
+
|
|
256
|
+
<br>
|
|
257
|
+
|
|
258
|
+
### Generate and display video
|
|
259
|
+
|
|
260
|
+
The following JavaScript snippet creates a camera stream, starts real-time generation,
|
|
261
|
+
and binds the output to a video view. Run this within an async function in the browser,
|
|
262
|
+
after a user action such as clicking a Start button.
|
|
263
|
+
|
|
264
|
+
```javascript
|
|
265
|
+
import {
|
|
266
|
+
CameraPosition,
|
|
267
|
+
RealtimeConfiguration,
|
|
268
|
+
RealtimeContext,
|
|
269
|
+
RealtimeModel,
|
|
270
|
+
RealtimeVideoFormat,
|
|
271
|
+
VideoContentMode,
|
|
272
|
+
XmaxClient,
|
|
273
|
+
XmaxConfiguration,
|
|
274
|
+
XmaxRealtimeVideoView,
|
|
275
|
+
} from "@xmaxai/web-sdk";
|
|
276
|
+
|
|
277
|
+
const client = new XmaxClient(
|
|
278
|
+
new XmaxConfiguration({ apiKey: "YOUR_TEMPORARY_XMAX_API_KEY" })
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
const realtime = client.createRealtimeManager(
|
|
282
|
+
new RealtimeConfiguration({ model: RealtimeModel.x2_fast_1080p })
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
const localStream = await realtime.createLocalCameraStream({
|
|
286
|
+
videoFormat: new RealtimeVideoFormat({ width: 1024, height: 1920, fps: 30 }),
|
|
287
|
+
position: CameraPosition.front,
|
|
288
|
+
useMicrophone: false,
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
const videoView = new XmaxRealtimeVideoView({
|
|
292
|
+
localTrack: localStream.videoTrack,
|
|
293
|
+
videoContentMode: VideoContentMode.fill,
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
videoView.element.style.width = "100%";
|
|
297
|
+
videoView.element.style.height = "100%";
|
|
298
|
+
const container = document.getElementById("video-container");
|
|
299
|
+
if (!container) throw new Error("Missing #video-container element");
|
|
300
|
+
videoView.attach(container);
|
|
301
|
+
|
|
302
|
+
const remoteStream = await realtime.startGeneration({
|
|
303
|
+
localStream,
|
|
304
|
+
context: new RealtimeContext({
|
|
305
|
+
prompt: "视频中角色替换成参考图中角色",
|
|
306
|
+
referencePath: "https://platform.xmaxai.com/images/source/charx/chatx_image1.jpg",
|
|
307
|
+
}),
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
videoView.remoteTrack = remoteStream.videoTrack;
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
Add a `video-container` element with an explicit width and height to your page.
|
|
314
|
+
The view displays a local camera preview until the first generated frame arrives.
|
|
315
|
+
|
|
316
|
+
<br>
|
|
317
|
+
|
|
318
|
+
### Using React
|
|
319
|
+
|
|
320
|
+
Use `XmaxRealtimeVideo` as your primary React view. Store the local and remote
|
|
321
|
+
tracks in component state, updating them dynamically as streams become available:
|
|
322
|
+
|
|
323
|
+
```jsx
|
|
324
|
+
import { XmaxRealtimeVideo } from "@xmaxai/web-sdk/react";
|
|
325
|
+
import { VideoContentMode } from "@xmaxai/web-sdk";
|
|
326
|
+
|
|
327
|
+
<XmaxRealtimeVideo
|
|
328
|
+
localTrack={localTrack}
|
|
329
|
+
remoteTrack={remoteTrack}
|
|
330
|
+
videoContentMode={VideoContentMode.fill}
|
|
331
|
+
style={{ width: "100%", height: "100%" }}
|
|
332
|
+
/>
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
See the [React component](./packages/xmax-sdk/src/react/XmaxRealtimeVideo.tsx) for state binding and the
|
|
336
|
+
[example project](#example-project) for a complete implementation.
|
|
337
|
+
|
|
338
|
+
<br>
|
|
339
|
+
|
|
340
|
+
### Listen for events
|
|
341
|
+
|
|
342
|
+
After creating `realtime`, register the listeners you need before creating the
|
|
343
|
+
input stream or starting generation.
|
|
344
|
+
|
|
345
|
+
| Listener | Purpose |
|
|
346
|
+
| --- | --- |
|
|
347
|
+
| `setStateListener` | Observe pipeline states and termination reasons during real-time generation. |
|
|
348
|
+
| `setLaunchTimingListener` | Monitor camera, connection, first-frame, and total launch timings. |
|
|
349
|
+
| `setLocalVideoStatisticsListener` | Monitor uplink video resolution, frame rate, and bitrate. |
|
|
350
|
+
| `setRemoteVideoStatisticsListener` | Monitor downlink video statistics, packet loss, playback buffer delay, RTT, and estimated RTC end-to-end delay. |
|
|
351
|
+
|
|
352
|
+
For example, monitor state changes and errors:
|
|
353
|
+
|
|
354
|
+
```javascript
|
|
355
|
+
await realtime.setStateListener((state) => {
|
|
356
|
+
console.log("State:", state.connectionState);
|
|
357
|
+
if (state.reason?.kind === "failure") {
|
|
358
|
+
console.error("Error:", state.reason.error.code, state.reason.error.message);
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
Handle errors thrown by async calls with `try/catch`. Failures that end the realtime
|
|
364
|
+
workflow are also available through `state.reason` after cleanup completes.
|
|
365
|
+
|
|
366
|
+
For camera input, bind the returned video track to a preview view. The SDK enters
|
|
367
|
+
`ready` after it has received a valid frame and the preview view is bound; observe
|
|
368
|
+
this through `setStateListener`.
|
|
369
|
+
|
|
370
|
+
<br>
|
|
371
|
+
|
|
372
|
+
### Resource Cleanup
|
|
373
|
+
|
|
374
|
+
- **`disconnect()` — Stop Remote Generation**
|
|
375
|
+
|
|
376
|
+
Stops remote generation and cancels billing while keeping the local camera stream
|
|
377
|
+
and preview active. Use this when ending the online session but staying on the
|
|
378
|
+
current screen. You can start a new session later using the same local stream:
|
|
379
|
+
|
|
380
|
+
```javascript
|
|
381
|
+
await realtime.disconnect();
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
- **`close()` — Full Teardown & Release**
|
|
385
|
+
|
|
386
|
+
Ends the remote session, stops local media capture, and releases all engine
|
|
387
|
+
resources. Use this when leaving or dismissing the generation screen:
|
|
388
|
+
|
|
389
|
+
```javascript
|
|
390
|
+
await realtime.close();
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
> **Note:** These methods are alternatives, not sequential steps. When exiting a
|
|
394
|
+
> screen, call `close()` directly—there is no need to call `disconnect()` first.
|
|
395
|
+
|
|
396
|
+
<br>
|
|
397
|
+
|
|
398
|
+
> [!TIP]
|
|
399
|
+
> For complete usage examples, including camera input, reference images,
|
|
400
|
+
> and live statistics, see the [example project](./examples/xlab-react).
|
|
401
|
+
|
|
402
|
+
<br>
|
|
403
|
+
|
|
404
|
+
## Example Project
|
|
405
|
+
|
|
406
|
+
A complete example application featuring React is available in
|
|
407
|
+
[`examples/xlab-react`](./examples/xlab-react).
|
|
408
|
+
It demonstrates real-time generation using live camera feeds and reference images.
|
|
409
|
+
|
|
410
|
+
<br>
|
|
411
|
+
|
|
412
|
+
## Dependencies
|
|
413
|
+
|
|
414
|
+
- <ins><strong>Tencent Cloud TRTC SDK for Web</strong></ins> enables low-latency, real-time audio and video communication.
|
|
415
|
+
- <ins><strong>Tencent Cloud COS SDK</strong></ins> handles media upload and download via object storage.
|
|
416
|
+
|
|
417
|
+
<br>
|
|
418
|
+
|
|
419
|
+
## Contact us
|
|
420
|
+
|
|
421
|
+
For bug reports and feature requests, please open a
|
|
422
|
+
[GitHub Issue](../../issues). For integration
|
|
423
|
+
assistance and technical support, contact us at [sdk@xmax.ai](mailto:sdk@xmax.ai).
|
|
424
|
+
|
|
425
|
+
<br>
|
|
426
|
+
|
|
427
|
+
## License
|
|
428
|
+
|
|
429
|
+
XmaxSDK Web is available under the terms of the [MIT License](./LICENSE).
|
|
430
|
+
Third-party dependencies and model weights retain their respective licenses.
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 实时视频的编码策略偏好。
|
|
3
|
+
*/
|
|
4
|
+
declare enum RealtimeVideoEncoderPreference {
|
|
5
|
+
/** 优先保障帧率(弱网降分辨率)。 */
|
|
6
|
+
maintainFramerate = "maintainFramerate",
|
|
7
|
+
/** 优先保障分辨率(弱网降帧率)。 */
|
|
8
|
+
maintainQuality = "maintainQuality"
|
|
9
|
+
}
|
|
10
|
+
interface RealtimeVideoFormatInit {
|
|
11
|
+
/** 视频宽度,单位为像素。 */
|
|
12
|
+
width: number;
|
|
13
|
+
/** 视频高度,单位为像素。 */
|
|
14
|
+
height: number;
|
|
15
|
+
/** 视频帧率,必须大于 0。 */
|
|
16
|
+
fps: number;
|
|
17
|
+
/** 最低上传码率,单位为 kbps;缺省使用 SDK 默认值,0 表示不设最低码率。 */
|
|
18
|
+
minimumBitrate?: number;
|
|
19
|
+
/** 最高上传码率,单位为 kbps;缺省使用 SDK 默认值,指定时必须大于 0。 */
|
|
20
|
+
maximumBitrate?: number;
|
|
21
|
+
/** 上传编码策略偏好,默认优先保障帧率。 */
|
|
22
|
+
encoderPreference?: RealtimeVideoEncoderPreference;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 实时视频的尺寸、帧率和上传编码配置。
|
|
26
|
+
*/
|
|
27
|
+
declare class RealtimeVideoFormat {
|
|
28
|
+
readonly width: number;
|
|
29
|
+
readonly height: number;
|
|
30
|
+
readonly fps: number;
|
|
31
|
+
readonly minimumBitrate?: number;
|
|
32
|
+
readonly maximumBitrate?: number;
|
|
33
|
+
readonly encoderPreference: RealtimeVideoEncoderPreference;
|
|
34
|
+
/**
|
|
35
|
+
* 创建实时视频格式。
|
|
36
|
+
*
|
|
37
|
+
* @param init.width 视频宽度,单位为像素。
|
|
38
|
+
* @param init.height 视频高度,单位为像素。
|
|
39
|
+
* @param init.fps 视频帧率,必须大于 0。
|
|
40
|
+
* @param init.minimumBitrate 最低上传码率,单位为 kbps;缺省按最终上传尺寸和帧率计算。
|
|
41
|
+
* @param init.maximumBitrate 最高上传码率,单位为 kbps;缺省按最终上传尺寸和帧率计算。
|
|
42
|
+
* @param init.encoderPreference 上传编码策略偏好,默认值为 maintainFramerate。
|
|
43
|
+
*/
|
|
44
|
+
constructor(init: RealtimeVideoFormatInit);
|
|
45
|
+
/**
|
|
46
|
+
* 校验尺寸、帧率和显式指定的码率范围。
|
|
47
|
+
* @throws 尺寸、帧率或码率配置无效时抛出错误。
|
|
48
|
+
*/
|
|
49
|
+
validate(): void;
|
|
50
|
+
/** 调整尺寸,保留帧率和上传编码配置。 */
|
|
51
|
+
resized(width: number, height: number): RealtimeVideoFormat;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 相机采集使用的镜头方向。
|
|
56
|
+
*
|
|
57
|
+
* 采集时映射为 RTC 层的前后置选择;桌面设备通常只有前置等价
|
|
58
|
+
* 摄像头,back 会回退到可用设备。
|
|
59
|
+
*/
|
|
60
|
+
declare enum CameraPosition {
|
|
61
|
+
/** 前置摄像头(面向用户)。 */
|
|
62
|
+
front = "front",
|
|
63
|
+
/** 后置摄像头(面向环境)。 */
|
|
64
|
+
back = "back"
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface RealtimeVideoTrackInit {
|
|
68
|
+
/** 视频轨道标识。 */
|
|
69
|
+
id: string;
|
|
70
|
+
/** 轨道当前使用的视频格式。 */
|
|
71
|
+
videoFormat?: RealtimeVideoFormat;
|
|
72
|
+
/** 本地相机轨道的摄像头位置。 */
|
|
73
|
+
position?: CameraPosition;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 实时视频轨道及其动态元数据。
|
|
77
|
+
*
|
|
78
|
+
* Web 版本额外持有 `MediaStreamTrack` 句柄(SDK 内部使用),
|
|
79
|
+
* 渲染层通过它把画面绑定到 `<video>` 元素。
|
|
80
|
+
*/
|
|
81
|
+
declare class RealtimeVideoTrack {
|
|
82
|
+
/** 视频轨道标识。 */
|
|
83
|
+
readonly id: string;
|
|
84
|
+
private metadata;
|
|
85
|
+
/**
|
|
86
|
+
* SDK 内部:轨道对应的 Web 媒体轨。
|
|
87
|
+
* 本地轨道在采集启动后可用;远端轨道在订阅成功后可用。
|
|
88
|
+
*/
|
|
89
|
+
mediaStreamTrack?: MediaStreamTrack;
|
|
90
|
+
/**
|
|
91
|
+
* 创建实时视频轨道。
|
|
92
|
+
*
|
|
93
|
+
* @param init.id 视频轨道标识。
|
|
94
|
+
* @param init.videoFormat 轨道初始视频格式。
|
|
95
|
+
* @param init.position 本地相机轨道的初始摄像头位置。
|
|
96
|
+
*/
|
|
97
|
+
constructor(init: RealtimeVideoTrackInit);
|
|
98
|
+
/** 当前视频轨道使用的视频格式。 */
|
|
99
|
+
get videoFormat(): RealtimeVideoFormat | undefined;
|
|
100
|
+
/** 本地相机轨道当前使用的摄像头位置。 */
|
|
101
|
+
get position(): CameraPosition | undefined;
|
|
102
|
+
/** 更新轨道视频格式。 @internal */
|
|
103
|
+
updateVideoFormat(videoFormat: RealtimeVideoFormat): void;
|
|
104
|
+
/** 更新轨道摄像头位置。 @internal */
|
|
105
|
+
updatePosition(position: CameraPosition): void;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 视频内容在渲染容器中的显示模式。
|
|
110
|
+
*/
|
|
111
|
+
declare enum VideoContentMode {
|
|
112
|
+
/** 等比完整显示,允许容器留空。 */
|
|
113
|
+
fit = "fit",
|
|
114
|
+
/** 等比铺满容器,允许裁剪画面。 */
|
|
115
|
+
fill = "fill"
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export { CameraPosition as C, RealtimeVideoFormat as R, VideoContentMode as V, RealtimeVideoTrack as a, RealtimeVideoEncoderPreference as b, type RealtimeVideoFormatInit as c };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 实时视频的编码策略偏好。
|
|
3
|
+
*/
|
|
4
|
+
declare enum RealtimeVideoEncoderPreference {
|
|
5
|
+
/** 优先保障帧率(弱网降分辨率)。 */
|
|
6
|
+
maintainFramerate = "maintainFramerate",
|
|
7
|
+
/** 优先保障分辨率(弱网降帧率)。 */
|
|
8
|
+
maintainQuality = "maintainQuality"
|
|
9
|
+
}
|
|
10
|
+
interface RealtimeVideoFormatInit {
|
|
11
|
+
/** 视频宽度,单位为像素。 */
|
|
12
|
+
width: number;
|
|
13
|
+
/** 视频高度,单位为像素。 */
|
|
14
|
+
height: number;
|
|
15
|
+
/** 视频帧率,必须大于 0。 */
|
|
16
|
+
fps: number;
|
|
17
|
+
/** 最低上传码率,单位为 kbps;缺省使用 SDK 默认值,0 表示不设最低码率。 */
|
|
18
|
+
minimumBitrate?: number;
|
|
19
|
+
/** 最高上传码率,单位为 kbps;缺省使用 SDK 默认值,指定时必须大于 0。 */
|
|
20
|
+
maximumBitrate?: number;
|
|
21
|
+
/** 上传编码策略偏好,默认优先保障帧率。 */
|
|
22
|
+
encoderPreference?: RealtimeVideoEncoderPreference;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 实时视频的尺寸、帧率和上传编码配置。
|
|
26
|
+
*/
|
|
27
|
+
declare class RealtimeVideoFormat {
|
|
28
|
+
readonly width: number;
|
|
29
|
+
readonly height: number;
|
|
30
|
+
readonly fps: number;
|
|
31
|
+
readonly minimumBitrate?: number;
|
|
32
|
+
readonly maximumBitrate?: number;
|
|
33
|
+
readonly encoderPreference: RealtimeVideoEncoderPreference;
|
|
34
|
+
/**
|
|
35
|
+
* 创建实时视频格式。
|
|
36
|
+
*
|
|
37
|
+
* @param init.width 视频宽度,单位为像素。
|
|
38
|
+
* @param init.height 视频高度,单位为像素。
|
|
39
|
+
* @param init.fps 视频帧率,必须大于 0。
|
|
40
|
+
* @param init.minimumBitrate 最低上传码率,单位为 kbps;缺省按最终上传尺寸和帧率计算。
|
|
41
|
+
* @param init.maximumBitrate 最高上传码率,单位为 kbps;缺省按最终上传尺寸和帧率计算。
|
|
42
|
+
* @param init.encoderPreference 上传编码策略偏好,默认值为 maintainFramerate。
|
|
43
|
+
*/
|
|
44
|
+
constructor(init: RealtimeVideoFormatInit);
|
|
45
|
+
/**
|
|
46
|
+
* 校验尺寸、帧率和显式指定的码率范围。
|
|
47
|
+
* @throws 尺寸、帧率或码率配置无效时抛出错误。
|
|
48
|
+
*/
|
|
49
|
+
validate(): void;
|
|
50
|
+
/** 调整尺寸,保留帧率和上传编码配置。 */
|
|
51
|
+
resized(width: number, height: number): RealtimeVideoFormat;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 相机采集使用的镜头方向。
|
|
56
|
+
*
|
|
57
|
+
* 采集时映射为 RTC 层的前后置选择;桌面设备通常只有前置等价
|
|
58
|
+
* 摄像头,back 会回退到可用设备。
|
|
59
|
+
*/
|
|
60
|
+
declare enum CameraPosition {
|
|
61
|
+
/** 前置摄像头(面向用户)。 */
|
|
62
|
+
front = "front",
|
|
63
|
+
/** 后置摄像头(面向环境)。 */
|
|
64
|
+
back = "back"
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface RealtimeVideoTrackInit {
|
|
68
|
+
/** 视频轨道标识。 */
|
|
69
|
+
id: string;
|
|
70
|
+
/** 轨道当前使用的视频格式。 */
|
|
71
|
+
videoFormat?: RealtimeVideoFormat;
|
|
72
|
+
/** 本地相机轨道的摄像头位置。 */
|
|
73
|
+
position?: CameraPosition;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 实时视频轨道及其动态元数据。
|
|
77
|
+
*
|
|
78
|
+
* Web 版本额外持有 `MediaStreamTrack` 句柄(SDK 内部使用),
|
|
79
|
+
* 渲染层通过它把画面绑定到 `<video>` 元素。
|
|
80
|
+
*/
|
|
81
|
+
declare class RealtimeVideoTrack {
|
|
82
|
+
/** 视频轨道标识。 */
|
|
83
|
+
readonly id: string;
|
|
84
|
+
private metadata;
|
|
85
|
+
/**
|
|
86
|
+
* SDK 内部:轨道对应的 Web 媒体轨。
|
|
87
|
+
* 本地轨道在采集启动后可用;远端轨道在订阅成功后可用。
|
|
88
|
+
*/
|
|
89
|
+
mediaStreamTrack?: MediaStreamTrack;
|
|
90
|
+
/**
|
|
91
|
+
* 创建实时视频轨道。
|
|
92
|
+
*
|
|
93
|
+
* @param init.id 视频轨道标识。
|
|
94
|
+
* @param init.videoFormat 轨道初始视频格式。
|
|
95
|
+
* @param init.position 本地相机轨道的初始摄像头位置。
|
|
96
|
+
*/
|
|
97
|
+
constructor(init: RealtimeVideoTrackInit);
|
|
98
|
+
/** 当前视频轨道使用的视频格式。 */
|
|
99
|
+
get videoFormat(): RealtimeVideoFormat | undefined;
|
|
100
|
+
/** 本地相机轨道当前使用的摄像头位置。 */
|
|
101
|
+
get position(): CameraPosition | undefined;
|
|
102
|
+
/** 更新轨道视频格式。 @internal */
|
|
103
|
+
updateVideoFormat(videoFormat: RealtimeVideoFormat): void;
|
|
104
|
+
/** 更新轨道摄像头位置。 @internal */
|
|
105
|
+
updatePosition(position: CameraPosition): void;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 视频内容在渲染容器中的显示模式。
|
|
110
|
+
*/
|
|
111
|
+
declare enum VideoContentMode {
|
|
112
|
+
/** 等比完整显示,允许容器留空。 */
|
|
113
|
+
fit = "fit",
|
|
114
|
+
/** 等比铺满容器,允许裁剪画面。 */
|
|
115
|
+
fill = "fill"
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export { CameraPosition as C, RealtimeVideoFormat as R, VideoContentMode as V, RealtimeVideoTrack as a, RealtimeVideoEncoderPreference as b, type RealtimeVideoFormatInit as c };
|