@coze/realtime-api 1.2.0 → 1.2.1-beta.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/dist/cjs/index.js +21 -10
- package/dist/esm/index.js +21 -10
- package/dist/types/event-names/index.d.ts +8 -1
- package/dist/types/event-names/utils.d.ts +6 -0
- package/dist/types/index.d.ts +8 -1
- package/dist/types/utils.d.ts +6 -0
- package/dist/umd/index.js +21 -10
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
@@ -61,6 +61,7 @@ __webpack_require__.d(utils_namespaceObject, {
|
|
61
61
|
checkDevicePermission: ()=>checkDevicePermission,
|
62
62
|
checkPermission: ()=>checkPermission,
|
63
63
|
getAudioDevices: ()=>getAudioDevices,
|
64
|
+
isMobileVideoDevice: ()=>isMobileVideoDevice,
|
64
65
|
isScreenShareDevice: ()=>isScreenShareDevice,
|
65
66
|
isScreenShareSupported: ()=>isScreenShareSupported,
|
66
67
|
sleep: ()=>sleep
|
@@ -135,6 +136,11 @@ var rtc_default = /*#__PURE__*/ __webpack_require__.n(rtc_namespaceObject);
|
|
135
136
|
};
|
136
137
|
};
|
137
138
|
const isScreenShareDevice = (deviceId)=>'screenShare' === deviceId;
|
139
|
+
/**
|
140
|
+
* 判断是否前后置摄像头
|
141
|
+
* @param deviceId
|
142
|
+
* @returns
|
143
|
+
*/ const isMobileVideoDevice = (deviceId)=>'user' === deviceId || 'environment' === deviceId;
|
138
144
|
/**
|
139
145
|
* Check if browser supports screen sharing
|
140
146
|
* 检查浏览器是否支持屏幕共享
|
@@ -439,7 +445,7 @@ class EngineClient extends RealtimeEventHandler {
|
|
439
445
|
const devices = await getAudioDevices({
|
440
446
|
video: true
|
441
447
|
});
|
442
|
-
if (-1 === devices.videoInputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Video input device not found: ${deviceId}`);
|
448
|
+
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}`);
|
443
449
|
await this.changeVideoState(false);
|
444
450
|
if (isScreenShareDevice(deviceId)) {
|
445
451
|
if (this._streamIndex === rtc_namespaceObject.StreamIndex.STREAM_INDEX_MAIN) this.engine.setLocalVideoPlayer(rtc_namespaceObject.StreamIndex.STREAM_INDEX_MAIN);
|
@@ -620,16 +626,16 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
620
626
|
// Step1 get token
|
621
627
|
if (getRoomInfo) roomInfo = await getRoomInfo();
|
622
628
|
else {
|
623
|
-
|
624
|
-
if (this._config.
|
625
|
-
|
629
|
+
const config = {};
|
630
|
+
if (this._config.prologueContent) config.prologue_content = this._config.prologueContent;
|
631
|
+
if (this._config.videoConfig) {
|
632
|
+
if (isScreenShareDevice(this._config.videoConfig.videoInputDeviceId)) config.video_config = {
|
626
633
|
stream_video_type: 'screen'
|
627
|
-
}
|
628
|
-
|
629
|
-
video_config: {
|
634
|
+
};
|
635
|
+
else config.video_config = {
|
630
636
|
stream_video_type: 'main'
|
631
|
-
}
|
632
|
-
}
|
637
|
+
};
|
638
|
+
}
|
633
639
|
roomInfo = await this._api.audio.rooms.create({
|
634
640
|
bot_id: botId,
|
635
641
|
conversation_id: conversationId || void 0,
|
@@ -785,7 +791,11 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
785
791
|
deviceId
|
786
792
|
});
|
787
793
|
}
|
788
|
-
|
794
|
+
/**
|
795
|
+
* en: Set the video input device
|
796
|
+
*
|
797
|
+
* zh: 设置视频输入设备
|
798
|
+
*/ async setVideoInputDevice(deviceId) {
|
789
799
|
var _this__client;
|
790
800
|
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setVideoInputDevice(deviceId));
|
791
801
|
this.dispatch(event_names.VIDEO_INPUT_DEVICE_CHANGED, {
|
@@ -842,6 +852,7 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
842
852
|
* 可选,视频输入设备的设备 ID。
|
843
853
|
* @param config.videoConfig.screenConfig - Optional, Screen share configuration if videoInputDeviceId is 'screenShare' see https://www.volcengine.com/docs/6348/104481#screenconfig for more details. |
|
844
854
|
* 可选,屏幕共享配置,如果 videoInputDeviceId 是 'screenShare',请参考 https://www.volcengine.com/docs/6348/104481#screenconfig 了解更多详情。
|
855
|
+
* @param config.prologueContent - Optional, Prologue content. | 可选,开场白内容。
|
845
856
|
*/ constructor(config){
|
846
857
|
super(config.debug), this._client = null, this.isConnected = false, this._isTestEnv = false, this._isSupportVideo = false;
|
847
858
|
this._config = config;
|
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
|
* 检查浏览器是否支持屏幕共享
|
@@ -410,7 +416,7 @@ class EngineClient extends RealtimeEventHandler {
|
|
410
416
|
const devices = await getAudioDevices({
|
411
417
|
video: true
|
412
418
|
});
|
413
|
-
if (-1 === devices.videoInputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Video input device not found: ${deviceId}`);
|
419
|
+
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}`);
|
414
420
|
await this.changeVideoState(false);
|
415
421
|
if (isScreenShareDevice(deviceId)) {
|
416
422
|
if (this._streamIndex === __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN) this.engine.setLocalVideoPlayer(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN);
|
@@ -591,16 +597,16 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
591
597
|
// Step1 get token
|
592
598
|
if (getRoomInfo) roomInfo = await getRoomInfo();
|
593
599
|
else {
|
594
|
-
|
595
|
-
if (this._config.
|
596
|
-
|
600
|
+
const config = {};
|
601
|
+
if (this._config.prologueContent) config.prologue_content = this._config.prologueContent;
|
602
|
+
if (this._config.videoConfig) {
|
603
|
+
if (isScreenShareDevice(this._config.videoConfig.videoInputDeviceId)) config.video_config = {
|
597
604
|
stream_video_type: 'screen'
|
598
|
-
}
|
599
|
-
|
600
|
-
video_config: {
|
605
|
+
};
|
606
|
+
else config.video_config = {
|
601
607
|
stream_video_type: 'main'
|
602
|
-
}
|
603
|
-
}
|
608
|
+
};
|
609
|
+
}
|
604
610
|
roomInfo = await this._api.audio.rooms.create({
|
605
611
|
bot_id: botId,
|
606
612
|
conversation_id: conversationId || void 0,
|
@@ -756,7 +762,11 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
756
762
|
deviceId
|
757
763
|
});
|
758
764
|
}
|
759
|
-
|
765
|
+
/**
|
766
|
+
* en: Set the video input device
|
767
|
+
*
|
768
|
+
* zh: 设置视频输入设备
|
769
|
+
*/ async setVideoInputDevice(deviceId) {
|
760
770
|
var _this__client;
|
761
771
|
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setVideoInputDevice(deviceId));
|
762
772
|
this.dispatch(event_names.VIDEO_INPUT_DEVICE_CHANGED, {
|
@@ -813,6 +823,7 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
813
823
|
* 可选,视频输入设备的设备 ID。
|
814
824
|
* @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
825
|
* 可选,屏幕共享配置,如果 videoInputDeviceId 是 'screenShare',请参考 https://www.volcengine.com/docs/6348/104481#screenconfig 了解更多详情。
|
826
|
+
* @param config.prologueContent - Optional, Prologue content. | 可选,开场白内容。
|
816
827
|
*/ constructor(config){
|
817
828
|
super(config.debug), this._client = null, this.isConnected = false, this._isTestEnv = false, this._isSupportVideo = false;
|
818
829
|
this._config = config;
|
@@ -30,6 +30,7 @@ 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 */;
|
33
34
|
}
|
34
35
|
declare class RealtimeClient extends RealtimeEventHandler {
|
35
36
|
_config: RealtimeClientConfig;
|
@@ -80,6 +81,7 @@ declare class RealtimeClient extends RealtimeEventHandler {
|
|
80
81
|
* 可选,视频输入设备的设备 ID。
|
81
82
|
* @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
83
|
* 可选,屏幕共享配置,如果 videoInputDeviceId 是 'screenShare',请参考 https://www.volcengine.com/docs/6348/104481#screenconfig 了解更多详情。
|
84
|
+
* @param config.prologueContent - Optional, Prologue content. | 可选,开场白内容。
|
83
85
|
*/
|
84
86
|
constructor(config: RealtimeClientConfig);
|
85
87
|
/**
|
@@ -143,7 +145,12 @@ declare class RealtimeClient extends RealtimeEventHandler {
|
|
143
145
|
* zh: 设置音频输出设备
|
144
146
|
*/
|
145
147
|
setAudioOutputDevice(deviceId: string): Promise<void>;
|
146
|
-
|
148
|
+
/**
|
149
|
+
* en: Set the video input device
|
150
|
+
*
|
151
|
+
* zh: 设置视频输入设备
|
152
|
+
*/
|
153
|
+
setVideoInputDevice(deviceId: string | 'screenShare' | 'user' | 'environment'): Promise<void>;
|
147
154
|
/**
|
148
155
|
* en: Get the RTC engine instance, for detail visit https://www.volcengine.com/docs/6348/104481
|
149
156
|
*
|
@@ -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
|
* 检查浏览器是否支持屏幕共享
|
package/dist/types/index.d.ts
CHANGED
@@ -30,6 +30,7 @@ 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 */;
|
33
34
|
}
|
34
35
|
declare class RealtimeClient extends RealtimeEventHandler {
|
35
36
|
_config: RealtimeClientConfig;
|
@@ -80,6 +81,7 @@ declare class RealtimeClient extends RealtimeEventHandler {
|
|
80
81
|
* 可选,视频输入设备的设备 ID。
|
81
82
|
* @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
83
|
* 可选,屏幕共享配置,如果 videoInputDeviceId 是 'screenShare',请参考 https://www.volcengine.com/docs/6348/104481#screenconfig 了解更多详情。
|
84
|
+
* @param config.prologueContent - Optional, Prologue content. | 可选,开场白内容。
|
83
85
|
*/
|
84
86
|
constructor(config: RealtimeClientConfig);
|
85
87
|
/**
|
@@ -143,7 +145,12 @@ declare class RealtimeClient extends RealtimeEventHandler {
|
|
143
145
|
* zh: 设置音频输出设备
|
144
146
|
*/
|
145
147
|
setAudioOutputDevice(deviceId: string): Promise<void>;
|
146
|
-
|
148
|
+
/**
|
149
|
+
* en: Set the video input device
|
150
|
+
*
|
151
|
+
* zh: 设置视频输入设备
|
152
|
+
*/
|
153
|
+
setVideoInputDevice(deviceId: string | 'screenShare' | 'user' | 'environment'): Promise<void>;
|
147
154
|
/**
|
148
155
|
* en: Get the RTC engine instance, for detail visit https://www.volcengine.com/docs/6348/104481
|
149
156
|
*
|
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
|
* 检查浏览器是否支持屏幕共享
|
package/dist/umd/index.js
CHANGED
@@ -96,6 +96,7 @@
|
|
96
96
|
checkDevicePermission: ()=>checkDevicePermission,
|
97
97
|
checkPermission: ()=>checkPermission,
|
98
98
|
getAudioDevices: ()=>getAudioDevices,
|
99
|
+
isMobileVideoDevice: ()=>isMobileVideoDevice,
|
99
100
|
isScreenShareDevice: ()=>isScreenShareDevice,
|
100
101
|
isScreenShareSupported: ()=>isScreenShareSupported,
|
101
102
|
sleep: ()=>sleep
|
@@ -173,6 +174,11 @@
|
|
173
174
|
};
|
174
175
|
const isScreenShareDevice = (deviceId)=>'screenShare' === deviceId;
|
175
176
|
/**
|
177
|
+
* 判断是否前后置摄像头
|
178
|
+
* @param deviceId
|
179
|
+
* @returns
|
180
|
+
*/ const isMobileVideoDevice = (deviceId)=>'user' === deviceId || 'environment' === deviceId;
|
181
|
+
/**
|
176
182
|
* Check if browser supports screen sharing
|
177
183
|
* 检查浏览器是否支持屏幕共享
|
178
184
|
*/ function isScreenShareSupported() {
|
@@ -477,7 +483,7 @@
|
|
477
483
|
const devices = await getAudioDevices({
|
478
484
|
video: true
|
479
485
|
});
|
480
|
-
if (-1 === devices.videoInputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Video input device not found: ${deviceId}`);
|
486
|
+
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}`);
|
481
487
|
await this.changeVideoState(false);
|
482
488
|
if (isScreenShareDevice(deviceId)) {
|
483
489
|
if (this._streamIndex === rtc_.StreamIndex.STREAM_INDEX_MAIN) this.engine.setLocalVideoPlayer(rtc_.StreamIndex.STREAM_INDEX_MAIN);
|
@@ -658,16 +664,16 @@
|
|
658
664
|
// Step1 get token
|
659
665
|
if (getRoomInfo) roomInfo = await getRoomInfo();
|
660
666
|
else {
|
661
|
-
|
662
|
-
if (this._config.
|
663
|
-
|
667
|
+
const config = {};
|
668
|
+
if (this._config.prologueContent) config.prologue_content = this._config.prologueContent;
|
669
|
+
if (this._config.videoConfig) {
|
670
|
+
if (isScreenShareDevice(this._config.videoConfig.videoInputDeviceId)) config.video_config = {
|
664
671
|
stream_video_type: 'screen'
|
665
|
-
}
|
666
|
-
|
667
|
-
video_config: {
|
672
|
+
};
|
673
|
+
else config.video_config = {
|
668
674
|
stream_video_type: 'main'
|
669
|
-
}
|
670
|
-
}
|
675
|
+
};
|
676
|
+
}
|
671
677
|
roomInfo = await this._api.audio.rooms.create({
|
672
678
|
bot_id: botId,
|
673
679
|
conversation_id: conversationId || void 0,
|
@@ -823,7 +829,11 @@
|
|
823
829
|
deviceId
|
824
830
|
});
|
825
831
|
}
|
826
|
-
|
832
|
+
/**
|
833
|
+
* en: Set the video input device
|
834
|
+
*
|
835
|
+
* zh: 设置视频输入设备
|
836
|
+
*/ async setVideoInputDevice(deviceId) {
|
827
837
|
var _this__client;
|
828
838
|
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setVideoInputDevice(deviceId));
|
829
839
|
this.dispatch(event_names.VIDEO_INPUT_DEVICE_CHANGED, {
|
@@ -880,6 +890,7 @@
|
|
880
890
|
* 可选,视频输入设备的设备 ID。
|
881
891
|
* @param config.videoConfig.screenConfig - Optional, Screen share configuration if videoInputDeviceId is 'screenShare' see https://www.volcengine.com/docs/6348/104481#screenconfig for more details. |
|
882
892
|
* 可选,屏幕共享配置,如果 videoInputDeviceId 是 'screenShare',请参考 https://www.volcengine.com/docs/6348/104481#screenconfig 了解更多详情。
|
893
|
+
* @param config.prologueContent - Optional, Prologue content. | 可选,开场白内容。
|
883
894
|
*/ constructor(config){
|
884
895
|
super(config.debug), this._client = null, this.isConnected = false, this._isTestEnv = false, this._isSupportVideo = false;
|
885
896
|
this._config = config;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@coze/realtime-api",
|
3
|
-
"version": "1.2.
|
3
|
+
"version": "1.2.1-beta.2",
|
4
4
|
"description": "A powerful real-time communication SDK for voice interactions with Coze AI bots | 扣子官方实时通信 SDK,用于与 Coze AI bots 进行语音交互",
|
5
5
|
"keywords": [
|
6
6
|
"coze",
|
@@ -54,7 +54,7 @@
|
|
54
54
|
"test:cov": "vitest --coverage --run"
|
55
55
|
},
|
56
56
|
"dependencies": {
|
57
|
-
"@coze/api": "1.2.
|
57
|
+
"@coze/api": "1.2.1-beta.9",
|
58
58
|
"@volcengine/rtc": "^4.62.1"
|
59
59
|
},
|
60
60
|
"devDependencies": {
|