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