@vivix-ai/ivi-frontend-sdk 0.3.2 → 0.3.3

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
@@ -170,6 +170,10 @@ runtime.stop();
170
170
 
171
171
  ```ts
172
172
  const runtime = new IviRuntimeCoordinator(client, {
173
+ trtcAIDenoiser: {
174
+ enabled: true,
175
+ mode: "normal" // 也可使用 "far_field_reduction"
176
+ },
173
177
  onTrtcEvent: (event) => {
174
178
  // event.type: "remote_video_available" | "remote_video_unavailable" | "remote_audio_available" | "remote_audio_unavailable"
175
179
  // event.rawType: TRTC SDK 原始事件名
@@ -178,6 +182,8 @@ const runtime = new IviRuntimeCoordinator(client, {
178
182
  });
179
183
  ```
180
184
 
185
+ `trtcAIDenoiser` 默认开启,传 `false` 可关闭;也可以传 `{ enabled, mode, assetsPath }` 调整 TRTC SDK 的 AIDenoiser 插件参数。
186
+
181
187
  ### 3)发送用户文本并触发模型回复
182
188
 
183
189
  ```ts
@@ -489,6 +495,7 @@ TRTC 远端流播放器,自动以 audience 身份入会并订阅远端流。
489
495
  | `loadingFallback` | `ReactNode` | 加载中兜底 |
490
496
  | `errorFallback` | `ReactNode` | 错误兜底 |
491
497
  | `muted` | `boolean` | 是否静音 |
498
+ | `trtcAIDenoiser` | `boolean \| IviRuntimeTrtcAIDenoiserOptions` | 独立使用 `IVITrtcPlayer` 时的 TRTC AIDenoiser 配置,默认开启 |
492
499
  | `className` / `style` | — | 容器样式 |
493
500
 
494
501
  ### `IVILivekitPlayer`
package/dist/index.cjs CHANGED
@@ -1107,10 +1107,15 @@ var ConversationManager = class {
1107
1107
 
1108
1108
  // src/runtime/managers/trtc-source-manager.ts
1109
1109
  var TAG = "[IVI-TRTC]";
1110
+ var DEFAULT_DENOISER_OPTIONS = {
1111
+ enabled: true,
1112
+ mode: "normal"
1113
+ };
1110
1114
  var TrtcSourceManager = class {
1111
- constructor(onLog, onTrtcEvent) {
1115
+ constructor(onLog, onTrtcEvent, aiDenoiser) {
1112
1116
  this.onLog = onLog;
1113
1117
  this.onTrtcEvent = onTrtcEvent;
1118
+ this.aiDenoiser = aiDenoiser;
1114
1119
  this.sessions = /* @__PURE__ */ new Map();
1115
1120
  this.listeners = /* @__PURE__ */ new Map();
1116
1121
  }
@@ -1137,21 +1142,21 @@ var TrtcSourceManager = class {
1137
1142
  * 按 sourceId 注册/更新 TRTC 配置。
1138
1143
  * 若配置发生变化,会先销毁旧会话再按新参数重建连接。
1139
1144
  */
1140
- upsertSource(sourceId, trtc) {
1145
+ upsertSource(sourceId, trtc, aiDenoiser) {
1141
1146
  const existing = this.sessions.get(sourceId);
1142
1147
  if (!existing) {
1143
1148
  this.log("info", `\u65B0\u5EFA\u4F1A\u8BDD source=${sourceId} room=${getTrtcString(trtc, "room_id")} user=${getTrtcString(trtc, "user_id")}`);
1144
- const session2 = this.createSession(sourceId, trtc);
1149
+ const session2 = this.createSession(sourceId, trtc, aiDenoiser);
1145
1150
  this.sessions.set(sourceId, session2);
1146
1151
  void this.ensureConnected(session2);
1147
1152
  return;
1148
1153
  }
1149
- if (isSameTrtcConfig(existing.trtc, trtc)) {
1154
+ if (isSameTrtcConfig(existing.trtc, trtc) && isSameAIDenoiserOptions(existing.aiDenoiser, aiDenoiser)) {
1150
1155
  return;
1151
1156
  }
1152
1157
  this.log("info", `\u914D\u7F6E\u53D8\u66F4\uFF0C\u91CD\u5EFA\u4F1A\u8BDD source=${sourceId} room=${getTrtcString(trtc, "room_id")}`);
1153
1158
  void this.disposeSession(existing);
1154
- const session = this.createSession(sourceId, trtc);
1159
+ const session = this.createSession(sourceId, trtc, aiDenoiser);
1155
1160
  this.sessions.set(sourceId, session);
1156
1161
  void this.ensureConnected(session);
1157
1162
  }
@@ -1288,10 +1293,11 @@ var TrtcSourceManager = class {
1288
1293
  binding.muted = muted;
1289
1294
  void this.applyAudioPolicy(session);
1290
1295
  }
1291
- createSession(sourceId, trtc) {
1296
+ createSession(sourceId, trtc, aiDenoiser) {
1292
1297
  return {
1293
1298
  sourceId,
1294
1299
  trtc,
1300
+ aiDenoiser,
1295
1301
  TRTC: null,
1296
1302
  client: null,
1297
1303
  connectPromise: null,
@@ -1397,6 +1403,7 @@ var TrtcSourceManager = class {
1397
1403
  session.status = "connected";
1398
1404
  session.error = void 0;
1399
1405
  this.log("info", `\u8FDB\u623F\u6210\u529F source=${session.sourceId} room=${roomId}`);
1406
+ await this.applyAIDenoiserPolicy(session, client, sdkAppId, userId, userSig);
1400
1407
  this.emitSnapshot(session.sourceId, {
1401
1408
  status: session.status
1402
1409
  });
@@ -1482,6 +1489,25 @@ var TrtcSourceManager = class {
1482
1489
  await client.muteRemoteAudio(userId, false);
1483
1490
  }
1484
1491
  }
1492
+ async applyAIDenoiserPolicy(session, client, sdkAppId, userId, userSig) {
1493
+ const options = resolveAIDenoiserOptions(session.aiDenoiser ?? this.aiDenoiser);
1494
+ if (!options.enabled) {
1495
+ this.log("info", `TRTC AIDenoiser \u5DF2\u5173\u95ED source=${session.sourceId}`);
1496
+ return;
1497
+ }
1498
+ try {
1499
+ await client.startPlugin("AIDenoiser", {
1500
+ sdkAppId,
1501
+ userId,
1502
+ userSig,
1503
+ mode: getAIDenoiserModeValue(options.mode),
1504
+ ...options.assetsPath ? { assetsPath: options.assetsPath } : {}
1505
+ });
1506
+ this.log("info", `TRTC AIDenoiser \u5DF2\u5F00\u542F source=${session.sourceId} mode=${options.mode}`);
1507
+ } catch (error) {
1508
+ this.log("warn", `TRTC AIDenoiser \u5F00\u542F\u5931\u8D25 source=${session.sourceId}`, error);
1509
+ }
1510
+ }
1485
1511
  /**
1486
1512
  * 销毁单个 source 会话:
1487
1513
  * 解绑事件、停止远端视频、退出房间并销毁客户端。
@@ -1563,6 +1589,11 @@ function isRuntimeTrtcSource(source) {
1563
1589
  function isSameTrtcConfig(a, b) {
1564
1590
  return a.app_id === b.app_id && a.user_id === b.user_id && a.user_sig === b.user_sig && a.room_id === b.room_id;
1565
1591
  }
1592
+ function isSameAIDenoiserOptions(a, b) {
1593
+ const left = resolveAIDenoiserOptions(a);
1594
+ const right = resolveAIDenoiserOptions(b);
1595
+ return left.enabled === right.enabled && left.mode === right.mode && left.assetsPath === right.assetsPath;
1596
+ }
1566
1597
  function shouldUseStringRoomId(roomId) {
1567
1598
  if (!/^\d+$/.test(roomId)) {
1568
1599
  return true;
@@ -1574,6 +1605,26 @@ function getTrtcString(trtc, key) {
1574
1605
  const value = trtc[key];
1575
1606
  return typeof value === "string" ? value : "";
1576
1607
  }
1608
+ function resolveAIDenoiserOptions(options) {
1609
+ if (options === false) {
1610
+ return {
1611
+ ...DEFAULT_DENOISER_OPTIONS,
1612
+ enabled: false
1613
+ };
1614
+ }
1615
+ if (options === true || options === void 0) {
1616
+ return DEFAULT_DENOISER_OPTIONS;
1617
+ }
1618
+ return {
1619
+ ...DEFAULT_DENOISER_OPTIONS,
1620
+ ...options,
1621
+ enabled: options.enabled ?? DEFAULT_DENOISER_OPTIONS.enabled,
1622
+ mode: options.mode ?? DEFAULT_DENOISER_OPTIONS.mode
1623
+ };
1624
+ }
1625
+ function getAIDenoiserModeValue(mode) {
1626
+ return mode === "far_field_reduction" ? 1 : 0;
1627
+ }
1577
1628
  function buildRemoteVideoKey(userId, streamType) {
1578
1629
  return `${userId}::${streamType}`;
1579
1630
  }
@@ -2076,7 +2127,8 @@ var IviRuntimeCoordinator = class {
2076
2127
  };
2077
2128
  this.trtcSourceManager = new TrtcSourceManager(
2078
2129
  this.config.onLog,
2079
- (event) => this.emitTrtcEvent(event)
2130
+ (event) => this.emitTrtcEvent(event),
2131
+ this.config.trtcAIDenoiser
2080
2132
  );
2081
2133
  this.livekitSourceManager = new LivekitSourceManager(this.config.onLog);
2082
2134
  this.sessionHandler = new SessionEventHandler(this.sessionManager, {
@@ -3156,7 +3208,8 @@ function IVITrtcPlayer(props) {
3156
3208
  style,
3157
3209
  loadingFallback = null,
3158
3210
  errorFallback = null,
3159
- muted = false
3211
+ muted = false,
3212
+ trtcAIDenoiser
3160
3213
  } = props;
3161
3214
  const containerRef = react.useRef(null);
3162
3215
  const viewIdRef = react.useRef(`trtc-view-${Math.random().toString(36).slice(2, 10)}`);
@@ -3177,7 +3230,7 @@ function IVITrtcPlayer(props) {
3177
3230
  }
3178
3231
  let disposed = false;
3179
3232
  if (shouldManageSourceLifecycle) {
3180
- manager.upsertSource(resolvedSourceId, trtc);
3233
+ manager.upsertSource(resolvedSourceId, trtc, trtcAIDenoiser);
3181
3234
  }
3182
3235
  const unsubscribe = manager.subscribe(resolvedSourceId, (snapshot) => {
3183
3236
  if (disposed) {
@@ -3208,7 +3261,8 @@ function IVITrtcPlayer(props) {
3208
3261
  trtc.app_id,
3209
3262
  trtc.room_id,
3210
3263
  trtc.user_id,
3211
- trtc.user_sig
3264
+ trtc.user_sig,
3265
+ trtcAIDenoiser
3212
3266
  ]);
3213
3267
  react.useEffect(() => {
3214
3268
  manager.updateViewMuted(resolvedSourceId, viewIdRef.current, muted);