@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/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,253 +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";
|
|
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";
|
|
289
159
|
return EventNames;
|
|
290
160
|
}(event_names_EventNames || {});
|
|
291
|
-
|
|
161
|
+
const event_names = event_names_EventNames;
|
|
292
162
|
var error_RealtimeError = /*#__PURE__*/ function(RealtimeError) {
|
|
293
163
|
RealtimeError["DEVICE_ACCESS_ERROR"] = "DEVICE_ACCESS_ERROR";
|
|
294
164
|
RealtimeError["STREAM_CREATION_ERROR"] = "STREAM_CREATION_ERROR";
|
|
@@ -305,11 +175,7 @@ var error_RealtimeError = /*#__PURE__*/ function(RealtimeError) {
|
|
|
305
175
|
return RealtimeError;
|
|
306
176
|
}({});
|
|
307
177
|
class RealtimeAPIError extends Error {
|
|
308
|
-
|
|
309
|
-
* @param code - Error code
|
|
310
|
-
* @param message - Error message
|
|
311
|
-
* @param error - Error object
|
|
312
|
-
*/ constructor(code, message, error){
|
|
178
|
+
constructor(code, message, error){
|
|
313
179
|
super(`[${code}] ${message}`);
|
|
314
180
|
this.name = 'RealtimeAPIError';
|
|
315
181
|
this.code = code;
|
|
@@ -331,14 +197,10 @@ class RealtimeEventHandler {
|
|
|
331
197
|
const handlers = this.eventHandlers[eventName] || [];
|
|
332
198
|
if (callback) {
|
|
333
199
|
const index = handlers.indexOf(callback);
|
|
334
|
-
if (-1 === index) {
|
|
335
|
-
console.warn(`Could not turn off specified event listener for "${eventName}": not found as a listener`);
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
200
|
+
if (-1 === index) return void console.warn(`Could not turn off specified event listener for "${eventName}": not found as a listener`);
|
|
338
201
|
handlers.splice(index, 1);
|
|
339
202
|
} else delete this.eventHandlers[eventName];
|
|
340
203
|
}
|
|
341
|
-
// eslint-disable-next-line max-params
|
|
342
204
|
_dispatchToHandlers(eventName, event, handlers, prefix) {
|
|
343
205
|
for (const handler of handlers)if (!prefix || eventName.startsWith(prefix)) try {
|
|
344
206
|
handler(eventName, event);
|
|
@@ -346,8 +208,7 @@ class RealtimeEventHandler {
|
|
|
346
208
|
throw new RealtimeAPIError(error_RealtimeError.HANDLER_MESSAGE_ERROR, `Failed to handle message: ${eventName}`);
|
|
347
209
|
}
|
|
348
210
|
}
|
|
349
|
-
dispatch(eventName, event) {
|
|
350
|
-
let consoleLog = !(arguments.length > 2) || void 0 === arguments[2] || arguments[2];
|
|
211
|
+
dispatch(eventName, event, consoleLog = true) {
|
|
351
212
|
if (consoleLog) this._log(`dispatch ${eventName} event`, event);
|
|
352
213
|
const handlers = (this.eventHandlers[eventName] || []).slice();
|
|
353
214
|
this._dispatchToHandlers(eventName, event, handlers);
|
|
@@ -366,37 +227,62 @@ class RealtimeEventHandler {
|
|
|
366
227
|
this._debug = debug;
|
|
367
228
|
}
|
|
368
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
|
+
}
|
|
369
256
|
class EngineClient extends RealtimeEventHandler {
|
|
370
257
|
bindEngineEvents() {
|
|
371
|
-
this.engine.on(
|
|
372
|
-
this.engine.on(
|
|
373
|
-
this.engine.on(
|
|
374
|
-
this.engine.on(
|
|
375
|
-
this.engine.on(
|
|
376
|
-
this.engine.on(
|
|
377
|
-
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);
|
|
378
265
|
if (this._debug) {
|
|
379
|
-
this.engine.on(
|
|
380
|
-
this.engine.on(
|
|
266
|
+
this.engine.on(rtc.events.onLocalAudioPropertiesReport, this.handleLocalAudioPropertiesReport);
|
|
267
|
+
this.engine.on(rtc.events.onRemoteAudioPropertiesReport, this.handleRemoteAudioPropertiesReport);
|
|
381
268
|
}
|
|
382
269
|
}
|
|
383
270
|
removeEventListener() {
|
|
384
|
-
this.engine.off(
|
|
385
|
-
this.engine.off(
|
|
386
|
-
this.engine.off(
|
|
387
|
-
this.engine.off(
|
|
388
|
-
this.engine.off(
|
|
389
|
-
this.engine.off(
|
|
390
|
-
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);
|
|
391
278
|
if (this._debug) {
|
|
392
|
-
this.engine.off(
|
|
393
|
-
this.engine.off(
|
|
279
|
+
this.engine.off(rtc.events.onLocalAudioPropertiesReport, this.handleLocalAudioPropertiesReport);
|
|
280
|
+
this.engine.off(rtc.events.onRemoteAudioPropertiesReport, this.handleRemoteAudioPropertiesReport);
|
|
394
281
|
}
|
|
395
282
|
}
|
|
396
283
|
_parseMessage(event) {
|
|
397
284
|
try {
|
|
398
285
|
return JSON.parse(event.message);
|
|
399
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
400
286
|
} catch (e) {
|
|
401
287
|
throw new RealtimeAPIError(error_RealtimeError.PARSE_MESSAGE_ERROR, (null == e ? void 0 : e.message) || 'Unknown error');
|
|
402
288
|
}
|
|
@@ -437,176 +323,198 @@ class EngineClient extends RealtimeEventHandler {
|
|
|
437
323
|
downlinkNetworkQuality
|
|
438
324
|
});
|
|
439
325
|
}
|
|
440
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
441
326
|
handleTrackEnded(event) {
|
|
442
327
|
if ((null == event ? void 0 : event.kind) === 'video') this.dispatch(event_names.VIDEO_OFF, event);
|
|
443
328
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
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
|
|
453
357
|
});
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
}
|
|
457
|
-
}
|
|
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
|
-
if (isScreenShareDevice(deviceId)) {
|
|
484
|
-
if (this._streamIndex === __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN) this.engine.setLocalVideoPlayer(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN);
|
|
485
|
-
if (isAutoCapture) {
|
|
486
|
-
var _this__videoConfig1;
|
|
487
|
-
this.engine.setVideoSourceType(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_SCREEN, __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
|
|
488
|
-
await this.engine.startScreenCapture(null === (_this__videoConfig1 = this._videoConfig) || void 0 === _this__videoConfig1 ? void 0 : _this__videoConfig1.screenConfig);
|
|
489
|
-
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;
|
|
490
387
|
}
|
|
491
|
-
|
|
492
|
-
} else {
|
|
493
|
-
if (this._streamIndex === __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_SCREEN) this.engine.setLocalVideoPlayer(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_SCREEN);
|
|
494
|
-
if (isAutoCapture) await this.engine.startVideoCapture(deviceId);
|
|
495
|
-
this._streamIndex = __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN;
|
|
496
|
-
}
|
|
388
|
+
}).call(this);
|
|
497
389
|
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
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
|
-
|
|
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);
|
|
532
430
|
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
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();
|
|
536
434
|
else {
|
|
537
435
|
var _this__videoConfig;
|
|
538
|
-
this.engine.setVideoSourceType(
|
|
539
|
-
|
|
540
|
-
|
|
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);
|
|
541
439
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
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);
|
|
569
472
|
}
|
|
570
473
|
enableAudioPropertiesReport(config) {
|
|
571
474
|
this.engine.enableAudioPropertiesReport(config);
|
|
572
475
|
}
|
|
573
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
574
476
|
handleLocalAudioPropertiesReport(event) {
|
|
575
477
|
var _event__audioPropertiesInfo, _event_;
|
|
576
|
-
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);
|
|
577
479
|
}
|
|
578
480
|
handleRemoteAudioPropertiesReport(event) {
|
|
579
481
|
if (this._debug) console.log('handleRemoteAudioPropertiesReport', event);
|
|
580
482
|
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
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);
|
|
588
492
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
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);
|
|
593
499
|
}
|
|
594
500
|
changeAIAnsExtension(enable) {
|
|
595
501
|
if (enable) {
|
|
596
502
|
var _this__AIAnsExtension;
|
|
597
|
-
null
|
|
503
|
+
null == (_this__AIAnsExtension = this._AIAnsExtension) || _this__AIAnsExtension.enable();
|
|
598
504
|
} else {
|
|
599
505
|
var _this__AIAnsExtension1;
|
|
600
|
-
null
|
|
506
|
+
null == (_this__AIAnsExtension1 = this._AIAnsExtension) || _this__AIAnsExtension1.disable();
|
|
601
507
|
}
|
|
602
508
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
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);
|
|
610
518
|
}
|
|
611
519
|
stopAudioPlaybackDeviceTest() {
|
|
612
520
|
try {
|
|
@@ -619,13 +527,13 @@ class EngineClient extends RealtimeEventHandler {
|
|
|
619
527
|
getRtcEngine() {
|
|
620
528
|
return this.engine;
|
|
621
529
|
}
|
|
622
|
-
// eslint-disable-next-line max-params
|
|
623
530
|
constructor(appId, debug = false, isTestEnv = false, isSupportVideo = false, videoConfig){
|
|
624
531
|
super(debug), this.joinUserId = '', this._AIAnsExtension = null, this._isSupportVideo = false;
|
|
625
|
-
if (isTestEnv)
|
|
532
|
+
if (isTestEnv) rtc.setParameter('ICE_CONFIG_REQUEST_URLS', [
|
|
626
533
|
'rtc-test.bytedance.com'
|
|
627
534
|
]);
|
|
628
|
-
|
|
535
|
+
else localStorage.removeItem('RTC_ACCESS_URLS-VolcEngine');
|
|
536
|
+
this.engine = rtc.createEngine(appId);
|
|
629
537
|
this.handleMessage = this.handleMessage.bind(this);
|
|
630
538
|
this.handleUserJoin = this.handleUserJoin.bind(this);
|
|
631
539
|
this.handleUserLeave = this.handleUserLeave.bind(this);
|
|
@@ -633,282 +541,228 @@ class EngineClient extends RealtimeEventHandler {
|
|
|
633
541
|
this.handlePlayerEvent = this.handlePlayerEvent.bind(this);
|
|
634
542
|
this.handleNetworkQuality = this.handleNetworkQuality.bind(this);
|
|
635
543
|
this.handleTrackEnded = this.handleTrackEnded.bind(this);
|
|
636
|
-
// Debug only
|
|
637
544
|
this.handleLocalAudioPropertiesReport = this.handleLocalAudioPropertiesReport.bind(this);
|
|
638
545
|
this.handleRemoteAudioPropertiesReport = this.handleRemoteAudioPropertiesReport.bind(this);
|
|
639
546
|
this._isSupportVideo = isSupportVideo;
|
|
640
547
|
this._videoConfig = videoConfig;
|
|
641
548
|
}
|
|
642
549
|
}
|
|
643
|
-
|
|
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
|
+
}
|
|
644
576
|
const TEST_APP_ID = '6705332c79516e015e3e5f0c';
|
|
645
577
|
class RealtimeClient extends RealtimeEventHandler {
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
const config = {};
|
|
660
|
-
if (this._config.prologueContent) config.prologue_content = this._config.prologueContent;
|
|
661
|
-
if (void 0 !== this._config.roomMode && null !== this._config.roomMode) config.room_mode = this._config.roomMode;
|
|
662
|
-
if (this._config.videoConfig) {
|
|
663
|
-
if (isScreenShareDevice(this._config.videoConfig.videoInputDeviceId)) config.video_config = {
|
|
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 = {
|
|
664
591
|
stream_video_type: 'screen'
|
|
665
592
|
};
|
|
666
593
|
else config.video_config = {
|
|
667
594
|
stream_video_type: 'main'
|
|
668
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);
|
|
669
608
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
voice_id: voiceId && voiceId.length > 0 ? voiceId : void 0,
|
|
674
|
-
connector_id: this._config.connectorId,
|
|
675
|
-
uid: this._config.userId || void 0,
|
|
676
|
-
workflow_id: this._config.workflowId || void 0,
|
|
677
|
-
config
|
|
678
|
-
});
|
|
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);
|
|
679
612
|
}
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
this.
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
this._client.
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
// step6 set connected and dispatch connected event
|
|
722
|
-
this.isConnected = true;
|
|
723
|
-
this.dispatch(event_names.CONNECTED, {
|
|
724
|
-
roomId: roomInfo.room_id,
|
|
725
|
-
uid: roomInfo.uid,
|
|
726
|
-
token: roomInfo.token,
|
|
727
|
-
appId: roomInfo.app_id
|
|
728
|
-
});
|
|
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);
|
|
729
654
|
}
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.stop());
|
|
737
|
-
this.dispatch(event_names.INTERRUPTED, {});
|
|
738
|
-
}
|
|
739
|
-
/**
|
|
740
|
-
* en: Disconnect from the current session
|
|
741
|
-
*
|
|
742
|
-
* zh: 断开与当前会话的连接
|
|
743
|
-
*/ async disconnect() {
|
|
744
|
-
var _this__client;
|
|
745
|
-
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.disconnect());
|
|
746
|
-
this.isConnected = false;
|
|
747
|
-
this._client = null;
|
|
748
|
-
this.dispatch(event_names.DISCONNECTED, {});
|
|
749
|
-
}
|
|
750
|
-
/**
|
|
751
|
-
* en: Send a message to the bot
|
|
752
|
-
*
|
|
753
|
-
* zh: 发送消息给Bot
|
|
754
|
-
*/ async sendMessage(message) {
|
|
755
|
-
var _this__client;
|
|
756
|
-
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.sendMessage(message));
|
|
757
|
-
const eventType = 'string' == typeof message.event_type ? message.event_type : 'unknown_event';
|
|
758
|
-
this.dispatch(`client.${eventType}`, message);
|
|
759
|
-
}
|
|
760
|
-
/**
|
|
761
|
-
* en: Enable or disable audio
|
|
762
|
-
*
|
|
763
|
-
* zh: 启用或禁用音频
|
|
764
|
-
*/ async setAudioEnable(isEnable) {
|
|
765
|
-
var _this__client;
|
|
766
|
-
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.changeAudioState(isEnable));
|
|
767
|
-
if (isEnable) this.dispatch(event_names.AUDIO_UNMUTED, {});
|
|
768
|
-
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);
|
|
769
661
|
}
|
|
770
|
-
|
|
771
|
-
|
|
662
|
+
disconnect() {
|
|
663
|
+
return src_async_to_generator(function*() {
|
|
772
664
|
var _this__client;
|
|
773
|
-
|
|
774
|
-
this.
|
|
775
|
-
|
|
776
|
-
this.dispatch(event_names.
|
|
777
|
-
|
|
778
|
-
|
|
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);
|
|
779
678
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
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);
|
|
698
|
+
}
|
|
699
|
+
enableAudioPropertiesReport(config) {
|
|
785
700
|
if (this._config.debug) {
|
|
786
701
|
var _this__client;
|
|
787
|
-
null
|
|
702
|
+
null == (_this__client = this._client) || _this__client.enableAudioPropertiesReport(config);
|
|
788
703
|
return true;
|
|
789
704
|
}
|
|
790
705
|
console.warn('enableAudioPropertiesReport is not supported in non-debug mode');
|
|
791
706
|
return false;
|
|
792
707
|
}
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
}
|
|
803
|
-
/**
|
|
804
|
-
* en: Stop audio playback device test (debug mode only)
|
|
805
|
-
*
|
|
806
|
-
* zh: 停止音频播放设备测试(仅限调试模式)
|
|
807
|
-
*/ 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() {
|
|
808
717
|
if (this._config.debug) {
|
|
809
718
|
var _this__client;
|
|
810
|
-
null
|
|
719
|
+
null == (_this__client = this._client) || _this__client.stopAudioPlaybackDeviceTest();
|
|
811
720
|
} else console.warn('stopAudioPlaybackDeviceTest is not supported in non-debug mode');
|
|
812
721
|
}
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
deviceId
|
|
822
|
-
});
|
|
823
|
-
}
|
|
824
|
-
/**
|
|
825
|
-
* en: Set the audio output device
|
|
826
|
-
*
|
|
827
|
-
* zh: 设置音频输出设备
|
|
828
|
-
*/ async setAudioOutputDevice(deviceId) {
|
|
829
|
-
var _this__client;
|
|
830
|
-
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setAudioOutputDevice(deviceId));
|
|
831
|
-
this.dispatch(event_names.AUDIO_OUTPUT_DEVICE_CHANGED, {
|
|
832
|
-
deviceId
|
|
833
|
-
});
|
|
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);
|
|
834
730
|
}
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
*
|
|
838
|
-
* zh: 设置视频输入设备
|
|
839
|
-
*/ async setVideoInputDevice(deviceId) {
|
|
840
|
-
try {
|
|
731
|
+
setAudioOutputDevice(deviceId) {
|
|
732
|
+
return src_async_to_generator(function*() {
|
|
841
733
|
var _this__client;
|
|
842
|
-
|
|
843
|
-
this.dispatch(event_names.
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
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);
|
|
851
754
|
}
|
|
852
|
-
|
|
853
|
-
* en: Get the RTC engine instance, for detail visit https://www.volcengine.com/docs/6348/104481
|
|
854
|
-
*
|
|
855
|
-
* zh: 获取 RTC 引擎实例,详情请访问 https://www.volcengine.com/docs/6348/104481
|
|
856
|
-
*/ getRtcEngine() {
|
|
755
|
+
getRtcEngine() {
|
|
857
756
|
var _this__client;
|
|
858
|
-
return null
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
* Constructor for initializing a RealtimeClient instance.
|
|
862
|
-
*
|
|
863
|
-
* 构造函数,初始化RealtimeClient实例。
|
|
864
|
-
*
|
|
865
|
-
* @param config
|
|
866
|
-
* @param config.accessToken - Required, Access Token. |
|
|
867
|
-
* 必填,Access Token。
|
|
868
|
-
* @param config.botId - Required, Bot Id. |
|
|
869
|
-
* 必填,Bot Id。
|
|
870
|
-
* @param config.voiceId - Optional, Voice Id. |
|
|
871
|
-
* 可选,音色Id。
|
|
872
|
-
* @param config.conversationId - Optional, Conversation Id. |
|
|
873
|
-
* 可选,会话Id。
|
|
874
|
-
* @param config.userId - Optional, User Id. |
|
|
875
|
-
* 可选,用户Id。
|
|
876
|
-
* @param config.baseURL - Optional, defaults to "https://api.coze.cn". |
|
|
877
|
-
* 可选,默认值为 "https://api.coze.cn"。
|
|
878
|
-
* @param config.debug - Optional, defaults to false.
|
|
879
|
-
* 可选,默认值为 false。
|
|
880
|
-
* @param config.allowPersonalAccessTokenInBrowser
|
|
881
|
-
* - Optional, whether to allow personal access tokens in browser environment. |
|
|
882
|
-
* 可选,是否允许在浏览器环境中使用个人访问令牌。
|
|
883
|
-
* @param config.audioMutedDefault - Optional, whether audio is muted by default, defaults to false. |
|
|
884
|
-
* 可选,默认是否静音,默认值为 false。
|
|
885
|
-
* @param config.connectorId - Required, Connector Id. |
|
|
886
|
-
* 必填,渠道 Id。
|
|
887
|
-
* @param config.suppressStationaryNoise - Optional, suppress stationary noise, defaults to false. |
|
|
888
|
-
* 可选,默认是否抑制静态噪声,默认值为 false。
|
|
889
|
-
* @param config.suppressNonStationaryNoise - Optional, suppress non-stationary noise, defaults to false. |
|
|
890
|
-
* 可选,默认是否抑制非静态噪声,默认值为 false。
|
|
891
|
-
* @param config.isAutoSubscribeAudio - Optional, whether to automatically subscribe to bot reply audio streams, defaults to true. |
|
|
892
|
-
* @param config.videoConfig - Optional, Video configuration. |
|
|
893
|
-
* 可选,视频配置。
|
|
894
|
-
* @param config.videoConfig.videoOnDefault - Optional, Whether to turn on video by default, defaults to true. |
|
|
895
|
-
* 可选,默认是否开启视频,默认值为 true。
|
|
896
|
-
* @param config.videoConfig.renderDom - Optional, The DOM element to render the video stream to. |
|
|
897
|
-
* 可选,渲染视频流的 DOM 元素。
|
|
898
|
-
* @param config.videoConfig.videoInputDeviceId - Optional, The device ID of the video input device to use. |
|
|
899
|
-
* 可选,视频输入设备的设备 ID。
|
|
900
|
-
* @param config.videoConfig.screenConfig - Optional, Screen share configuration if videoInputDeviceId is 'screenShare' see https://www.volcengine.com/docs/6348/104481#screenconfig for more details. |
|
|
901
|
-
* 可选,屏幕共享配置,如果 videoInputDeviceId 是 'screenShare',请参考 https://www.volcengine.com/docs/6348/104481#screenconfig 了解更多详情。
|
|
902
|
-
* @param config.prologueContent - Optional, Prologue content. | 可选,开场白内容。
|
|
903
|
-
* @param config.roomMode - Optional, Room mode. | 可选,房间模式。
|
|
904
|
-
*/ constructor(config){
|
|
757
|
+
return null == (_this__client = this._client) ? void 0 : _this__client.getRtcEngine();
|
|
758
|
+
}
|
|
759
|
+
constructor(config){
|
|
905
760
|
super(config.debug), this._client = null, this.isConnected = false, this._isTestEnv = false, this._isSupportVideo = false;
|
|
906
761
|
this._config = config;
|
|
907
762
|
var _this__config_baseURL;
|
|
908
|
-
const defaultBaseURL = null
|
|
763
|
+
const defaultBaseURL = null != (_this__config_baseURL = this._config.baseURL) ? _this__config_baseURL : 'https://api.coze.cn';
|
|
909
764
|
this._config.baseURL = defaultBaseURL;
|
|
910
|
-
|
|
911
|
-
this._api = new __WEBPACK_EXTERNAL_MODULE__coze_api__.CozeAPI({
|
|
765
|
+
this._api = new CozeAPI({
|
|
912
766
|
token: this._config.accessToken,
|
|
913
767
|
baseURL: defaultBaseURL,
|
|
914
768
|
allowPersonalAccessTokenInBrowser: this._config.allowPersonalAccessTokenInBrowser
|