@vivix-ai/ivi-frontend-sdk 0.3.1 → 0.3.2
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 +17 -0
- package/dist/index.cjs +32 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -2
- package/dist/index.d.ts +21 -2
- package/dist/index.js +32 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -155,12 +155,29 @@ const unlistenEvent = runtime.onEvent((event, state) => {
|
|
|
155
155
|
console.log("event:", event.type, "runtime:", state.status);
|
|
156
156
|
});
|
|
157
157
|
|
|
158
|
+
const unlistenTrtcEvent = runtime.onTrtcEvent((event) => {
|
|
159
|
+
console.log("trtc event:", event.sourceId, event.type, event.payload);
|
|
160
|
+
});
|
|
161
|
+
|
|
158
162
|
// 业务结束时
|
|
159
163
|
unlistenState();
|
|
160
164
|
unlistenEvent();
|
|
165
|
+
unlistenTrtcEvent();
|
|
161
166
|
runtime.stop();
|
|
162
167
|
```
|
|
163
168
|
|
|
169
|
+
也可以在创建 runtime 时通过 `onTrtcEvent` 配置项统一接收 TRTC SDK 原始事件:
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
const runtime = new IviRuntimeCoordinator(client, {
|
|
173
|
+
onTrtcEvent: (event) => {
|
|
174
|
+
// event.type: "remote_video_available" | "remote_video_unavailable" | "remote_audio_available" | "remote_audio_unavailable"
|
|
175
|
+
// event.rawType: TRTC SDK 原始事件名
|
|
176
|
+
// event.payload: TRTC SDK 原始事件 payload
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
164
181
|
### 3)发送用户文本并触发模型回复
|
|
165
182
|
|
|
166
183
|
```ts
|
package/dist/index.cjs
CHANGED
|
@@ -1108,8 +1108,9 @@ var ConversationManager = class {
|
|
|
1108
1108
|
// src/runtime/managers/trtc-source-manager.ts
|
|
1109
1109
|
var TAG = "[IVI-TRTC]";
|
|
1110
1110
|
var TrtcSourceManager = class {
|
|
1111
|
-
constructor(onLog) {
|
|
1111
|
+
constructor(onLog, onTrtcEvent) {
|
|
1112
1112
|
this.onLog = onLog;
|
|
1113
|
+
this.onTrtcEvent = onTrtcEvent;
|
|
1113
1114
|
this.sessions = /* @__PURE__ */ new Map();
|
|
1114
1115
|
this.listeners = /* @__PURE__ */ new Map();
|
|
1115
1116
|
}
|
|
@@ -1345,6 +1346,7 @@ var TrtcSourceManager = class {
|
|
|
1345
1346
|
session.views.forEach((binding) => {
|
|
1346
1347
|
void this.startRemoteVideoForBinding(client, event.userId, event.streamType, binding, remoteVideoKey);
|
|
1347
1348
|
});
|
|
1349
|
+
this.emitTrtcEvent(session.sourceId, "remote_video_available", TRTC.EVENT.REMOTE_VIDEO_AVAILABLE, event);
|
|
1348
1350
|
};
|
|
1349
1351
|
const onRemoteVideoUnavailable = (event) => {
|
|
1350
1352
|
this.log("info", `\u8FDC\u7AEF\u89C6\u9891\u4E0D\u53EF\u7528 source=${session.sourceId} userId=${event.userId} streamType=${event.streamType}`);
|
|
@@ -1358,16 +1360,19 @@ var TrtcSourceManager = class {
|
|
|
1358
1360
|
userId: event.userId,
|
|
1359
1361
|
streamType: event.streamType
|
|
1360
1362
|
}).catch(() => void 0);
|
|
1363
|
+
this.emitTrtcEvent(session.sourceId, "remote_video_unavailable", TRTC.EVENT.REMOTE_VIDEO_UNAVAILABLE, event);
|
|
1361
1364
|
};
|
|
1362
1365
|
const onRemoteAudioAvailable = (event) => {
|
|
1363
1366
|
this.log("info", `\u8FDC\u7AEF\u97F3\u9891\u53EF\u7528 source=${session.sourceId} userId=${event.userId}`);
|
|
1364
1367
|
session.remoteAudioUsers.add(event.userId);
|
|
1365
1368
|
void this.applyAudioPolicy(session);
|
|
1369
|
+
this.emitTrtcEvent(session.sourceId, "remote_audio_available", TRTC.EVENT.REMOTE_AUDIO_AVAILABLE, event);
|
|
1366
1370
|
};
|
|
1367
1371
|
const onRemoteAudioUnavailable = (event) => {
|
|
1368
1372
|
this.log("info", `\u8FDC\u7AEF\u97F3\u9891\u4E0D\u53EF\u7528 source=${session.sourceId} userId=${event.userId}`);
|
|
1369
1373
|
session.remoteAudioUsers.delete(event.userId);
|
|
1370
1374
|
void this.applyAudioPolicy(session);
|
|
1375
|
+
this.emitTrtcEvent(session.sourceId, "remote_audio_unavailable", TRTC.EVENT.REMOTE_AUDIO_UNAVAILABLE, event);
|
|
1371
1376
|
};
|
|
1372
1377
|
session.onRemoteVideoAvailable = onRemoteVideoAvailable;
|
|
1373
1378
|
session.onRemoteVideoUnavailable = onRemoteVideoUnavailable;
|
|
@@ -1540,6 +1545,17 @@ var TrtcSourceManager = class {
|
|
|
1540
1545
|
data: extra.length > 0 ? { message, extra } : { message }
|
|
1541
1546
|
});
|
|
1542
1547
|
}
|
|
1548
|
+
emitTrtcEvent(sourceId, type, rawType, payload) {
|
|
1549
|
+
const event = {
|
|
1550
|
+
sourceId,
|
|
1551
|
+
type,
|
|
1552
|
+
rawType: String(rawType),
|
|
1553
|
+
payload,
|
|
1554
|
+
userId: payload.userId,
|
|
1555
|
+
streamType: payload.streamType
|
|
1556
|
+
};
|
|
1557
|
+
this.onTrtcEvent?.(event);
|
|
1558
|
+
}
|
|
1543
1559
|
};
|
|
1544
1560
|
function isRuntimeTrtcSource(source) {
|
|
1545
1561
|
return source.status === "ready" && source.playback?.type === "trtc" && typeof source.playback.trtc === "object" && source.playback.trtc !== null;
|
|
@@ -2038,6 +2054,7 @@ var IviRuntimeCoordinator = class {
|
|
|
2038
2054
|
this.conversationManager = new ConversationManager();
|
|
2039
2055
|
this.stateListeners = /* @__PURE__ */ new Set();
|
|
2040
2056
|
this.eventListeners = /* @__PURE__ */ new Set();
|
|
2057
|
+
this.trtcEventListeners = /* @__PURE__ */ new Set();
|
|
2041
2058
|
this.pendingUserTextToResponseFlows = /* @__PURE__ */ new Map();
|
|
2042
2059
|
this.userTextFlowCounter = 0;
|
|
2043
2060
|
this.waitingTracksListValidation = false;
|
|
@@ -2057,7 +2074,10 @@ var IviRuntimeCoordinator = class {
|
|
|
2057
2074
|
syncStageOnSessionCreated: true,
|
|
2058
2075
|
...config
|
|
2059
2076
|
};
|
|
2060
|
-
this.trtcSourceManager = new TrtcSourceManager(
|
|
2077
|
+
this.trtcSourceManager = new TrtcSourceManager(
|
|
2078
|
+
this.config.onLog,
|
|
2079
|
+
(event) => this.emitTrtcEvent(event)
|
|
2080
|
+
);
|
|
2061
2081
|
this.livekitSourceManager = new LivekitSourceManager(this.config.onLog);
|
|
2062
2082
|
this.sessionHandler = new SessionEventHandler(this.sessionManager, {
|
|
2063
2083
|
onSessionCreated: (event) => this.onSessionCreated(event),
|
|
@@ -2130,6 +2150,12 @@ var IviRuntimeCoordinator = class {
|
|
|
2130
2150
|
this.eventListeners.delete(listener);
|
|
2131
2151
|
};
|
|
2132
2152
|
}
|
|
2153
|
+
onTrtcEvent(listener) {
|
|
2154
|
+
this.trtcEventListeners.add(listener);
|
|
2155
|
+
return () => {
|
|
2156
|
+
this.trtcEventListeners.delete(listener);
|
|
2157
|
+
};
|
|
2158
|
+
}
|
|
2133
2159
|
emitLog(entry) {
|
|
2134
2160
|
this.config.onLog?.(entry);
|
|
2135
2161
|
}
|
|
@@ -2384,6 +2410,10 @@ var IviRuntimeCoordinator = class {
|
|
|
2384
2410
|
this.progressUserTextToResponseFlows(event);
|
|
2385
2411
|
this.eventListeners.forEach((listener) => listener(event, this.state));
|
|
2386
2412
|
}
|
|
2413
|
+
emitTrtcEvent(event) {
|
|
2414
|
+
this.config.onTrtcEvent?.(event);
|
|
2415
|
+
this.trtcEventListeners.forEach((listener) => listener(event));
|
|
2416
|
+
}
|
|
2387
2417
|
resetStoppedState() {
|
|
2388
2418
|
this.rejectPendingUserTextToResponseFlows(
|
|
2389
2419
|
new Error("Runtime stopped before user text to response flow completed.")
|