@coze/realtime-api 1.3.1 → 1.3.2-alpha.30153e
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 -186
- package/dist/cjs/index.js +511 -662
- package/dist/cjs/live/index.js +134 -173
- package/dist/esm/event-names/index.js +43 -169
- package/dist/esm/index.js +515 -668
- package/dist/esm/live/index.js +122 -156
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/event-names/index.d.ts +2 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/live/index.d.ts +139 -60
- package/dist/umd/index.js +43855 -899
- package/dist/umd/index.js.LICENSE.txt +23 -0
- package/package.json +14 -4
package/dist/esm/index.js
CHANGED
|
@@ -1,27 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
// The require scope
|
|
1
|
+
import { CozeAPI, RoomMode } from "@coze/api";
|
|
2
|
+
import rtc, { MediaType, StreamIndex, VideoSourceType } from "@volcengine/rtc";
|
|
3
|
+
import extension_ainr from "@volcengine/rtc/extension-ainr";
|
|
5
4
|
var __webpack_require__ = {};
|
|
6
|
-
/************************************************************************/ // webpack/runtime/define_property_getters
|
|
7
5
|
(()=>{
|
|
8
|
-
__webpack_require__.d =
|
|
6
|
+
__webpack_require__.d = (exports, definition)=>{
|
|
9
7
|
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
|
|
10
8
|
enumerable: true,
|
|
11
9
|
get: definition[key]
|
|
12
10
|
});
|
|
13
11
|
};
|
|
14
12
|
})();
|
|
15
|
-
// webpack/runtime/has_own_property
|
|
16
13
|
(()=>{
|
|
17
|
-
__webpack_require__.o =
|
|
18
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
19
|
-
};
|
|
14
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
20
15
|
})();
|
|
21
|
-
// webpack/runtime/make_namespace_object
|
|
22
16
|
(()=>{
|
|
23
|
-
|
|
24
|
-
__webpack_require__.r = function(exports) {
|
|
17
|
+
__webpack_require__.r = (exports)=>{
|
|
25
18
|
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports, Symbol.toStringTag, {
|
|
26
19
|
value: 'Module'
|
|
27
20
|
});
|
|
@@ -30,7 +23,6 @@ var __webpack_require__ = {};
|
|
|
30
23
|
});
|
|
31
24
|
};
|
|
32
25
|
})();
|
|
33
|
-
/************************************************************************/ // NAMESPACE OBJECT: ./src/utils.ts
|
|
34
26
|
var utils_namespaceObject = {};
|
|
35
27
|
__webpack_require__.r(utils_namespaceObject);
|
|
36
28
|
__webpack_require__.d(utils_namespaceObject, {
|
|
@@ -42,257 +34,131 @@ __webpack_require__.d(utils_namespaceObject, {
|
|
|
42
34
|
isScreenShareSupported: ()=>isScreenShareSupported,
|
|
43
35
|
sleep: ()=>sleep
|
|
44
36
|
});
|
|
45
|
-
|
|
46
|
-
+ * Delays execution for the specified duration
|
|
47
|
-
+ * @param milliseconds The time to sleep in milliseconds
|
|
48
|
-
+ * @throws {Error} If milliseconds is negative
|
|
49
|
-
+ * @returns Promise that resolves after the specified duration
|
|
50
|
-
+ */ const sleep = (milliseconds)=>{
|
|
51
|
-
if (milliseconds < 0) throw new Error('Sleep duration must be non-negative');
|
|
52
|
-
return new Promise((resolve)=>setTimeout(resolve, milliseconds));
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* @deprecated use checkDevicePermission instead
|
|
56
|
-
* Check microphone permission,return boolean
|
|
57
|
-
*/ const checkPermission = async function() {
|
|
58
|
-
let { audio = true, video = false } = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
|
|
37
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
59
38
|
try {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
video
|
|
63
|
-
});
|
|
64
|
-
return result.audio;
|
|
39
|
+
var info = gen[key](arg);
|
|
40
|
+
var value = info.value;
|
|
65
41
|
} catch (error) {
|
|
66
|
-
|
|
67
|
-
return
|
|
42
|
+
reject(error);
|
|
43
|
+
return;
|
|
68
44
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
*/ const getAudioDevices = async function() {
|
|
85
|
-
let { video = false } = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
|
|
86
|
-
let devices = [];
|
|
87
|
-
if (video) {
|
|
88
|
-
devices = await __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].enumerateDevices();
|
|
89
|
-
if (isScreenShareSupported()) // @ts-expect-error - add screenShare device to devices
|
|
90
|
-
devices.push({
|
|
91
|
-
deviceId: 'screenShare',
|
|
92
|
-
kind: 'videoinput',
|
|
93
|
-
label: 'Screen Share',
|
|
94
|
-
groupId: 'screenShare'
|
|
45
|
+
if (info.done) resolve(value);
|
|
46
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
47
|
+
}
|
|
48
|
+
function _async_to_generator(fn) {
|
|
49
|
+
return function() {
|
|
50
|
+
var self = this, args = arguments;
|
|
51
|
+
return new Promise(function(resolve, reject) {
|
|
52
|
+
var gen = fn.apply(self, args);
|
|
53
|
+
function _next(value) {
|
|
54
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
55
|
+
}
|
|
56
|
+
function _throw(err) {
|
|
57
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
58
|
+
}
|
|
59
|
+
_next(void 0);
|
|
95
60
|
});
|
|
96
|
-
} else devices = await [
|
|
97
|
-
...await __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].enumerateAudioCaptureDevices(),
|
|
98
|
-
...await __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].enumerateAudioPlaybackDevices()
|
|
99
|
-
];
|
|
100
|
-
if (!(null == devices ? void 0 : devices.length)) return {
|
|
101
|
-
audioInputs: [],
|
|
102
|
-
audioOutputs: [],
|
|
103
|
-
videoInputs: []
|
|
104
|
-
};
|
|
105
|
-
return {
|
|
106
|
-
audioInputs: devices.filter((i)=>i.deviceId && 'audioinput' === i.kind),
|
|
107
|
-
audioOutputs: devices.filter((i)=>i.deviceId && 'audiooutput' === i.kind),
|
|
108
|
-
videoInputs: devices.filter((i)=>i.deviceId && 'videoinput' === i.kind)
|
|
109
61
|
};
|
|
62
|
+
}
|
|
63
|
+
const sleep = (milliseconds)=>{
|
|
64
|
+
if (milliseconds < 0) throw new Error('Sleep duration must be non-negative');
|
|
65
|
+
return new Promise((resolve)=>setTimeout(resolve, milliseconds));
|
|
110
66
|
};
|
|
67
|
+
const checkPermission = ({ audio = true, video = false } = {})=>_async_to_generator(function*() {
|
|
68
|
+
try {
|
|
69
|
+
const result = yield rtc.enableDevices({
|
|
70
|
+
audio,
|
|
71
|
+
video
|
|
72
|
+
});
|
|
73
|
+
return result.audio;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error('Failed to check device permissions:', error);
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
})();
|
|
79
|
+
const checkDevicePermission = (checkVideo = false)=>_async_to_generator(function*() {
|
|
80
|
+
return yield rtc.enableDevices({
|
|
81
|
+
audio: true,
|
|
82
|
+
video: checkVideo
|
|
83
|
+
});
|
|
84
|
+
})();
|
|
85
|
+
const getAudioDevices = ({ video = false } = {})=>_async_to_generator(function*() {
|
|
86
|
+
let devices = [];
|
|
87
|
+
if (video) {
|
|
88
|
+
devices = yield rtc.enumerateDevices();
|
|
89
|
+
if (isScreenShareSupported()) devices.push({
|
|
90
|
+
deviceId: 'screenShare',
|
|
91
|
+
kind: 'videoinput',
|
|
92
|
+
label: 'Screen Share',
|
|
93
|
+
groupId: 'screenShare'
|
|
94
|
+
});
|
|
95
|
+
} else devices = yield [
|
|
96
|
+
...yield rtc.enumerateAudioCaptureDevices(),
|
|
97
|
+
...yield rtc.enumerateAudioPlaybackDevices()
|
|
98
|
+
];
|
|
99
|
+
if (!(null == devices ? void 0 : devices.length)) return {
|
|
100
|
+
audioInputs: [],
|
|
101
|
+
audioOutputs: [],
|
|
102
|
+
videoInputs: []
|
|
103
|
+
};
|
|
104
|
+
return {
|
|
105
|
+
audioInputs: devices.filter((i)=>i.deviceId && 'audioinput' === i.kind),
|
|
106
|
+
audioOutputs: devices.filter((i)=>i.deviceId && 'audiooutput' === i.kind),
|
|
107
|
+
videoInputs: devices.filter((i)=>i.deviceId && 'videoinput' === i.kind)
|
|
108
|
+
};
|
|
109
|
+
})();
|
|
111
110
|
const isScreenShareDevice = (deviceId)=>'screenShare' === deviceId;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
* @param deviceId
|
|
115
|
-
* @returns
|
|
116
|
-
*/ const isMobileVideoDevice = (deviceId)=>'user' === deviceId || 'environment' === deviceId;
|
|
117
|
-
/**
|
|
118
|
-
* Check if browser supports screen sharing
|
|
119
|
-
* 检查浏览器是否支持屏幕共享
|
|
120
|
-
*/ function isScreenShareSupported() {
|
|
111
|
+
const isMobileVideoDevice = (deviceId)=>'user' === deviceId || 'environment' === deviceId;
|
|
112
|
+
function isScreenShareSupported() {
|
|
121
113
|
var _navigator_mediaDevices, _navigator;
|
|
122
|
-
return !!(null
|
|
114
|
+
return !!(null == (_navigator = navigator) ? void 0 : null == (_navigator_mediaDevices = _navigator.mediaDevices) ? void 0 : _navigator_mediaDevices.getDisplayMedia);
|
|
123
115
|
}
|
|
124
116
|
var event_names_EventNames = /*#__PURE__*/ function(EventNames) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
* zh: 客户端视频开启
|
|
168
|
-
*/ EventNames["VIDEO_ON"] = "client.video.on";
|
|
169
|
-
/**
|
|
170
|
-
* en: Client video off
|
|
171
|
-
* zh: 客户端视频关闭
|
|
172
|
-
*/ EventNames["VIDEO_OFF"] = "client.video.off";
|
|
173
|
-
/**
|
|
174
|
-
* en: Client video error
|
|
175
|
-
* zh: 客户端视频(或屏幕共享)错误
|
|
176
|
-
*/ EventNames["VIDEO_ERROR"] = "client.video.error";
|
|
177
|
-
/**
|
|
178
|
-
* en: Client video event
|
|
179
|
-
* zh: 客户端视频事件
|
|
180
|
-
*/ EventNames["PLAYER_EVENT"] = "client.video.event";
|
|
181
|
-
/**
|
|
182
|
-
* en: Client error
|
|
183
|
-
* zh: 客户端错误
|
|
184
|
-
*/ EventNames["ERROR"] = "client.error";
|
|
185
|
-
/**
|
|
186
|
-
* en: Audio noise reduction enabled
|
|
187
|
-
* zh: 抑制平稳噪声
|
|
188
|
-
*/ EventNames["SUPPRESS_STATIONARY_NOISE"] = "client.suppress.stationary.noise";
|
|
189
|
-
/**
|
|
190
|
-
* en: Suppress non-stationary noise
|
|
191
|
-
* zh: 抑制非平稳噪声
|
|
192
|
-
*/ EventNames["SUPPRESS_NON_STATIONARY_NOISE"] = "client.suppress.non.stationary.noise";
|
|
193
|
-
/**
|
|
194
|
-
* en: Audio input device changed
|
|
195
|
-
* zh: 音频输入设备改变
|
|
196
|
-
*/ EventNames["AUDIO_INPUT_DEVICE_CHANGED"] = "client.input.device.changed";
|
|
197
|
-
/**
|
|
198
|
-
* en: Audio output device changed
|
|
199
|
-
* zh: 音频输出设备改变
|
|
200
|
-
*/ EventNames["AUDIO_OUTPUT_DEVICE_CHANGED"] = "client.output.device.changed";
|
|
201
|
-
/**
|
|
202
|
-
* en: Video input device changed
|
|
203
|
-
* zh: 视频输入设备改变
|
|
204
|
-
*/ EventNames["VIDEO_INPUT_DEVICE_CHANGED"] = "client.video.input.device.changed";
|
|
205
|
-
/**
|
|
206
|
-
* en: Network quality changed
|
|
207
|
-
* zh: 网络质量改变
|
|
208
|
-
*/ EventNames["NETWORK_QUALITY"] = "client.network.quality";
|
|
209
|
-
/**
|
|
210
|
-
* en: Bot joined
|
|
211
|
-
* zh: Bot 加入
|
|
212
|
-
*/ EventNames["BOT_JOIN"] = "server.bot.join";
|
|
213
|
-
/**
|
|
214
|
-
* en: Bot left
|
|
215
|
-
* zh: Bot 离开
|
|
216
|
-
*/ EventNames["BOT_LEAVE"] = "server.bot.leave";
|
|
217
|
-
/**
|
|
218
|
-
* en: Audio speech started
|
|
219
|
-
* zh: 开始说话
|
|
220
|
-
*/ EventNames["AUDIO_AGENT_SPEECH_STARTED"] = "server.audio.agent.speech_started";
|
|
221
|
-
/**
|
|
222
|
-
* en: Audio speech stopped
|
|
223
|
-
* zh: 停止说话
|
|
224
|
-
*/ EventNames["AUDIO_AGENT_SPEECH_STOPPED"] = "server.audio.agent.speech_stopped";
|
|
225
|
-
/**
|
|
226
|
-
* en: Server error
|
|
227
|
-
* zh: 服务端错误
|
|
228
|
-
*/ EventNames["SERVER_ERROR"] = "server.error";
|
|
229
|
-
/**
|
|
230
|
-
* en: User speech started
|
|
231
|
-
* zh: 用户开始说话
|
|
232
|
-
*/ EventNames["AUDIO_USER_SPEECH_STARTED"] = "server.audio.user.speech_started";
|
|
233
|
-
/**
|
|
234
|
-
* en: User speech stopped
|
|
235
|
-
* zh: 用户停止说话
|
|
236
|
-
*/ EventNames["AUDIO_USER_SPEECH_STOPPED"] = "server.audio.user.speech_stopped";
|
|
237
|
-
/**
|
|
238
|
-
* en: User successfully enters the room
|
|
239
|
-
* zh: 用户成功进入房间后,会收到该事件
|
|
240
|
-
*/ EventNames["SESSION_CREATED"] = "server.session.created";
|
|
241
|
-
/**
|
|
242
|
-
* en: Session updated
|
|
243
|
-
* zh: 会话更新
|
|
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";
|
|
289
|
-
/**
|
|
290
|
-
* en: Live created
|
|
291
|
-
* zh: 直播创建
|
|
292
|
-
*/ EventNames["LIVE_CREATED"] = "server.live.created";
|
|
117
|
+
EventNames["ALL"] = "realtime.event";
|
|
118
|
+
EventNames["ALL_CLIENT"] = "client.*";
|
|
119
|
+
EventNames["ALL_SERVER"] = "server.*";
|
|
120
|
+
EventNames["ROOM_INFO"] = "client.room.info";
|
|
121
|
+
EventNames["CONNECTED"] = "client.connected";
|
|
122
|
+
EventNames["CONNECTING"] = "client.connecting";
|
|
123
|
+
EventNames["INTERRUPTED"] = "client.interrupted";
|
|
124
|
+
EventNames["DISCONNECTED"] = "client.disconnected";
|
|
125
|
+
EventNames["AUDIO_UNMUTED"] = "client.audio.unmuted";
|
|
126
|
+
EventNames["AUDIO_MUTED"] = "client.audio.muted";
|
|
127
|
+
EventNames["VIDEO_ON"] = "client.video.on";
|
|
128
|
+
EventNames["VIDEO_OFF"] = "client.video.off";
|
|
129
|
+
EventNames["VIDEO_ERROR"] = "client.video.error";
|
|
130
|
+
EventNames["PLAYER_EVENT"] = "client.video.event";
|
|
131
|
+
EventNames["ERROR"] = "client.error";
|
|
132
|
+
EventNames["SUPPRESS_STATIONARY_NOISE"] = "client.suppress.stationary.noise";
|
|
133
|
+
EventNames["SUPPRESS_NON_STATIONARY_NOISE"] = "client.suppress.non.stationary.noise";
|
|
134
|
+
EventNames["AUDIO_INPUT_DEVICE_CHANGED"] = "client.input.device.changed";
|
|
135
|
+
EventNames["AUDIO_OUTPUT_DEVICE_CHANGED"] = "client.output.device.changed";
|
|
136
|
+
EventNames["VIDEO_INPUT_DEVICE_CHANGED"] = "client.video.input.device.changed";
|
|
137
|
+
EventNames["NETWORK_QUALITY"] = "client.network.quality";
|
|
138
|
+
EventNames["BOT_JOIN"] = "server.bot.join";
|
|
139
|
+
EventNames["BOT_LEAVE"] = "server.bot.leave";
|
|
140
|
+
EventNames["AUDIO_AGENT_SPEECH_STARTED"] = "server.audio.agent.speech_started";
|
|
141
|
+
EventNames["AUDIO_AGENT_SPEECH_STOPPED"] = "server.audio.agent.speech_stopped";
|
|
142
|
+
EventNames["SERVER_ERROR"] = "server.error";
|
|
143
|
+
EventNames["AUDIO_USER_SPEECH_STARTED"] = "server.audio.user.speech_started";
|
|
144
|
+
EventNames["AUDIO_USER_SPEECH_STOPPED"] = "server.audio.user.speech_stopped";
|
|
145
|
+
EventNames["SESSION_CREATED"] = "server.session.created";
|
|
146
|
+
EventNames["SESSION_UPDATED"] = "server.session.updated";
|
|
147
|
+
EventNames["CONVERSATION_CREATED"] = "server.conversation.created";
|
|
148
|
+
EventNames["CONVERSATION_CHAT_CREATED"] = "server.conversation.chat.created";
|
|
149
|
+
EventNames["CONVERSATION_CHAT_IN_PROGRESS"] = "server.conversation.chat.in_progress";
|
|
150
|
+
EventNames["CONVERSATION_MESSAGE_DELTA"] = "server.conversation.message.delta";
|
|
151
|
+
EventNames["CONVERSATION_MESSAGE_COMPLETED"] = "server.conversation.message.completed";
|
|
152
|
+
EventNames["CONVERSATION_CHAT_COMPLETED"] = "server.conversation.chat.completed";
|
|
153
|
+
EventNames["CONVERSATION_CHAT_REQUIRES_ACTION"] = "server.conversation.chat.requires_action";
|
|
154
|
+
EventNames["CONVERSATION_CHAT_FAILED"] = "server.conversation.chat.failed";
|
|
155
|
+
EventNames["SESSION_PRE_ANSWER_UPDATED"] = "server.session.pre_answer.updated";
|
|
156
|
+
EventNames["CONVERSATION_AUDIO_TRANSCRIPT_DELTA"] = "server.conversation.audio_transcript.delta";
|
|
157
|
+
EventNames["MODE_UPDATED"] = "server.mode.updated";
|
|
158
|
+
EventNames["LIVE_CREATED"] = "server.live.created";
|
|
293
159
|
return EventNames;
|
|
294
160
|
}(event_names_EventNames || {});
|
|
295
|
-
|
|
161
|
+
const event_names = event_names_EventNames;
|
|
296
162
|
var error_RealtimeError = /*#__PURE__*/ function(RealtimeError) {
|
|
297
163
|
RealtimeError["DEVICE_ACCESS_ERROR"] = "DEVICE_ACCESS_ERROR";
|
|
298
164
|
RealtimeError["STREAM_CREATION_ERROR"] = "STREAM_CREATION_ERROR";
|
|
@@ -309,11 +175,7 @@ var error_RealtimeError = /*#__PURE__*/ function(RealtimeError) {
|
|
|
309
175
|
return RealtimeError;
|
|
310
176
|
}({});
|
|
311
177
|
class RealtimeAPIError extends Error {
|
|
312
|
-
|
|
313
|
-
* @param code - Error code
|
|
314
|
-
* @param message - Error message
|
|
315
|
-
* @param error - Error object
|
|
316
|
-
*/ constructor(code, message, error){
|
|
178
|
+
constructor(code, message, error){
|
|
317
179
|
super(`[${code}] ${message}`);
|
|
318
180
|
this.name = 'RealtimeAPIError';
|
|
319
181
|
this.code = code;
|
|
@@ -335,14 +197,10 @@ class RealtimeEventHandler {
|
|
|
335
197
|
const handlers = this.eventHandlers[eventName] || [];
|
|
336
198
|
if (callback) {
|
|
337
199
|
const index = handlers.indexOf(callback);
|
|
338
|
-
if (-1 === index) {
|
|
339
|
-
console.warn(`Could not turn off specified event listener for "${eventName}": not found as a listener`);
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
200
|
+
if (-1 === index) return void console.warn(`Could not turn off specified event listener for "${eventName}": not found as a listener`);
|
|
342
201
|
handlers.splice(index, 1);
|
|
343
202
|
} else delete this.eventHandlers[eventName];
|
|
344
203
|
}
|
|
345
|
-
// eslint-disable-next-line max-params
|
|
346
204
|
_dispatchToHandlers(eventName, event, handlers, prefix) {
|
|
347
205
|
for (const handler of handlers)if (!prefix || eventName.startsWith(prefix)) try {
|
|
348
206
|
handler(eventName, event);
|
|
@@ -350,8 +208,7 @@ class RealtimeEventHandler {
|
|
|
350
208
|
throw new RealtimeAPIError(error_RealtimeError.HANDLER_MESSAGE_ERROR, `Failed to handle message: ${eventName}`);
|
|
351
209
|
}
|
|
352
210
|
}
|
|
353
|
-
dispatch(eventName, event) {
|
|
354
|
-
let consoleLog = !(arguments.length > 2) || void 0 === arguments[2] || arguments[2];
|
|
211
|
+
dispatch(eventName, event, consoleLog = true) {
|
|
355
212
|
if (consoleLog) this._log(`dispatch ${eventName} event`, event);
|
|
356
213
|
const handlers = (this.eventHandlers[eventName] || []).slice();
|
|
357
214
|
this._dispatchToHandlers(eventName, event, handlers);
|
|
@@ -370,37 +227,62 @@ class RealtimeEventHandler {
|
|
|
370
227
|
this._debug = debug;
|
|
371
228
|
}
|
|
372
229
|
}
|
|
230
|
+
function client_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
231
|
+
try {
|
|
232
|
+
var info = gen[key](arg);
|
|
233
|
+
var value = info.value;
|
|
234
|
+
} catch (error) {
|
|
235
|
+
reject(error);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (info.done) resolve(value);
|
|
239
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
240
|
+
}
|
|
241
|
+
function client_async_to_generator(fn) {
|
|
242
|
+
return function() {
|
|
243
|
+
var self = this, args = arguments;
|
|
244
|
+
return new Promise(function(resolve, reject) {
|
|
245
|
+
var gen = fn.apply(self, args);
|
|
246
|
+
function _next(value) {
|
|
247
|
+
client_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
248
|
+
}
|
|
249
|
+
function _throw(err) {
|
|
250
|
+
client_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
251
|
+
}
|
|
252
|
+
_next(void 0);
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
}
|
|
373
256
|
class EngineClient extends RealtimeEventHandler {
|
|
374
257
|
bindEngineEvents() {
|
|
375
|
-
this.engine.on(
|
|
376
|
-
this.engine.on(
|
|
377
|
-
this.engine.on(
|
|
378
|
-
this.engine.on(
|
|
379
|
-
this.engine.on(
|
|
380
|
-
this.engine.on(
|
|
381
|
-
if (this._isSupportVideo) this.engine.on(
|
|
258
|
+
this.engine.on(rtc.events.onUserMessageReceived, this.handleMessage);
|
|
259
|
+
this.engine.on(rtc.events.onUserJoined, this.handleUserJoin);
|
|
260
|
+
this.engine.on(rtc.events.onUserLeave, this.handleUserLeave);
|
|
261
|
+
this.engine.on(rtc.events.onError, this.handleEventError);
|
|
262
|
+
this.engine.on(rtc.events.onNetworkQuality, this.handleNetworkQuality);
|
|
263
|
+
this.engine.on(rtc.events.onTrackEnded, this.handleTrackEnded);
|
|
264
|
+
if (this._isSupportVideo) this.engine.on(rtc.events.onPlayerEvent, this.handlePlayerEvent);
|
|
382
265
|
if (this._debug) {
|
|
383
|
-
this.engine.on(
|
|
384
|
-
this.engine.on(
|
|
266
|
+
this.engine.on(rtc.events.onLocalAudioPropertiesReport, this.handleLocalAudioPropertiesReport);
|
|
267
|
+
this.engine.on(rtc.events.onRemoteAudioPropertiesReport, this.handleRemoteAudioPropertiesReport);
|
|
385
268
|
}
|
|
386
269
|
}
|
|
387
270
|
removeEventListener() {
|
|
388
|
-
this.engine.off(
|
|
389
|
-
this.engine.off(
|
|
390
|
-
this.engine.off(
|
|
391
|
-
this.engine.off(
|
|
392
|
-
this.engine.off(
|
|
393
|
-
this.engine.off(
|
|
394
|
-
if (this._isSupportVideo) this.engine.off(
|
|
271
|
+
this.engine.off(rtc.events.onUserMessageReceived, this.handleMessage);
|
|
272
|
+
this.engine.off(rtc.events.onUserJoined, this.handleUserJoin);
|
|
273
|
+
this.engine.off(rtc.events.onUserLeave, this.handleUserLeave);
|
|
274
|
+
this.engine.off(rtc.events.onError, this.handleEventError);
|
|
275
|
+
this.engine.off(rtc.events.onNetworkQuality, this.handleNetworkQuality);
|
|
276
|
+
this.engine.off(rtc.events.onTrackEnded, this.handleTrackEnded);
|
|
277
|
+
if (this._isSupportVideo) this.engine.off(rtc.events.onPlayerEvent, this.handlePlayerEvent);
|
|
395
278
|
if (this._debug) {
|
|
396
|
-
this.engine.off(
|
|
397
|
-
this.engine.off(
|
|
279
|
+
this.engine.off(rtc.events.onLocalAudioPropertiesReport, this.handleLocalAudioPropertiesReport);
|
|
280
|
+
this.engine.off(rtc.events.onRemoteAudioPropertiesReport, this.handleRemoteAudioPropertiesReport);
|
|
398
281
|
}
|
|
399
282
|
}
|
|
400
283
|
_parseMessage(event) {
|
|
401
284
|
try {
|
|
402
285
|
return JSON.parse(event.message);
|
|
403
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
404
286
|
} catch (e) {
|
|
405
287
|
throw new RealtimeAPIError(error_RealtimeError.PARSE_MESSAGE_ERROR, (null == e ? void 0 : e.message) || 'Unknown error');
|
|
406
288
|
}
|
|
@@ -441,176 +323,198 @@ class EngineClient extends RealtimeEventHandler {
|
|
|
441
323
|
downlinkNetworkQuality
|
|
442
324
|
});
|
|
443
325
|
}
|
|
444
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
445
326
|
handleTrackEnded(event) {
|
|
446
327
|
if ((null == event ? void 0 : event.kind) === 'video') this.dispatch(event_names.VIDEO_OFF, event);
|
|
447
328
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
329
|
+
joinRoom(options) {
|
|
330
|
+
return client_async_to_generator(function*() {
|
|
331
|
+
const { token, roomId, uid, audioMutedDefault, videoOnDefault, isAutoSubscribeAudio } = options;
|
|
332
|
+
try {
|
|
333
|
+
yield this.engine.joinRoom(token, roomId, {
|
|
334
|
+
userId: uid
|
|
335
|
+
}, {
|
|
336
|
+
isAutoPublish: !audioMutedDefault,
|
|
337
|
+
isAutoSubscribeAudio,
|
|
338
|
+
isAutoSubscribeVideo: this._isSupportVideo && videoOnDefault
|
|
339
|
+
});
|
|
340
|
+
} catch (e) {
|
|
341
|
+
if (e instanceof Error) throw new RealtimeAPIError(error_RealtimeError.CONNECTION_ERROR, e.message);
|
|
342
|
+
}
|
|
343
|
+
}).call(this);
|
|
344
|
+
}
|
|
345
|
+
setAudioInputDevice(deviceId) {
|
|
346
|
+
return client_async_to_generator(function*() {
|
|
347
|
+
const devices = yield getAudioDevices();
|
|
348
|
+
if (-1 === devices.audioInputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Audio input device not found: ${deviceId}`);
|
|
349
|
+
this.engine.stopAudioCapture();
|
|
350
|
+
yield this.engine.startAudioCapture(deviceId);
|
|
351
|
+
}).call(this);
|
|
352
|
+
}
|
|
353
|
+
setAudioOutputDevice(deviceId) {
|
|
354
|
+
return client_async_to_generator(function*() {
|
|
355
|
+
const devices = yield getAudioDevices({
|
|
356
|
+
video: false
|
|
457
357
|
});
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
if (isScreenShareDevice(deviceId)) {
|
|
488
|
-
if (this._streamIndex === __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN) this.engine.setLocalVideoPlayer(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN);
|
|
489
|
-
if (isAutoCapture) {
|
|
490
|
-
var _this__videoConfig1;
|
|
491
|
-
this.engine.setVideoSourceType(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_SCREEN, __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
|
|
492
|
-
await this.engine.startScreenCapture(null === (_this__videoConfig1 = this._videoConfig) || void 0 === _this__videoConfig1 ? void 0 : _this__videoConfig1.screenConfig);
|
|
493
|
-
await this.engine.publishScreen(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.MediaType.VIDEO);
|
|
358
|
+
if (-1 === devices.audioOutputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Audio output device not found: ${deviceId}`);
|
|
359
|
+
yield this.engine.setAudioPlaybackDevice(deviceId);
|
|
360
|
+
}).call(this);
|
|
361
|
+
}
|
|
362
|
+
setVideoInputDevice(deviceId, isAutoCapture = true) {
|
|
363
|
+
return client_async_to_generator(function*() {
|
|
364
|
+
var _this__videoConfig;
|
|
365
|
+
const devices = yield getAudioDevices({
|
|
366
|
+
video: true
|
|
367
|
+
});
|
|
368
|
+
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}`);
|
|
369
|
+
this.engine.setLocalVideoPlayer(isScreenShareDevice(deviceId) ? StreamIndex.STREAM_INDEX_SCREEN : StreamIndex.STREAM_INDEX_MAIN, {
|
|
370
|
+
renderDom: (null == (_this__videoConfig = this._videoConfig) ? void 0 : _this__videoConfig.renderDom) || 'local-player',
|
|
371
|
+
userId: this._roomUserId
|
|
372
|
+
});
|
|
373
|
+
yield this.changeVideoState(false);
|
|
374
|
+
if (isScreenShareDevice(deviceId)) {
|
|
375
|
+
if (this._streamIndex === StreamIndex.STREAM_INDEX_MAIN) this.engine.setLocalVideoPlayer(StreamIndex.STREAM_INDEX_MAIN);
|
|
376
|
+
if (isAutoCapture) {
|
|
377
|
+
var _this__videoConfig1;
|
|
378
|
+
this.engine.setVideoSourceType(StreamIndex.STREAM_INDEX_SCREEN, VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
|
|
379
|
+
yield this.engine.startScreenCapture(null == (_this__videoConfig1 = this._videoConfig) ? void 0 : _this__videoConfig1.screenConfig);
|
|
380
|
+
yield this.engine.publishScreen(MediaType.VIDEO);
|
|
381
|
+
}
|
|
382
|
+
this._streamIndex = StreamIndex.STREAM_INDEX_SCREEN;
|
|
383
|
+
} else {
|
|
384
|
+
if (this._streamIndex === StreamIndex.STREAM_INDEX_SCREEN) this.engine.setLocalVideoPlayer(StreamIndex.STREAM_INDEX_SCREEN);
|
|
385
|
+
if (isAutoCapture) yield this.engine.startVideoCapture(deviceId);
|
|
386
|
+
this._streamIndex = StreamIndex.STREAM_INDEX_MAIN;
|
|
494
387
|
}
|
|
495
|
-
|
|
496
|
-
} else {
|
|
497
|
-
if (this._streamIndex === __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_SCREEN) this.engine.setLocalVideoPlayer(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_SCREEN);
|
|
498
|
-
if (isAutoCapture) await this.engine.startVideoCapture(deviceId);
|
|
499
|
-
this._streamIndex = __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN;
|
|
500
|
-
}
|
|
388
|
+
}).call(this);
|
|
501
389
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
390
|
+
createLocalStream(userId, videoConfig) {
|
|
391
|
+
return client_async_to_generator(function*() {
|
|
392
|
+
this._roomUserId = userId;
|
|
393
|
+
const devices = yield getAudioDevices({
|
|
394
|
+
video: this._isSupportVideo
|
|
395
|
+
});
|
|
396
|
+
if (!devices.audioInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get audio devices');
|
|
397
|
+
if (this._isSupportVideo && !devices.videoInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get video devices');
|
|
398
|
+
yield this.engine.startAudioCapture(devices.audioInputs[0].deviceId);
|
|
399
|
+
if (this._isSupportVideo) try {
|
|
400
|
+
yield this.setVideoInputDevice((null == videoConfig ? void 0 : videoConfig.videoInputDeviceId) || devices.videoInputs[0].deviceId, null == videoConfig ? void 0 : videoConfig.videoOnDefault);
|
|
401
|
+
this.dispatch((null == videoConfig ? void 0 : videoConfig.videoOnDefault) ? event_names.VIDEO_ON : event_names.VIDEO_OFF, {});
|
|
402
|
+
} catch (e) {
|
|
403
|
+
this.dispatch(event_names.VIDEO_ERROR, e);
|
|
404
|
+
}
|
|
405
|
+
}).call(this);
|
|
406
|
+
}
|
|
407
|
+
disconnect() {
|
|
408
|
+
return client_async_to_generator(function*() {
|
|
409
|
+
try {
|
|
410
|
+
yield this.engine.leaveRoom();
|
|
411
|
+
this.removeEventListener();
|
|
412
|
+
this.clearEventHandlers();
|
|
413
|
+
rtc.destroyEngine(this.engine);
|
|
414
|
+
} catch (e) {
|
|
415
|
+
this.dispatch(event_names.ERROR, e);
|
|
416
|
+
throw e;
|
|
417
|
+
}
|
|
418
|
+
}).call(this);
|
|
419
|
+
}
|
|
420
|
+
changeAudioState(isMicOn) {
|
|
421
|
+
return client_async_to_generator(function*() {
|
|
422
|
+
try {
|
|
423
|
+
if (isMicOn) yield this.engine.publishStream(MediaType.AUDIO);
|
|
424
|
+
else yield this.engine.unpublishStream(MediaType.AUDIO);
|
|
425
|
+
} catch (e) {
|
|
426
|
+
this.dispatch(event_names.ERROR, e);
|
|
427
|
+
throw e;
|
|
428
|
+
}
|
|
429
|
+
}).call(this);
|
|
536
430
|
}
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
if (this._streamIndex ===
|
|
431
|
+
changeVideoState(isVideoOn) {
|
|
432
|
+
return client_async_to_generator(function*() {
|
|
433
|
+
if (isVideoOn) if (this._streamIndex === StreamIndex.STREAM_INDEX_MAIN) yield this.engine.startVideoCapture();
|
|
540
434
|
else {
|
|
541
435
|
var _this__videoConfig;
|
|
542
|
-
this.engine.setVideoSourceType(
|
|
543
|
-
|
|
544
|
-
|
|
436
|
+
this.engine.setVideoSourceType(StreamIndex.STREAM_INDEX_SCREEN, VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
|
|
437
|
+
yield this.engine.startScreenCapture(null == (_this__videoConfig = this._videoConfig) ? void 0 : _this__videoConfig.screenConfig);
|
|
438
|
+
yield this.engine.publishScreen(MediaType.VIDEO);
|
|
545
439
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
440
|
+
else if (this._streamIndex === StreamIndex.STREAM_INDEX_MAIN) yield this.engine.stopVideoCapture();
|
|
441
|
+
else {
|
|
442
|
+
yield this.engine.stopScreenCapture();
|
|
443
|
+
yield this.engine.unpublishScreen(MediaType.VIDEO);
|
|
444
|
+
}
|
|
445
|
+
}).call(this);
|
|
446
|
+
}
|
|
447
|
+
stop() {
|
|
448
|
+
return client_async_to_generator(function*() {
|
|
449
|
+
try {
|
|
450
|
+
const result = yield this.engine.sendUserMessage(this.joinUserId, JSON.stringify({
|
|
451
|
+
id: 'event_1',
|
|
452
|
+
event_type: 'conversation.chat.cancel',
|
|
453
|
+
data: {}
|
|
454
|
+
}));
|
|
455
|
+
this._log(`interrupt ${this.joinUserId} ${result}`);
|
|
456
|
+
} catch (e) {
|
|
457
|
+
this.dispatch(event_names.ERROR, e);
|
|
458
|
+
throw e;
|
|
459
|
+
}
|
|
460
|
+
}).call(this);
|
|
461
|
+
}
|
|
462
|
+
sendMessage(message) {
|
|
463
|
+
return client_async_to_generator(function*() {
|
|
464
|
+
try {
|
|
465
|
+
const result = yield this.engine.sendUserMessage(this.joinUserId, JSON.stringify(message));
|
|
466
|
+
this._log(`sendMessage ${this.joinUserId} ${JSON.stringify(message)} ${result}`);
|
|
467
|
+
} catch (e) {
|
|
468
|
+
this.dispatch(event_names.ERROR, e);
|
|
469
|
+
throw e;
|
|
470
|
+
}
|
|
471
|
+
}).call(this);
|
|
573
472
|
}
|
|
574
473
|
enableAudioPropertiesReport(config) {
|
|
575
474
|
this.engine.enableAudioPropertiesReport(config);
|
|
576
475
|
}
|
|
577
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
578
476
|
handleLocalAudioPropertiesReport(event) {
|
|
579
477
|
var _event__audioPropertiesInfo, _event_;
|
|
580
|
-
if (this._debug && (null
|
|
478
|
+
if (this._debug && (null == (_event_ = event[0]) ? void 0 : null == (_event__audioPropertiesInfo = _event_.audioPropertiesInfo) ? void 0 : _event__audioPropertiesInfo.linearVolume) > 0) console.log('handleLocalAudioPropertiesReport', event);
|
|
581
479
|
}
|
|
582
480
|
handleRemoteAudioPropertiesReport(event) {
|
|
583
481
|
if (this._debug) console.log('handleRemoteAudioPropertiesReport', event);
|
|
584
482
|
}
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
483
|
+
enableAudioNoiseReduction() {
|
|
484
|
+
return client_async_to_generator(function*() {
|
|
485
|
+
var _this_engine;
|
|
486
|
+
yield null == (_this_engine = this.engine) ? void 0 : _this_engine.setAudioCaptureConfig({
|
|
487
|
+
noiseSuppression: true,
|
|
488
|
+
echoCancellation: true,
|
|
489
|
+
autoGainControl: true
|
|
490
|
+
});
|
|
491
|
+
}).call(this);
|
|
592
492
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
493
|
+
initAIAnsExtension() {
|
|
494
|
+
return client_async_to_generator(function*() {
|
|
495
|
+
const AIAnsExtension = new extension_ainr();
|
|
496
|
+
yield this.engine.registerExtension(AIAnsExtension);
|
|
497
|
+
this._AIAnsExtension = AIAnsExtension;
|
|
498
|
+
}).call(this);
|
|
597
499
|
}
|
|
598
500
|
changeAIAnsExtension(enable) {
|
|
599
501
|
if (enable) {
|
|
600
502
|
var _this__AIAnsExtension;
|
|
601
|
-
null
|
|
503
|
+
null == (_this__AIAnsExtension = this._AIAnsExtension) || _this__AIAnsExtension.enable();
|
|
602
504
|
} else {
|
|
603
505
|
var _this__AIAnsExtension1;
|
|
604
|
-
null
|
|
506
|
+
null == (_this__AIAnsExtension1 = this._AIAnsExtension) || _this__AIAnsExtension1.disable();
|
|
605
507
|
}
|
|
606
508
|
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
509
|
+
startAudioPlaybackDeviceTest() {
|
|
510
|
+
return client_async_to_generator(function*() {
|
|
511
|
+
try {
|
|
512
|
+
yield this.engine.startAudioPlaybackDeviceTest('audio-test.wav', 200);
|
|
513
|
+
} catch (e) {
|
|
514
|
+
this.dispatch(event_names.ERROR, e);
|
|
515
|
+
throw e;
|
|
516
|
+
}
|
|
517
|
+
}).call(this);
|
|
614
518
|
}
|
|
615
519
|
stopAudioPlaybackDeviceTest() {
|
|
616
520
|
try {
|
|
@@ -623,14 +527,13 @@ class EngineClient extends RealtimeEventHandler {
|
|
|
623
527
|
getRtcEngine() {
|
|
624
528
|
return this.engine;
|
|
625
529
|
}
|
|
626
|
-
// eslint-disable-next-line max-params
|
|
627
530
|
constructor(appId, debug = false, isTestEnv = false, isSupportVideo = false, videoConfig){
|
|
628
531
|
super(debug), this.joinUserId = '', this._AIAnsExtension = null, this._isSupportVideo = false;
|
|
629
|
-
if (isTestEnv)
|
|
532
|
+
if (isTestEnv) rtc.setParameter('ICE_CONFIG_REQUEST_URLS', [
|
|
630
533
|
'rtc-test.bytedance.com'
|
|
631
534
|
]);
|
|
632
535
|
else localStorage.removeItem('RTC_ACCESS_URLS-VolcEngine');
|
|
633
|
-
this.engine =
|
|
536
|
+
this.engine = rtc.createEngine(appId);
|
|
634
537
|
this.handleMessage = this.handleMessage.bind(this);
|
|
635
538
|
this.handleUserJoin = this.handleUserJoin.bind(this);
|
|
636
539
|
this.handleUserLeave = this.handleUserLeave.bind(this);
|
|
@@ -638,284 +541,228 @@ class EngineClient extends RealtimeEventHandler {
|
|
|
638
541
|
this.handlePlayerEvent = this.handlePlayerEvent.bind(this);
|
|
639
542
|
this.handleNetworkQuality = this.handleNetworkQuality.bind(this);
|
|
640
543
|
this.handleTrackEnded = this.handleTrackEnded.bind(this);
|
|
641
|
-
// Debug only
|
|
642
544
|
this.handleLocalAudioPropertiesReport = this.handleLocalAudioPropertiesReport.bind(this);
|
|
643
545
|
this.handleRemoteAudioPropertiesReport = this.handleRemoteAudioPropertiesReport.bind(this);
|
|
644
546
|
this._isSupportVideo = isSupportVideo;
|
|
645
547
|
this._videoConfig = videoConfig;
|
|
646
548
|
}
|
|
647
549
|
}
|
|
648
|
-
|
|
550
|
+
function src_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
551
|
+
try {
|
|
552
|
+
var info = gen[key](arg);
|
|
553
|
+
var value = info.value;
|
|
554
|
+
} catch (error) {
|
|
555
|
+
reject(error);
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
if (info.done) resolve(value);
|
|
559
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
560
|
+
}
|
|
561
|
+
function src_async_to_generator(fn) {
|
|
562
|
+
return function() {
|
|
563
|
+
var self = this, args = arguments;
|
|
564
|
+
return new Promise(function(resolve, reject) {
|
|
565
|
+
var gen = fn.apply(self, args);
|
|
566
|
+
function _next(value) {
|
|
567
|
+
src_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
568
|
+
}
|
|
569
|
+
function _throw(err) {
|
|
570
|
+
src_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
571
|
+
}
|
|
572
|
+
_next(void 0);
|
|
573
|
+
});
|
|
574
|
+
};
|
|
575
|
+
}
|
|
649
576
|
const TEST_APP_ID = '6705332c79516e015e3e5f0c';
|
|
650
577
|
class RealtimeClient extends RealtimeEventHandler {
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
const config = {};
|
|
665
|
-
if (this._config.prologueContent) config.prologue_content = this._config.prologueContent;
|
|
666
|
-
if (void 0 !== this._config.roomMode && null !== this._config.roomMode) config.room_mode = this._config.roomMode || __WEBPACK_EXTERNAL_MODULE__coze_api__.RoomMode.Default;
|
|
667
|
-
if (this._config.videoConfig) {
|
|
668
|
-
if (isScreenShareDevice(this._config.videoConfig.videoInputDeviceId)) config.video_config = {
|
|
578
|
+
connect() {
|
|
579
|
+
return src_async_to_generator(function*() {
|
|
580
|
+
var _this__config_videoConfig;
|
|
581
|
+
const { botId, conversationId, voiceId, getRoomInfo } = this._config;
|
|
582
|
+
this.dispatch(event_names.CONNECTING, {});
|
|
583
|
+
let roomInfo;
|
|
584
|
+
try {
|
|
585
|
+
if (getRoomInfo) roomInfo = yield getRoomInfo();
|
|
586
|
+
else {
|
|
587
|
+
const config = {};
|
|
588
|
+
if (this._config.prologueContent) config.prologue_content = this._config.prologueContent;
|
|
589
|
+
if (void 0 !== this._config.roomMode && null !== this._config.roomMode) config.room_mode = this._config.roomMode || RoomMode.Default;
|
|
590
|
+
if (this._config.videoConfig) if (isScreenShareDevice(this._config.videoConfig.videoInputDeviceId)) config.video_config = {
|
|
669
591
|
stream_video_type: 'screen'
|
|
670
592
|
};
|
|
671
593
|
else config.video_config = {
|
|
672
594
|
stream_video_type: 'main'
|
|
673
595
|
};
|
|
596
|
+
if (this._config.translateConfig) config.translate_config = this._config.translateConfig;
|
|
597
|
+
if (this._config.turnDetection) config.turn_detection = this._config.turnDetection;
|
|
598
|
+
const params = {
|
|
599
|
+
bot_id: botId,
|
|
600
|
+
conversation_id: conversationId || void 0,
|
|
601
|
+
voice_id: voiceId && voiceId.length > 0 ? voiceId : void 0,
|
|
602
|
+
connector_id: this._config.connectorId,
|
|
603
|
+
uid: this._config.userId || void 0,
|
|
604
|
+
workflow_id: this._config.workflowId || void 0,
|
|
605
|
+
config
|
|
606
|
+
};
|
|
607
|
+
roomInfo = yield this._api.audio.rooms.create(params);
|
|
674
608
|
}
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
conversation_id: conversationId || void 0,
|
|
679
|
-
voice_id: voiceId && voiceId.length > 0 ? voiceId : void 0,
|
|
680
|
-
connector_id: this._config.connectorId,
|
|
681
|
-
uid: this._config.userId || void 0,
|
|
682
|
-
workflow_id: this._config.workflowId || void 0,
|
|
683
|
-
config
|
|
684
|
-
};
|
|
685
|
-
roomInfo = await this._api.audio.rooms.create(params);
|
|
609
|
+
} catch (error) {
|
|
610
|
+
this.dispatch(event_names.ERROR, error);
|
|
611
|
+
throw new RealtimeAPIError(error_RealtimeError.CREATE_ROOM_ERROR, error instanceof Error ? error.message : 'Unknown error', error);
|
|
686
612
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
this.
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
this._client.
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
// step6 set connected and dispatch connected event
|
|
729
|
-
this.isConnected = true;
|
|
730
|
-
this.dispatch(event_names.CONNECTED, {
|
|
731
|
-
roomId: roomInfo.room_id,
|
|
732
|
-
uid: roomInfo.uid,
|
|
733
|
-
token: roomInfo.token,
|
|
734
|
-
appId: roomInfo.app_id
|
|
735
|
-
});
|
|
613
|
+
this.dispatch(event_names.ROOM_INFO, {
|
|
614
|
+
roomId: roomInfo.room_id,
|
|
615
|
+
uid: roomInfo.uid,
|
|
616
|
+
token: roomInfo.token,
|
|
617
|
+
appId: roomInfo.app_id
|
|
618
|
+
});
|
|
619
|
+
this._isTestEnv = TEST_APP_ID === roomInfo.app_id;
|
|
620
|
+
this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo, this._config.videoConfig);
|
|
621
|
+
this._client.bindEngineEvents();
|
|
622
|
+
this._client.on(event_names.ALL, (eventName, data)=>{
|
|
623
|
+
this.dispatch(eventName, data, false);
|
|
624
|
+
});
|
|
625
|
+
if (this._config.suppressStationaryNoise) {
|
|
626
|
+
yield this._client.enableAudioNoiseReduction();
|
|
627
|
+
this.dispatch(event_names.SUPPRESS_STATIONARY_NOISE, {});
|
|
628
|
+
}
|
|
629
|
+
if (this._config.suppressNonStationaryNoise) try {
|
|
630
|
+
yield this._client.initAIAnsExtension();
|
|
631
|
+
this._client.changeAIAnsExtension(true);
|
|
632
|
+
this.dispatch(event_names.SUPPRESS_NON_STATIONARY_NOISE, {});
|
|
633
|
+
} catch (error) {
|
|
634
|
+
console.warn('Config suppressNonStationaryNoise is not supported', error);
|
|
635
|
+
}
|
|
636
|
+
var _this__config_audioMutedDefault, _this__config_videoConfig_videoOnDefault, _this__config_isAutoSubscribeAudio;
|
|
637
|
+
yield this._client.joinRoom({
|
|
638
|
+
token: roomInfo.token,
|
|
639
|
+
roomId: roomInfo.room_id,
|
|
640
|
+
uid: roomInfo.uid,
|
|
641
|
+
audioMutedDefault: null != (_this__config_audioMutedDefault = this._config.audioMutedDefault) ? _this__config_audioMutedDefault : false,
|
|
642
|
+
videoOnDefault: null != (_this__config_videoConfig_videoOnDefault = null == (_this__config_videoConfig = this._config.videoConfig) ? void 0 : _this__config_videoConfig.videoOnDefault) ? _this__config_videoConfig_videoOnDefault : true,
|
|
643
|
+
isAutoSubscribeAudio: null != (_this__config_isAutoSubscribeAudio = this._config.isAutoSubscribeAudio) ? _this__config_isAutoSubscribeAudio : true
|
|
644
|
+
});
|
|
645
|
+
yield this._client.createLocalStream(roomInfo.uid, this._config.videoConfig);
|
|
646
|
+
this.isConnected = true;
|
|
647
|
+
this.dispatch(event_names.CONNECTED, {
|
|
648
|
+
roomId: roomInfo.room_id,
|
|
649
|
+
uid: roomInfo.uid,
|
|
650
|
+
token: roomInfo.token,
|
|
651
|
+
appId: roomInfo.app_id
|
|
652
|
+
});
|
|
653
|
+
}).call(this);
|
|
736
654
|
}
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.stop());
|
|
744
|
-
this.dispatch(event_names.INTERRUPTED, {});
|
|
745
|
-
}
|
|
746
|
-
/**
|
|
747
|
-
* en: Disconnect from the current session
|
|
748
|
-
*
|
|
749
|
-
* zh: 断开与当前会话的连接
|
|
750
|
-
*/ async disconnect() {
|
|
751
|
-
var _this__client;
|
|
752
|
-
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.disconnect());
|
|
753
|
-
this.isConnected = false;
|
|
754
|
-
this._client = null;
|
|
755
|
-
this.dispatch(event_names.DISCONNECTED, {});
|
|
756
|
-
}
|
|
757
|
-
/**
|
|
758
|
-
* en: Send a message to the bot
|
|
759
|
-
*
|
|
760
|
-
* zh: 发送消息给Bot
|
|
761
|
-
*/ async sendMessage(message) {
|
|
762
|
-
var _this__client;
|
|
763
|
-
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.sendMessage(message));
|
|
764
|
-
const eventType = 'string' == typeof message.event_type ? message.event_type : 'unknown_event';
|
|
765
|
-
this.dispatch(`client.${eventType}`, message);
|
|
766
|
-
}
|
|
767
|
-
/**
|
|
768
|
-
* en: Enable or disable audio
|
|
769
|
-
*
|
|
770
|
-
* zh: 启用或禁用音频
|
|
771
|
-
*/ async setAudioEnable(isEnable) {
|
|
772
|
-
var _this__client;
|
|
773
|
-
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.changeAudioState(isEnable));
|
|
774
|
-
if (isEnable) this.dispatch(event_names.AUDIO_UNMUTED, {});
|
|
775
|
-
else this.dispatch(event_names.AUDIO_MUTED, {});
|
|
655
|
+
interrupt() {
|
|
656
|
+
return src_async_to_generator(function*() {
|
|
657
|
+
var _this__client;
|
|
658
|
+
yield null == (_this__client = this._client) ? void 0 : _this__client.stop();
|
|
659
|
+
this.dispatch(event_names.INTERRUPTED, {});
|
|
660
|
+
}).call(this);
|
|
776
661
|
}
|
|
777
|
-
|
|
778
|
-
|
|
662
|
+
disconnect() {
|
|
663
|
+
return src_async_to_generator(function*() {
|
|
779
664
|
var _this__client;
|
|
780
|
-
|
|
781
|
-
this.
|
|
782
|
-
|
|
783
|
-
this.dispatch(event_names.
|
|
784
|
-
|
|
785
|
-
|
|
665
|
+
yield null == (_this__client = this._client) ? void 0 : _this__client.disconnect();
|
|
666
|
+
this.isConnected = false;
|
|
667
|
+
this._client = null;
|
|
668
|
+
this.dispatch(event_names.DISCONNECTED, {});
|
|
669
|
+
}).call(this);
|
|
670
|
+
}
|
|
671
|
+
sendMessage(message) {
|
|
672
|
+
return src_async_to_generator(function*() {
|
|
673
|
+
var _this__client;
|
|
674
|
+
yield null == (_this__client = this._client) ? void 0 : _this__client.sendMessage(message);
|
|
675
|
+
const eventType = 'string' == typeof message.event_type ? message.event_type : 'unknown_event';
|
|
676
|
+
this.dispatch(`client.${eventType}`, message);
|
|
677
|
+
}).call(this);
|
|
678
|
+
}
|
|
679
|
+
setAudioEnable(isEnable) {
|
|
680
|
+
return src_async_to_generator(function*() {
|
|
681
|
+
var _this__client;
|
|
682
|
+
yield null == (_this__client = this._client) ? void 0 : _this__client.changeAudioState(isEnable);
|
|
683
|
+
if (isEnable) this.dispatch(event_names.AUDIO_UNMUTED, {});
|
|
684
|
+
else this.dispatch(event_names.AUDIO_MUTED, {});
|
|
685
|
+
}).call(this);
|
|
686
|
+
}
|
|
687
|
+
setVideoEnable(isEnable) {
|
|
688
|
+
return src_async_to_generator(function*() {
|
|
689
|
+
try {
|
|
690
|
+
var _this__client;
|
|
691
|
+
yield null == (_this__client = this._client) ? void 0 : _this__client.changeVideoState(isEnable);
|
|
692
|
+
this.dispatch(isEnable ? event_names.VIDEO_ON : event_names.VIDEO_OFF, {});
|
|
693
|
+
} catch (e) {
|
|
694
|
+
this.dispatch(event_names.VIDEO_ERROR, e);
|
|
695
|
+
throw e;
|
|
696
|
+
}
|
|
697
|
+
}).call(this);
|
|
786
698
|
}
|
|
787
|
-
|
|
788
|
-
* en: Enable audio properties reporting (debug mode only)
|
|
789
|
-
*
|
|
790
|
-
* zh: 启用音频属性报告(仅限调试模式)
|
|
791
|
-
*/ enableAudioPropertiesReport(config) {
|
|
699
|
+
enableAudioPropertiesReport(config) {
|
|
792
700
|
if (this._config.debug) {
|
|
793
701
|
var _this__client;
|
|
794
|
-
null
|
|
702
|
+
null == (_this__client = this._client) || _this__client.enableAudioPropertiesReport(config);
|
|
795
703
|
return true;
|
|
796
704
|
}
|
|
797
705
|
console.warn('enableAudioPropertiesReport is not supported in non-debug mode');
|
|
798
706
|
return false;
|
|
799
707
|
}
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
}
|
|
810
|
-
/**
|
|
811
|
-
* en: Stop audio playback device test (debug mode only)
|
|
812
|
-
*
|
|
813
|
-
* zh: 停止音频播放设备测试(仅限调试模式)
|
|
814
|
-
*/ stopAudioPlaybackDeviceTest() {
|
|
708
|
+
startAudioPlaybackDeviceTest() {
|
|
709
|
+
return src_async_to_generator(function*() {
|
|
710
|
+
if (this._config.debug) {
|
|
711
|
+
var _this__client;
|
|
712
|
+
yield null == (_this__client = this._client) ? void 0 : _this__client.startAudioPlaybackDeviceTest();
|
|
713
|
+
} else console.warn('startAudioPlaybackDeviceTest is not supported in non-debug mode');
|
|
714
|
+
}).call(this);
|
|
715
|
+
}
|
|
716
|
+
stopAudioPlaybackDeviceTest() {
|
|
815
717
|
if (this._config.debug) {
|
|
816
718
|
var _this__client;
|
|
817
|
-
null
|
|
719
|
+
null == (_this__client = this._client) || _this__client.stopAudioPlaybackDeviceTest();
|
|
818
720
|
} else console.warn('stopAudioPlaybackDeviceTest is not supported in non-debug mode');
|
|
819
721
|
}
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
deviceId
|
|
829
|
-
});
|
|
830
|
-
}
|
|
831
|
-
/**
|
|
832
|
-
* en: Set the audio output device
|
|
833
|
-
*
|
|
834
|
-
* zh: 设置音频输出设备
|
|
835
|
-
*/ async setAudioOutputDevice(deviceId) {
|
|
836
|
-
var _this__client;
|
|
837
|
-
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setAudioOutputDevice(deviceId));
|
|
838
|
-
this.dispatch(event_names.AUDIO_OUTPUT_DEVICE_CHANGED, {
|
|
839
|
-
deviceId
|
|
840
|
-
});
|
|
722
|
+
setAudioInputDevice(deviceId) {
|
|
723
|
+
return src_async_to_generator(function*() {
|
|
724
|
+
var _this__client;
|
|
725
|
+
yield null == (_this__client = this._client) ? void 0 : _this__client.setAudioInputDevice(deviceId);
|
|
726
|
+
this.dispatch(event_names.AUDIO_INPUT_DEVICE_CHANGED, {
|
|
727
|
+
deviceId
|
|
728
|
+
});
|
|
729
|
+
}).call(this);
|
|
841
730
|
}
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
*
|
|
845
|
-
* zh: 设置视频输入设备
|
|
846
|
-
*/ async setVideoInputDevice(deviceId) {
|
|
847
|
-
try {
|
|
731
|
+
setAudioOutputDevice(deviceId) {
|
|
732
|
+
return src_async_to_generator(function*() {
|
|
848
733
|
var _this__client;
|
|
849
|
-
|
|
850
|
-
this.dispatch(event_names.
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
734
|
+
yield null == (_this__client = this._client) ? void 0 : _this__client.setAudioOutputDevice(deviceId);
|
|
735
|
+
this.dispatch(event_names.AUDIO_OUTPUT_DEVICE_CHANGED, {
|
|
736
|
+
deviceId
|
|
737
|
+
});
|
|
738
|
+
}).call(this);
|
|
739
|
+
}
|
|
740
|
+
setVideoInputDevice(deviceId) {
|
|
741
|
+
return src_async_to_generator(function*() {
|
|
742
|
+
try {
|
|
743
|
+
var _this__client;
|
|
744
|
+
yield null == (_this__client = this._client) ? void 0 : _this__client.setVideoInputDevice(deviceId);
|
|
745
|
+
this.dispatch(event_names.VIDEO_ON, {});
|
|
746
|
+
} catch (e) {
|
|
747
|
+
this.dispatch(event_names.VIDEO_ERROR, e);
|
|
748
|
+
throw e;
|
|
749
|
+
}
|
|
750
|
+
this.dispatch(event_names.VIDEO_INPUT_DEVICE_CHANGED, {
|
|
751
|
+
deviceId
|
|
752
|
+
});
|
|
753
|
+
}).call(this);
|
|
858
754
|
}
|
|
859
|
-
|
|
860
|
-
* en: Get the RTC engine instance, for detail visit https://www.volcengine.com/docs/6348/104481
|
|
861
|
-
*
|
|
862
|
-
* zh: 获取 RTC 引擎实例,详情请访问 https://www.volcengine.com/docs/6348/104481
|
|
863
|
-
*/ getRtcEngine() {
|
|
755
|
+
getRtcEngine() {
|
|
864
756
|
var _this__client;
|
|
865
|
-
return null
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
* Constructor for initializing a RealtimeClient instance.
|
|
869
|
-
*
|
|
870
|
-
* 构造函数,初始化RealtimeClient实例。
|
|
871
|
-
*
|
|
872
|
-
* @param config
|
|
873
|
-
* @param config.accessToken - Required, Access Token. |
|
|
874
|
-
* 必填,Access Token。
|
|
875
|
-
* @param config.botId - Required, Bot Id. |
|
|
876
|
-
* 必填,Bot Id。
|
|
877
|
-
* @param config.voiceId - Optional, Voice Id. |
|
|
878
|
-
* 可选,音色Id。
|
|
879
|
-
* @param config.conversationId - Optional, Conversation Id. |
|
|
880
|
-
* 可选,会话Id。
|
|
881
|
-
* @param config.userId - Optional, User Id. |
|
|
882
|
-
* 可选,用户Id。
|
|
883
|
-
* @param config.baseURL - Optional, defaults to "https://api.coze.cn". |
|
|
884
|
-
* 可选,默认值为 "https://api.coze.cn"。
|
|
885
|
-
* @param config.debug - Optional, defaults to false.
|
|
886
|
-
* 可选,默认值为 false。
|
|
887
|
-
* @param config.allowPersonalAccessTokenInBrowser
|
|
888
|
-
* - Optional, whether to allow personal access tokens in browser environment. |
|
|
889
|
-
* 可选,是否允许在浏览器环境中使用个人访问令牌。
|
|
890
|
-
* @param config.audioMutedDefault - Optional, whether audio is muted by default, defaults to false. |
|
|
891
|
-
* 可选,默认是否静音,默认值为 false。
|
|
892
|
-
* @param config.connectorId - Required, Connector Id. |
|
|
893
|
-
* 必填,渠道 Id。
|
|
894
|
-
* @param config.suppressStationaryNoise - Optional, suppress stationary noise, defaults to false. |
|
|
895
|
-
* 可选,默认是否抑制静态噪声,默认值为 false。
|
|
896
|
-
* @param config.suppressNonStationaryNoise - Optional, suppress non-stationary noise, defaults to false. |
|
|
897
|
-
* 可选,默认是否抑制非静态噪声,默认值为 false。
|
|
898
|
-
* @param config.isAutoSubscribeAudio - Optional, whether to automatically subscribe to bot reply audio streams, defaults to true. |
|
|
899
|
-
* @param config.videoConfig - Optional, Video configuration. |
|
|
900
|
-
* 可选,视频配置。
|
|
901
|
-
* @param config.videoConfig.videoOnDefault - Optional, Whether to turn on video by default, defaults to true. |
|
|
902
|
-
* 可选,默认是否开启视频,默认值为 true。
|
|
903
|
-
* @param config.videoConfig.renderDom - Optional, The DOM element to render the video stream to. |
|
|
904
|
-
* 可选,渲染视频流的 DOM 元素。
|
|
905
|
-
* @param config.videoConfig.videoInputDeviceId - Optional, The device ID of the video input device to use. |
|
|
906
|
-
* 可选,视频输入设备的设备 ID。
|
|
907
|
-
* @param config.videoConfig.screenConfig - Optional, Screen share configuration if videoInputDeviceId is 'screenShare' see https://www.volcengine.com/docs/6348/104481#screenconfig for more details. |
|
|
908
|
-
* 可选,屏幕共享配置,如果 videoInputDeviceId 是 'screenShare',请参考 https://www.volcengine.com/docs/6348/104481#screenconfig 了解更多详情。
|
|
909
|
-
* @param config.prologueContent - Optional, Prologue content. | 可选,开场白内容。
|
|
910
|
-
* @param config.roomMode - Optional, Room mode. | 可选,房间模式。
|
|
911
|
-
*/ constructor(config){
|
|
757
|
+
return null == (_this__client = this._client) ? void 0 : _this__client.getRtcEngine();
|
|
758
|
+
}
|
|
759
|
+
constructor(config){
|
|
912
760
|
super(config.debug), this._client = null, this.isConnected = false, this._isTestEnv = false, this._isSupportVideo = false;
|
|
913
761
|
this._config = config;
|
|
914
762
|
var _this__config_baseURL;
|
|
915
|
-
const defaultBaseURL = null
|
|
763
|
+
const defaultBaseURL = null != (_this__config_baseURL = this._config.baseURL) ? _this__config_baseURL : 'https://api.coze.cn';
|
|
916
764
|
this._config.baseURL = defaultBaseURL;
|
|
917
|
-
|
|
918
|
-
this._api = new __WEBPACK_EXTERNAL_MODULE__coze_api__.CozeAPI({
|
|
765
|
+
this._api = new CozeAPI({
|
|
919
766
|
token: this._config.accessToken,
|
|
920
767
|
baseURL: defaultBaseURL,
|
|
921
768
|
allowPersonalAccessTokenInBrowser: this._config.allowPersonalAccessTokenInBrowser
|