@coze/realtime-api 1.2.0 → 1.2.1-beta.11
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/dist/cjs/event-names/index.js +53 -1
- package/dist/cjs/index.js +125 -37
- package/dist/esm/event-names/index.js +53 -1
- package/dist/esm/index.js +125 -37
- package/dist/types/client.d.ts +1 -0
- package/dist/types/event-names/client.d.ts +1 -0
- package/dist/types/event-names/event-names.d.ts +66 -1
- package/dist/types/event-names/index.d.ts +11 -2
- package/dist/types/event-names/utils.d.ts +6 -0
- package/dist/types/event-names.d.ts +66 -1
- package/dist/types/index.d.ts +11 -2
- package/dist/types/utils.d.ts +6 -0
- package/dist/umd/index.js +125 -37
- package/package.json +5 -5
package/dist/esm/index.js
CHANGED
@@ -37,6 +37,7 @@ __webpack_require__.d(utils_namespaceObject, {
|
|
37
37
|
checkDevicePermission: ()=>checkDevicePermission,
|
38
38
|
checkPermission: ()=>checkPermission,
|
39
39
|
getAudioDevices: ()=>getAudioDevices,
|
40
|
+
isMobileVideoDevice: ()=>isMobileVideoDevice,
|
40
41
|
isScreenShareDevice: ()=>isScreenShareDevice,
|
41
42
|
isScreenShareSupported: ()=>isScreenShareSupported,
|
42
43
|
sleep: ()=>sleep
|
@@ -108,6 +109,11 @@ __webpack_require__.d(utils_namespaceObject, {
|
|
108
109
|
};
|
109
110
|
};
|
110
111
|
const isScreenShareDevice = (deviceId)=>'screenShare' === deviceId;
|
112
|
+
/**
|
113
|
+
* 判断是否前后置摄像头
|
114
|
+
* @param deviceId
|
115
|
+
* @returns
|
116
|
+
*/ const isMobileVideoDevice = (deviceId)=>'user' === deviceId || 'environment' === deviceId;
|
111
117
|
/**
|
112
118
|
* Check if browser supports screen sharing
|
113
119
|
* 检查浏览器是否支持屏幕共享
|
@@ -129,6 +135,10 @@ var event_names_EventNames = /*#__PURE__*/ function(EventNames) {
|
|
129
135
|
* zh: 所有服务端事件
|
130
136
|
*/ EventNames["ALL_SERVER"] = "server.*";
|
131
137
|
/**
|
138
|
+
* en: Room info
|
139
|
+
* zh: 房间信息
|
140
|
+
*/ EventNames["ROOM_INFO"] = "client.room.info";
|
141
|
+
/**
|
132
142
|
* en: Client connected
|
133
143
|
* zh: 客户端连接
|
134
144
|
*/ EventNames["CONNECTED"] = "client.connected";
|
@@ -161,6 +171,10 @@ var event_names_EventNames = /*#__PURE__*/ function(EventNames) {
|
|
161
171
|
* zh: 客户端视频关闭
|
162
172
|
*/ EventNames["VIDEO_OFF"] = "client.video.off";
|
163
173
|
/**
|
174
|
+
* en: Client video error
|
175
|
+
* zh: 客户端视频(或屏幕共享)错误
|
176
|
+
*/ EventNames["VIDEO_ERROR"] = "client.video.error";
|
177
|
+
/**
|
164
178
|
* en: Client video event
|
165
179
|
* zh: 客户端视频事件
|
166
180
|
*/ EventNames["PLAYER_EVENT"] = "client.video.event";
|
@@ -227,7 +241,51 @@ var event_names_EventNames = /*#__PURE__*/ function(EventNames) {
|
|
227
241
|
/**
|
228
242
|
* en: Session updated
|
229
243
|
* zh: 会话更新
|
230
|
-
*/ EventNames["
|
244
|
+
*/ EventNames["SESSION_UPDATED"] = "server.session.updated";
|
245
|
+
/**
|
246
|
+
* en: Conversation created
|
247
|
+
* zh: 会话创建
|
248
|
+
*/ EventNames["CONVERSATION_CREATED"] = "server.conversation.created";
|
249
|
+
/**
|
250
|
+
* en: Conversation chat created
|
251
|
+
* zh: 会话对话创建
|
252
|
+
*/ EventNames["CONVERSATION_CHAT_CREATED"] = "server.conversation.chat.created";
|
253
|
+
/**
|
254
|
+
* en: Conversation chat in progress
|
255
|
+
* zh: 对话正在处理中
|
256
|
+
*/ EventNames["CONVERSATION_CHAT_IN_PROGRESS"] = "server.conversation.chat.in_progress";
|
257
|
+
/**
|
258
|
+
* en: Conversation message delta received
|
259
|
+
* zh: 文本消息增量返回
|
260
|
+
*/ EventNames["CONVERSATION_MESSAGE_DELTA"] = "server.conversation.message.delta";
|
261
|
+
/**
|
262
|
+
* en: Conversation message completed
|
263
|
+
* zh: 文本消息完成
|
264
|
+
*/ EventNames["CONVERSATION_MESSAGE_COMPLETED"] = "server.conversation.message.completed";
|
265
|
+
/**
|
266
|
+
* en: Conversation chat completed
|
267
|
+
* zh: 对话完成
|
268
|
+
*/ EventNames["CONVERSATION_CHAT_COMPLETED"] = "server.conversation.chat.completed";
|
269
|
+
/**
|
270
|
+
* en: Conversation chat requires action
|
271
|
+
* zh: 对话需要插件
|
272
|
+
*/ EventNames["CONVERSATION_CHAT_REQUIRES_ACTION"] = "server.conversation.chat.requires_action";
|
273
|
+
/**
|
274
|
+
* en: Conversation chat failed
|
275
|
+
* zh: 对话失败
|
276
|
+
*/ EventNames["CONVERSATION_CHAT_FAILED"] = "server.conversation.chat.failed";
|
277
|
+
/**
|
278
|
+
* en: Session pre answer updated
|
279
|
+
* zh: 安抚配置更新成功
|
280
|
+
*/ EventNames["SESSION_PRE_ANSWER_UPDATED"] = "server.session.pre_answer.updated";
|
281
|
+
/**
|
282
|
+
* en: Conversation audio transcript delta
|
283
|
+
* zh: 用户语音识别字幕
|
284
|
+
*/ EventNames["CONVERSATION_AUDIO_TRANSCRIPT_DELTA"] = "server.conversation.audio_transcript.delta";
|
285
|
+
/**
|
286
|
+
* en: Mode updated
|
287
|
+
* zh: 更新房间模式成功
|
288
|
+
*/ EventNames["MODE_UPDATED"] = "server.mode.updated";
|
231
289
|
return EventNames;
|
232
290
|
}(event_names_EventNames || {});
|
233
291
|
/* ESM default export */ const event_names = event_names_EventNames;
|
@@ -315,6 +373,7 @@ class EngineClient extends RealtimeEventHandler {
|
|
315
373
|
this.engine.on(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onUserLeave, this.handleUserLeave);
|
316
374
|
this.engine.on(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onError, this.handleEventError);
|
317
375
|
this.engine.on(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onNetworkQuality, this.handleNetworkQuality);
|
376
|
+
this.engine.on(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onTrackEnded, this.handleTrackEnded);
|
318
377
|
if (this._isSupportVideo) this.engine.on(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onPlayerEvent, this.handlePlayerEvent);
|
319
378
|
if (this._debug) {
|
320
379
|
this.engine.on(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onLocalAudioPropertiesReport, this.handleLocalAudioPropertiesReport);
|
@@ -327,6 +386,7 @@ class EngineClient extends RealtimeEventHandler {
|
|
327
386
|
this.engine.off(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onUserLeave, this.handleUserLeave);
|
328
387
|
this.engine.off(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onError, this.handleEventError);
|
329
388
|
this.engine.off(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onNetworkQuality, this.handleNetworkQuality);
|
389
|
+
this.engine.off(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onTrackEnded, this.handleTrackEnded);
|
330
390
|
if (this._isSupportVideo) this.engine.off(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onPlayerEvent, this.handlePlayerEvent);
|
331
391
|
if (this._debug) {
|
332
392
|
this.engine.off(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onLocalAudioPropertiesReport, this.handleLocalAudioPropertiesReport);
|
@@ -377,6 +437,10 @@ class EngineClient extends RealtimeEventHandler {
|
|
377
437
|
downlinkNetworkQuality
|
378
438
|
});
|
379
439
|
}
|
440
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
441
|
+
handleTrackEnded(event) {
|
442
|
+
if ((null == event ? void 0 : event.kind) === 'video') this.dispatch(event_names.VIDEO_OFF, event);
|
443
|
+
}
|
380
444
|
async joinRoom(options) {
|
381
445
|
const { token, roomId, uid, audioMutedDefault, videoOnDefault, isAutoSubscribeAudio } = options;
|
382
446
|
try {
|
@@ -410,7 +474,11 @@ class EngineClient extends RealtimeEventHandler {
|
|
410
474
|
const devices = await getAudioDevices({
|
411
475
|
video: true
|
412
476
|
});
|
413
|
-
if (-1 === devices.videoInputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Video input device not found: ${deviceId}`);
|
477
|
+
if (!isMobileVideoDevice(deviceId) && -1 === devices.videoInputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Video input device not found: ${deviceId}`);
|
478
|
+
this.engine.setLocalVideoPlayer(isScreenShareDevice(deviceId) ? __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_SCREEN : __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN, {
|
479
|
+
renderDom: (null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.renderDom) || 'local-player',
|
480
|
+
userId: this._roomUserId
|
481
|
+
});
|
414
482
|
await this.changeVideoState(false);
|
415
483
|
if (isScreenShareDevice(deviceId)) {
|
416
484
|
if (this._streamIndex === __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN) this.engine.setLocalVideoPlayer(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN);
|
@@ -426,10 +494,6 @@ class EngineClient extends RealtimeEventHandler {
|
|
426
494
|
if (isAutoCapture) await this.engine.startVideoCapture(deviceId);
|
427
495
|
this._streamIndex = __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN;
|
428
496
|
}
|
429
|
-
this.engine.setLocalVideoPlayer(this._streamIndex, {
|
430
|
-
renderDom: (null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.renderDom) || 'local-player',
|
431
|
-
userId: this._roomUserId
|
432
|
-
});
|
433
497
|
}
|
434
498
|
async createLocalStream(userId, videoConfig) {
|
435
499
|
this._roomUserId = userId;
|
@@ -439,7 +503,12 @@ class EngineClient extends RealtimeEventHandler {
|
|
439
503
|
if (!devices.audioInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get audio devices');
|
440
504
|
if (this._isSupportVideo && !devices.videoInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get video devices');
|
441
505
|
await this.engine.startAudioCapture(devices.audioInputs[0].deviceId);
|
442
|
-
if (this._isSupportVideo)
|
506
|
+
if (this._isSupportVideo) try {
|
507
|
+
await this.setVideoInputDevice((null == videoConfig ? void 0 : videoConfig.videoInputDeviceId) || devices.videoInputs[0].deviceId, null == videoConfig ? void 0 : videoConfig.videoOnDefault);
|
508
|
+
this.dispatch((null == videoConfig ? void 0 : videoConfig.videoOnDefault) ? event_names.VIDEO_ON : event_names.VIDEO_OFF, {});
|
509
|
+
} catch (e) {
|
510
|
+
this.dispatch(event_names.VIDEO_ERROR, e);
|
511
|
+
}
|
443
512
|
}
|
444
513
|
async disconnect() {
|
445
514
|
try {
|
@@ -462,23 +531,18 @@ class EngineClient extends RealtimeEventHandler {
|
|
462
531
|
}
|
463
532
|
}
|
464
533
|
async changeVideoState(isVideoOn) {
|
465
|
-
|
466
|
-
if (
|
467
|
-
if (this._streamIndex === __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN) await this.engine.startVideoCapture();
|
468
|
-
else {
|
469
|
-
var _this__videoConfig;
|
470
|
-
this.engine.setVideoSourceType(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_SCREEN, __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
|
471
|
-
await this.engine.startScreenCapture(null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.screenConfig);
|
472
|
-
await this.engine.publishScreen(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.MediaType.VIDEO);
|
473
|
-
}
|
474
|
-
} else if (this._streamIndex === __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN) await this.engine.stopVideoCapture();
|
534
|
+
if (isVideoOn) {
|
535
|
+
if (this._streamIndex === __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN) await this.engine.startVideoCapture();
|
475
536
|
else {
|
476
|
-
|
477
|
-
|
537
|
+
var _this__videoConfig;
|
538
|
+
this.engine.setVideoSourceType(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_SCREEN, __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
|
539
|
+
await this.engine.startScreenCapture(null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.screenConfig);
|
540
|
+
await this.engine.publishScreen(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.MediaType.VIDEO);
|
478
541
|
}
|
479
|
-
}
|
480
|
-
|
481
|
-
|
542
|
+
} else if (this._streamIndex === __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN) await this.engine.stopVideoCapture();
|
543
|
+
else {
|
544
|
+
await this.engine.stopScreenCapture();
|
545
|
+
await this.engine.unpublishScreen(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.MediaType.VIDEO);
|
482
546
|
}
|
483
547
|
}
|
484
548
|
async stop() {
|
@@ -568,6 +632,7 @@ class EngineClient extends RealtimeEventHandler {
|
|
568
632
|
this.handleEventError = this.handleEventError.bind(this);
|
569
633
|
this.handlePlayerEvent = this.handlePlayerEvent.bind(this);
|
570
634
|
this.handleNetworkQuality = this.handleNetworkQuality.bind(this);
|
635
|
+
this.handleTrackEnded = this.handleTrackEnded.bind(this);
|
571
636
|
// Debug only
|
572
637
|
this.handleLocalAudioPropertiesReport = this.handleLocalAudioPropertiesReport.bind(this);
|
573
638
|
this.handleRemoteAudioPropertiesReport = this.handleRemoteAudioPropertiesReport.bind(this);
|
@@ -591,16 +656,17 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
591
656
|
// Step1 get token
|
592
657
|
if (getRoomInfo) roomInfo = await getRoomInfo();
|
593
658
|
else {
|
594
|
-
|
595
|
-
if (this._config.
|
596
|
-
|
659
|
+
const config = {};
|
660
|
+
if (this._config.prologueContent) config.prologue_content = this._config.prologueContent;
|
661
|
+
if (void 0 !== this._config.roomMode && null !== this._config.roomMode) config.room_mode = this._config.roomMode;
|
662
|
+
if (this._config.videoConfig) {
|
663
|
+
if (isScreenShareDevice(this._config.videoConfig.videoInputDeviceId)) config.video_config = {
|
597
664
|
stream_video_type: 'screen'
|
598
|
-
}
|
599
|
-
|
600
|
-
video_config: {
|
665
|
+
};
|
666
|
+
else config.video_config = {
|
601
667
|
stream_video_type: 'main'
|
602
|
-
}
|
603
|
-
}
|
668
|
+
};
|
669
|
+
}
|
604
670
|
roomInfo = await this._api.audio.rooms.create({
|
605
671
|
bot_id: botId,
|
606
672
|
conversation_id: conversationId || void 0,
|
@@ -615,6 +681,12 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
615
681
|
this.dispatch(event_names.ERROR, error);
|
616
682
|
throw new RealtimeAPIError(error_RealtimeError.CREATE_ROOM_ERROR, error instanceof Error ? error.message : 'Unknown error', error);
|
617
683
|
}
|
684
|
+
this.dispatch(event_names.ROOM_INFO, {
|
685
|
+
roomId: roomInfo.room_id,
|
686
|
+
uid: roomInfo.uid,
|
687
|
+
token: roomInfo.token,
|
688
|
+
appId: roomInfo.app_id
|
689
|
+
});
|
618
690
|
this._isTestEnv = TEST_APP_ID === roomInfo.app_id;
|
619
691
|
// Step2 create engine
|
620
692
|
this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo, this._config.videoConfig);
|
@@ -696,10 +768,14 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
696
768
|
else this.dispatch(event_names.AUDIO_MUTED, {});
|
697
769
|
}
|
698
770
|
async setVideoEnable(isEnable) {
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
771
|
+
try {
|
772
|
+
var _this__client;
|
773
|
+
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.changeVideoState(isEnable));
|
774
|
+
this.dispatch(isEnable ? event_names.VIDEO_ON : event_names.VIDEO_OFF, {});
|
775
|
+
} catch (e) {
|
776
|
+
this.dispatch(event_names.VIDEO_ERROR, e);
|
777
|
+
throw e;
|
778
|
+
}
|
703
779
|
}
|
704
780
|
/**
|
705
781
|
* en: Enable audio properties reporting (debug mode only)
|
@@ -756,9 +832,19 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
756
832
|
deviceId
|
757
833
|
});
|
758
834
|
}
|
759
|
-
|
760
|
-
|
761
|
-
|
835
|
+
/**
|
836
|
+
* en: Set the video input device
|
837
|
+
*
|
838
|
+
* zh: 设置视频输入设备
|
839
|
+
*/ async setVideoInputDevice(deviceId) {
|
840
|
+
try {
|
841
|
+
var _this__client;
|
842
|
+
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setVideoInputDevice(deviceId));
|
843
|
+
this.dispatch(event_names.VIDEO_ON, {});
|
844
|
+
} catch (e) {
|
845
|
+
this.dispatch(event_names.VIDEO_ERROR, e);
|
846
|
+
throw e;
|
847
|
+
}
|
762
848
|
this.dispatch(event_names.VIDEO_INPUT_DEVICE_CHANGED, {
|
763
849
|
deviceId
|
764
850
|
});
|
@@ -813,6 +899,8 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
813
899
|
* 可选,视频输入设备的设备 ID。
|
814
900
|
* @param config.videoConfig.screenConfig - Optional, Screen share configuration if videoInputDeviceId is 'screenShare' see https://www.volcengine.com/docs/6348/104481#screenconfig for more details. |
|
815
901
|
* 可选,屏幕共享配置,如果 videoInputDeviceId 是 'screenShare',请参考 https://www.volcengine.com/docs/6348/104481#screenconfig 了解更多详情。
|
902
|
+
* @param config.prologueContent - Optional, Prologue content. | 可选,开场白内容。
|
903
|
+
* @param config.roomMode - Optional, Room mode. | 可选,房间模式。
|
816
904
|
*/ constructor(config){
|
817
905
|
super(config.debug), this._client = null, this.isConnected = false, this._isTestEnv = false, this._isSupportVideo = false;
|
818
906
|
this._config = config;
|
package/dist/types/client.d.ts
CHANGED
@@ -19,6 +19,7 @@ export declare class EngineClient extends RealtimeEventHandler {
|
|
19
19
|
handleUserLeave(event: onUserLeaveEvent): void;
|
20
20
|
handlePlayerEvent(event: unknown): void;
|
21
21
|
handleNetworkQuality(uplinkNetworkQuality: NetworkQuality, downlinkNetworkQuality: NetworkQuality): void;
|
22
|
+
handleTrackEnded(event: any): void;
|
22
23
|
joinRoom(options: {
|
23
24
|
token: string;
|
24
25
|
roomId: string;
|
@@ -19,6 +19,7 @@ export declare class EngineClient extends RealtimeEventHandler {
|
|
19
19
|
handleUserLeave(event: onUserLeaveEvent): void;
|
20
20
|
handlePlayerEvent(event: unknown): void;
|
21
21
|
handleNetworkQuality(uplinkNetworkQuality: NetworkQuality, downlinkNetworkQuality: NetworkQuality): void;
|
22
|
+
handleTrackEnded(event: any): void;
|
22
23
|
joinRoom(options: {
|
23
24
|
token: string;
|
24
25
|
roomId: string;
|
@@ -14,6 +14,11 @@ declare enum EventNames {
|
|
14
14
|
* zh: 所有服务端事件
|
15
15
|
*/
|
16
16
|
ALL_SERVER = "server.*",
|
17
|
+
/**
|
18
|
+
* en: Room info
|
19
|
+
* zh: 房间信息
|
20
|
+
*/
|
21
|
+
ROOM_INFO = "client.room.info",
|
17
22
|
/**
|
18
23
|
* en: Client connected
|
19
24
|
* zh: 客户端连接
|
@@ -54,6 +59,11 @@ declare enum EventNames {
|
|
54
59
|
* zh: 客户端视频关闭
|
55
60
|
*/
|
56
61
|
VIDEO_OFF = "client.video.off",
|
62
|
+
/**
|
63
|
+
* en: Client video error
|
64
|
+
* zh: 客户端视频(或屏幕共享)错误
|
65
|
+
*/
|
66
|
+
VIDEO_ERROR = "client.video.error",
|
57
67
|
/**
|
58
68
|
* en: Client video event
|
59
69
|
* zh: 客户端视频事件
|
@@ -138,6 +148,61 @@ declare enum EventNames {
|
|
138
148
|
* en: Session updated
|
139
149
|
* zh: 会话更新
|
140
150
|
*/
|
141
|
-
|
151
|
+
SESSION_UPDATED = "server.session.updated",
|
152
|
+
/**
|
153
|
+
* en: Conversation created
|
154
|
+
* zh: 会话创建
|
155
|
+
*/
|
156
|
+
CONVERSATION_CREATED = "server.conversation.created",
|
157
|
+
/**
|
158
|
+
* en: Conversation chat created
|
159
|
+
* zh: 会话对话创建
|
160
|
+
*/
|
161
|
+
CONVERSATION_CHAT_CREATED = "server.conversation.chat.created",
|
162
|
+
/**
|
163
|
+
* en: Conversation chat in progress
|
164
|
+
* zh: 对话正在处理中
|
165
|
+
*/
|
166
|
+
CONVERSATION_CHAT_IN_PROGRESS = "server.conversation.chat.in_progress",
|
167
|
+
/**
|
168
|
+
* en: Conversation message delta received
|
169
|
+
* zh: 文本消息增量返回
|
170
|
+
*/
|
171
|
+
CONVERSATION_MESSAGE_DELTA = "server.conversation.message.delta",
|
172
|
+
/**
|
173
|
+
* en: Conversation message completed
|
174
|
+
* zh: 文本消息完成
|
175
|
+
*/
|
176
|
+
CONVERSATION_MESSAGE_COMPLETED = "server.conversation.message.completed",
|
177
|
+
/**
|
178
|
+
* en: Conversation chat completed
|
179
|
+
* zh: 对话完成
|
180
|
+
*/
|
181
|
+
CONVERSATION_CHAT_COMPLETED = "server.conversation.chat.completed",
|
182
|
+
/**
|
183
|
+
* en: Conversation chat requires action
|
184
|
+
* zh: 对话需要插件
|
185
|
+
*/
|
186
|
+
CONVERSATION_CHAT_REQUIRES_ACTION = "server.conversation.chat.requires_action",
|
187
|
+
/**
|
188
|
+
* en: Conversation chat failed
|
189
|
+
* zh: 对话失败
|
190
|
+
*/
|
191
|
+
CONVERSATION_CHAT_FAILED = "server.conversation.chat.failed",
|
192
|
+
/**
|
193
|
+
* en: Session pre answer updated
|
194
|
+
* zh: 安抚配置更新成功
|
195
|
+
*/
|
196
|
+
SESSION_PRE_ANSWER_UPDATED = "server.session.pre_answer.updated",
|
197
|
+
/**
|
198
|
+
* en: Conversation audio transcript delta
|
199
|
+
* zh: 用户语音识别字幕
|
200
|
+
*/
|
201
|
+
CONVERSATION_AUDIO_TRANSCRIPT_DELTA = "server.conversation.audio_transcript.delta",
|
202
|
+
/**
|
203
|
+
* en: Mode updated
|
204
|
+
* zh: 更新房间模式成功
|
205
|
+
*/
|
206
|
+
MODE_UPDATED = "server.mode.updated"
|
142
207
|
}
|
143
208
|
export default EventNames;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { type ScreenConfig, type AudioPropertiesConfig, type IRTCEngine } from '@volcengine/rtc';
|
2
|
-
import { type CreateRoomData, type GetToken } from '@coze/api';
|
2
|
+
import { type CreateRoomData, type GetToken, type RoomMode } from '@coze/api';
|
3
3
|
import * as RealtimeUtils from './utils';
|
4
4
|
import EventNames from './event-names';
|
5
5
|
import { RealtimeEventHandler } from './event-handler';
|
@@ -30,6 +30,8 @@ export interface RealtimeClientConfig {
|
|
30
30
|
suppressNonStationaryNoise?: boolean /** optional, Suppress non-stationary noise, defaults to false */;
|
31
31
|
videoConfig?: VideoConfig /** optional, Video configuration */;
|
32
32
|
isAutoSubscribeAudio?: boolean /** optional, Whether to automatically subscribe to bot reply audio streams, defaults to true */;
|
33
|
+
prologueContent?: string /** optional, Prologue content */;
|
34
|
+
roomMode?: RoomMode /** optional, Room mode */;
|
33
35
|
}
|
34
36
|
declare class RealtimeClient extends RealtimeEventHandler {
|
35
37
|
_config: RealtimeClientConfig;
|
@@ -80,6 +82,8 @@ declare class RealtimeClient extends RealtimeEventHandler {
|
|
80
82
|
* 可选,视频输入设备的设备 ID。
|
81
83
|
* @param config.videoConfig.screenConfig - Optional, Screen share configuration if videoInputDeviceId is 'screenShare' see https://www.volcengine.com/docs/6348/104481#screenconfig for more details. |
|
82
84
|
* 可选,屏幕共享配置,如果 videoInputDeviceId 是 'screenShare',请参考 https://www.volcengine.com/docs/6348/104481#screenconfig 了解更多详情。
|
85
|
+
* @param config.prologueContent - Optional, Prologue content. | 可选,开场白内容。
|
86
|
+
* @param config.roomMode - Optional, Room mode. | 可选,房间模式。
|
83
87
|
*/
|
84
88
|
constructor(config: RealtimeClientConfig);
|
85
89
|
/**
|
@@ -143,7 +147,12 @@ declare class RealtimeClient extends RealtimeEventHandler {
|
|
143
147
|
* zh: 设置音频输出设备
|
144
148
|
*/
|
145
149
|
setAudioOutputDevice(deviceId: string): Promise<void>;
|
146
|
-
|
150
|
+
/**
|
151
|
+
* en: Set the video input device
|
152
|
+
*
|
153
|
+
* zh: 设置视频输入设备
|
154
|
+
*/
|
155
|
+
setVideoInputDevice(deviceId: string | 'screenShare' | 'user' | 'environment'): Promise<void>;
|
147
156
|
/**
|
148
157
|
* en: Get the RTC engine instance, for detail visit https://www.volcengine.com/docs/6348/104481
|
149
158
|
*
|
@@ -36,6 +36,12 @@ export declare const getAudioDevices: ({ video, }?: {
|
|
36
36
|
videoInputs: MediaDeviceInfo[];
|
37
37
|
}>;
|
38
38
|
export declare const isScreenShareDevice: (deviceId?: string) => boolean;
|
39
|
+
/**
|
40
|
+
* 判断是否前后置摄像头
|
41
|
+
* @param deviceId
|
42
|
+
* @returns
|
43
|
+
*/
|
44
|
+
export declare const isMobileVideoDevice: (deviceId?: string) => boolean;
|
39
45
|
/**
|
40
46
|
* Check if browser supports screen sharing
|
41
47
|
* 检查浏览器是否支持屏幕共享
|
@@ -14,6 +14,11 @@ declare enum EventNames {
|
|
14
14
|
* zh: 所有服务端事件
|
15
15
|
*/
|
16
16
|
ALL_SERVER = "server.*",
|
17
|
+
/**
|
18
|
+
* en: Room info
|
19
|
+
* zh: 房间信息
|
20
|
+
*/
|
21
|
+
ROOM_INFO = "client.room.info",
|
17
22
|
/**
|
18
23
|
* en: Client connected
|
19
24
|
* zh: 客户端连接
|
@@ -54,6 +59,11 @@ declare enum EventNames {
|
|
54
59
|
* zh: 客户端视频关闭
|
55
60
|
*/
|
56
61
|
VIDEO_OFF = "client.video.off",
|
62
|
+
/**
|
63
|
+
* en: Client video error
|
64
|
+
* zh: 客户端视频(或屏幕共享)错误
|
65
|
+
*/
|
66
|
+
VIDEO_ERROR = "client.video.error",
|
57
67
|
/**
|
58
68
|
* en: Client video event
|
59
69
|
* zh: 客户端视频事件
|
@@ -138,6 +148,61 @@ declare enum EventNames {
|
|
138
148
|
* en: Session updated
|
139
149
|
* zh: 会话更新
|
140
150
|
*/
|
141
|
-
|
151
|
+
SESSION_UPDATED = "server.session.updated",
|
152
|
+
/**
|
153
|
+
* en: Conversation created
|
154
|
+
* zh: 会话创建
|
155
|
+
*/
|
156
|
+
CONVERSATION_CREATED = "server.conversation.created",
|
157
|
+
/**
|
158
|
+
* en: Conversation chat created
|
159
|
+
* zh: 会话对话创建
|
160
|
+
*/
|
161
|
+
CONVERSATION_CHAT_CREATED = "server.conversation.chat.created",
|
162
|
+
/**
|
163
|
+
* en: Conversation chat in progress
|
164
|
+
* zh: 对话正在处理中
|
165
|
+
*/
|
166
|
+
CONVERSATION_CHAT_IN_PROGRESS = "server.conversation.chat.in_progress",
|
167
|
+
/**
|
168
|
+
* en: Conversation message delta received
|
169
|
+
* zh: 文本消息增量返回
|
170
|
+
*/
|
171
|
+
CONVERSATION_MESSAGE_DELTA = "server.conversation.message.delta",
|
172
|
+
/**
|
173
|
+
* en: Conversation message completed
|
174
|
+
* zh: 文本消息完成
|
175
|
+
*/
|
176
|
+
CONVERSATION_MESSAGE_COMPLETED = "server.conversation.message.completed",
|
177
|
+
/**
|
178
|
+
* en: Conversation chat completed
|
179
|
+
* zh: 对话完成
|
180
|
+
*/
|
181
|
+
CONVERSATION_CHAT_COMPLETED = "server.conversation.chat.completed",
|
182
|
+
/**
|
183
|
+
* en: Conversation chat requires action
|
184
|
+
* zh: 对话需要插件
|
185
|
+
*/
|
186
|
+
CONVERSATION_CHAT_REQUIRES_ACTION = "server.conversation.chat.requires_action",
|
187
|
+
/**
|
188
|
+
* en: Conversation chat failed
|
189
|
+
* zh: 对话失败
|
190
|
+
*/
|
191
|
+
CONVERSATION_CHAT_FAILED = "server.conversation.chat.failed",
|
192
|
+
/**
|
193
|
+
* en: Session pre answer updated
|
194
|
+
* zh: 安抚配置更新成功
|
195
|
+
*/
|
196
|
+
SESSION_PRE_ANSWER_UPDATED = "server.session.pre_answer.updated",
|
197
|
+
/**
|
198
|
+
* en: Conversation audio transcript delta
|
199
|
+
* zh: 用户语音识别字幕
|
200
|
+
*/
|
201
|
+
CONVERSATION_AUDIO_TRANSCRIPT_DELTA = "server.conversation.audio_transcript.delta",
|
202
|
+
/**
|
203
|
+
* en: Mode updated
|
204
|
+
* zh: 更新房间模式成功
|
205
|
+
*/
|
206
|
+
MODE_UPDATED = "server.mode.updated"
|
142
207
|
}
|
143
208
|
export default EventNames;
|
package/dist/types/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { type ScreenConfig, type AudioPropertiesConfig, type IRTCEngine } from '@volcengine/rtc';
|
2
|
-
import { type CreateRoomData, type GetToken } from '@coze/api';
|
2
|
+
import { type CreateRoomData, type GetToken, type RoomMode } from '@coze/api';
|
3
3
|
import * as RealtimeUtils from './utils';
|
4
4
|
import EventNames from './event-names';
|
5
5
|
import { RealtimeEventHandler } from './event-handler';
|
@@ -30,6 +30,8 @@ export interface RealtimeClientConfig {
|
|
30
30
|
suppressNonStationaryNoise?: boolean /** optional, Suppress non-stationary noise, defaults to false */;
|
31
31
|
videoConfig?: VideoConfig /** optional, Video configuration */;
|
32
32
|
isAutoSubscribeAudio?: boolean /** optional, Whether to automatically subscribe to bot reply audio streams, defaults to true */;
|
33
|
+
prologueContent?: string /** optional, Prologue content */;
|
34
|
+
roomMode?: RoomMode /** optional, Room mode */;
|
33
35
|
}
|
34
36
|
declare class RealtimeClient extends RealtimeEventHandler {
|
35
37
|
_config: RealtimeClientConfig;
|
@@ -80,6 +82,8 @@ declare class RealtimeClient extends RealtimeEventHandler {
|
|
80
82
|
* 可选,视频输入设备的设备 ID。
|
81
83
|
* @param config.videoConfig.screenConfig - Optional, Screen share configuration if videoInputDeviceId is 'screenShare' see https://www.volcengine.com/docs/6348/104481#screenconfig for more details. |
|
82
84
|
* 可选,屏幕共享配置,如果 videoInputDeviceId 是 'screenShare',请参考 https://www.volcengine.com/docs/6348/104481#screenconfig 了解更多详情。
|
85
|
+
* @param config.prologueContent - Optional, Prologue content. | 可选,开场白内容。
|
86
|
+
* @param config.roomMode - Optional, Room mode. | 可选,房间模式。
|
83
87
|
*/
|
84
88
|
constructor(config: RealtimeClientConfig);
|
85
89
|
/**
|
@@ -143,7 +147,12 @@ declare class RealtimeClient extends RealtimeEventHandler {
|
|
143
147
|
* zh: 设置音频输出设备
|
144
148
|
*/
|
145
149
|
setAudioOutputDevice(deviceId: string): Promise<void>;
|
146
|
-
|
150
|
+
/**
|
151
|
+
* en: Set the video input device
|
152
|
+
*
|
153
|
+
* zh: 设置视频输入设备
|
154
|
+
*/
|
155
|
+
setVideoInputDevice(deviceId: string | 'screenShare' | 'user' | 'environment'): Promise<void>;
|
147
156
|
/**
|
148
157
|
* en: Get the RTC engine instance, for detail visit https://www.volcengine.com/docs/6348/104481
|
149
158
|
*
|
package/dist/types/utils.d.ts
CHANGED
@@ -36,6 +36,12 @@ export declare const getAudioDevices: ({ video, }?: {
|
|
36
36
|
videoInputs: MediaDeviceInfo[];
|
37
37
|
}>;
|
38
38
|
export declare const isScreenShareDevice: (deviceId?: string) => boolean;
|
39
|
+
/**
|
40
|
+
* 判断是否前后置摄像头
|
41
|
+
* @param deviceId
|
42
|
+
* @returns
|
43
|
+
*/
|
44
|
+
export declare const isMobileVideoDevice: (deviceId?: string) => boolean;
|
39
45
|
/**
|
40
46
|
* Check if browser supports screen sharing
|
41
47
|
* 检查浏览器是否支持屏幕共享
|