@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/dist/esm/index.js CHANGED
@@ -1,27 +1,20 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE__coze_api__ from "@coze/api";
2
- import * as __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__ from "@volcengine/rtc";
3
- import * as __WEBPACK_EXTERNAL_MODULE__volcengine_rtc_extension_ainr__ from "@volcengine/rtc/extension-ainr";
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 = function(exports, definition) {
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 = function(obj, prop) {
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
- // define __esModule on exports
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
- const result = await __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].enableDevices({
61
- audio,
62
- video
63
- });
64
- return result.audio;
39
+ var info = gen[key](arg);
40
+ var value = info.value;
65
41
  } catch (error) {
66
- console.error('Failed to check device permissions:', error);
67
- return false;
42
+ reject(error);
43
+ return;
68
44
  }
69
- };
70
- /**
71
- * Checks device permissions for audio and video
72
- * @param checkVideo Whether to check video permissions (default: false)
73
- * @returns Promise that resolves with the device permission status
74
- */ const checkDevicePermission = async function() {
75
- let checkVideo = arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
76
- return await __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].enableDevices({
77
- audio: true,
78
- video: checkVideo
79
- });
80
- };
81
- /**
82
- * Get audio devices
83
- * @returns Promise<AudioDevices> Object containing arrays of audio input and output devices
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 === (_navigator = navigator) || void 0 === _navigator ? void 0 : null === (_navigator_mediaDevices = _navigator.mediaDevices) || void 0 === _navigator_mediaDevices ? void 0 : _navigator_mediaDevices.getDisplayMedia);
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
- * en: All events
127
- * zh: 所有事件
128
- */ EventNames["ALL"] = "realtime.event";
129
- /**
130
- * en: All client events
131
- * zh: 所有客户端事件
132
- */ EventNames["ALL_CLIENT"] = "client.*";
133
- /**
134
- * en: All server events
135
- * zh: 所有服务端事件
136
- */ EventNames["ALL_SERVER"] = "server.*";
137
- /**
138
- * en: Room info
139
- * zh: 房间信息
140
- */ EventNames["ROOM_INFO"] = "client.room.info";
141
- /**
142
- * en: Client connected
143
- * zh: 客户端连接
144
- */ EventNames["CONNECTED"] = "client.connected";
145
- /**
146
- * en: Client connecting
147
- * zh: 客户端连接中
148
- */ EventNames["CONNECTING"] = "client.connecting";
149
- /**
150
- * en: Client interrupted
151
- * zh: 客户端中断
152
- */ EventNames["INTERRUPTED"] = "client.interrupted";
153
- /**
154
- * en: Client disconnected
155
- * zh: 客户端断开
156
- */ EventNames["DISCONNECTED"] = "client.disconnected";
157
- /**
158
- * en: Client audio unmuted
159
- * zh: 客户端音频未静音
160
- */ EventNames["AUDIO_UNMUTED"] = "client.audio.unmuted";
161
- /**
162
- * en: Client audio muted
163
- * zh: 客户端音频静音
164
- */ EventNames["AUDIO_MUTED"] = "client.audio.muted";
165
- /**
166
- * en: Client video on
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
- /* ESM default export */ const event_names = event_names_EventNames;
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(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onUserMessageReceived, this.handleMessage);
372
- this.engine.on(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onUserJoined, this.handleUserJoin);
373
- this.engine.on(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onUserLeave, this.handleUserLeave);
374
- this.engine.on(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onError, this.handleEventError);
375
- this.engine.on(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onNetworkQuality, this.handleNetworkQuality);
376
- this.engine.on(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onTrackEnded, this.handleTrackEnded);
377
- if (this._isSupportVideo) this.engine.on(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onPlayerEvent, this.handlePlayerEvent);
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(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onLocalAudioPropertiesReport, this.handleLocalAudioPropertiesReport);
380
- this.engine.on(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onRemoteAudioPropertiesReport, this.handleRemoteAudioPropertiesReport);
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(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onUserMessageReceived, this.handleMessage);
385
- this.engine.off(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onUserJoined, this.handleUserJoin);
386
- this.engine.off(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onUserLeave, this.handleUserLeave);
387
- this.engine.off(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onError, this.handleEventError);
388
- this.engine.off(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onNetworkQuality, this.handleNetworkQuality);
389
- this.engine.off(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onTrackEnded, this.handleTrackEnded);
390
- if (this._isSupportVideo) this.engine.off(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onPlayerEvent, this.handlePlayerEvent);
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(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onLocalAudioPropertiesReport, this.handleLocalAudioPropertiesReport);
393
- this.engine.off(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onRemoteAudioPropertiesReport, this.handleRemoteAudioPropertiesReport);
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
- async joinRoom(options) {
445
- const { token, roomId, uid, audioMutedDefault, videoOnDefault, isAutoSubscribeAudio } = options;
446
- try {
447
- await this.engine.joinRoom(token, roomId, {
448
- userId: uid
449
- }, {
450
- isAutoPublish: !audioMutedDefault,
451
- isAutoSubscribeAudio,
452
- isAutoSubscribeVideo: this._isSupportVideo && videoOnDefault
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
- } catch (e) {
455
- if (e instanceof Error) throw new RealtimeAPIError(error_RealtimeError.CONNECTION_ERROR, e.message);
456
- }
457
- }
458
- async setAudioInputDevice(deviceId) {
459
- const devices = await getAudioDevices();
460
- if (-1 === devices.audioInputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Audio input device not found: ${deviceId}`);
461
- this.engine.stopAudioCapture();
462
- await this.engine.startAudioCapture(deviceId);
463
- }
464
- async setAudioOutputDevice(deviceId) {
465
- const devices = await getAudioDevices({
466
- video: false
467
- });
468
- if (-1 === devices.audioOutputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Audio output device not found: ${deviceId}`);
469
- await this.engine.setAudioPlaybackDevice(deviceId);
470
- }
471
- async setVideoInputDevice(deviceId) {
472
- let isAutoCapture = !(arguments.length > 1) || void 0 === arguments[1] || arguments[1];
473
- var _this__videoConfig;
474
- const devices = await getAudioDevices({
475
- video: true
476
- });
477
- if (!isMobileVideoDevice(deviceId) && -1 === devices.videoInputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Video input device not found: ${deviceId}`);
478
- this.engine.setLocalVideoPlayer(isScreenShareDevice(deviceId) ? __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_SCREEN : __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN, {
479
- renderDom: (null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.renderDom) || 'local-player',
480
- userId: this._roomUserId
481
- });
482
- await this.changeVideoState(false);
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
- this._streamIndex = __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_SCREEN;
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
- async createLocalStream(userId, videoConfig) {
499
- this._roomUserId = userId;
500
- const devices = await getAudioDevices({
501
- video: this._isSupportVideo
502
- });
503
- if (!devices.audioInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get audio devices');
504
- if (this._isSupportVideo && !devices.videoInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get video devices');
505
- await this.engine.startAudioCapture(devices.audioInputs[0].deviceId);
506
- if (this._isSupportVideo) try {
507
- await this.setVideoInputDevice((null == videoConfig ? void 0 : videoConfig.videoInputDeviceId) || devices.videoInputs[0].deviceId, null == videoConfig ? void 0 : videoConfig.videoOnDefault);
508
- this.dispatch((null == videoConfig ? void 0 : videoConfig.videoOnDefault) ? event_names.VIDEO_ON : event_names.VIDEO_OFF, {});
509
- } catch (e) {
510
- this.dispatch(event_names.VIDEO_ERROR, e);
511
- }
512
- }
513
- async disconnect() {
514
- try {
515
- await this.engine.leaveRoom();
516
- this.removeEventListener();
517
- this.clearEventHandlers();
518
- __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].destroyEngine(this.engine);
519
- } catch (e) {
520
- this.dispatch(event_names.ERROR, e);
521
- throw e;
522
- }
523
- }
524
- async changeAudioState(isMicOn) {
525
- try {
526
- if (isMicOn) await this.engine.publishStream(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.MediaType.AUDIO);
527
- else await this.engine.unpublishStream(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.MediaType.AUDIO);
528
- } catch (e) {
529
- this.dispatch(event_names.ERROR, e);
530
- throw e;
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
- async changeVideoState(isVideoOn) {
534
- if (isVideoOn) {
535
- if (this._streamIndex === __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN) await this.engine.startVideoCapture();
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(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_SCREEN, __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
539
- await this.engine.startScreenCapture(null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.screenConfig);
540
- await this.engine.publishScreen(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.MediaType.VIDEO);
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
- } else if (this._streamIndex === __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN) await this.engine.stopVideoCapture();
543
- else {
544
- await this.engine.stopScreenCapture();
545
- await this.engine.unpublishScreen(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.MediaType.VIDEO);
546
- }
547
- }
548
- async stop() {
549
- try {
550
- const result = await this.engine.sendUserMessage(this.joinUserId, JSON.stringify({
551
- id: 'event_1',
552
- event_type: 'conversation.chat.cancel',
553
- data: {}
554
- }));
555
- this._log(`interrupt ${this.joinUserId} ${result}`);
556
- } catch (e) {
557
- this.dispatch(event_names.ERROR, e);
558
- throw e;
559
- }
560
- }
561
- async sendMessage(message) {
562
- try {
563
- const result = await this.engine.sendUserMessage(this.joinUserId, JSON.stringify(message));
564
- this._log(`sendMessage ${this.joinUserId} ${JSON.stringify(message)} ${result}`);
565
- } catch (e) {
566
- this.dispatch(event_names.ERROR, e);
567
- throw e;
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 === (_event_ = event[0]) || void 0 === _event_ ? void 0 : null === (_event__audioPropertiesInfo = _event_.audioPropertiesInfo) || void 0 === _event__audioPropertiesInfo ? void 0 : _event__audioPropertiesInfo.linearVolume) > 0) console.log('handleLocalAudioPropertiesReport', event);
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
- async enableAudioNoiseReduction() {
582
- var _this_engine;
583
- await (null === (_this_engine = this.engine) || void 0 === _this_engine ? void 0 : _this_engine.setAudioCaptureConfig({
584
- noiseSuppression: true,
585
- echoCancellation: true,
586
- autoGainControl: true
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
- async initAIAnsExtension() {
590
- const AIAnsExtension = new __WEBPACK_EXTERNAL_MODULE__volcengine_rtc_extension_ainr__["default"]();
591
- await this.engine.registerExtension(AIAnsExtension);
592
- this._AIAnsExtension = AIAnsExtension;
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 === (_this__AIAnsExtension = this._AIAnsExtension) || void 0 === _this__AIAnsExtension || _this__AIAnsExtension.enable();
503
+ null == (_this__AIAnsExtension = this._AIAnsExtension) || _this__AIAnsExtension.enable();
598
504
  } else {
599
505
  var _this__AIAnsExtension1;
600
- null === (_this__AIAnsExtension1 = this._AIAnsExtension) || void 0 === _this__AIAnsExtension1 || _this__AIAnsExtension1.disable();
506
+ null == (_this__AIAnsExtension1 = this._AIAnsExtension) || _this__AIAnsExtension1.disable();
601
507
  }
602
508
  }
603
- async startAudioPlaybackDeviceTest() {
604
- try {
605
- await this.engine.startAudioPlaybackDeviceTest('audio-test.wav', 200);
606
- } catch (e) {
607
- this.dispatch(event_names.ERROR, e);
608
- throw e;
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) __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].setParameter('ICE_CONFIG_REQUEST_URLS', [
532
+ if (isTestEnv) rtc.setParameter('ICE_CONFIG_REQUEST_URLS', [
626
533
  'rtc-test.bytedance.com'
627
534
  ]);
628
- this.engine = __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].createEngine(appId);
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
- // Only use for test
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
- * en: Establish a connection to the Coze API and join the room
648
- *
649
- * zh: 建立与 Coze API 的连接并加入房间
650
- */ async connect() {
651
- var _this__config_videoConfig;
652
- const { botId, conversationId, voiceId, getRoomInfo } = this._config;
653
- this.dispatch(event_names.CONNECTING, {});
654
- let roomInfo;
655
- try {
656
- // Step1 get token
657
- if (getRoomInfo) roomInfo = await getRoomInfo();
658
- else {
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
- roomInfo = await this._api.audio.rooms.create({
671
- bot_id: botId,
672
- conversation_id: conversationId || void 0,
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
- } catch (error) {
681
- this.dispatch(event_names.ERROR, error);
682
- throw new RealtimeAPIError(error_RealtimeError.CREATE_ROOM_ERROR, error instanceof Error ? error.message : 'Unknown error', error);
683
- }
684
- this.dispatch(event_names.ROOM_INFO, {
685
- roomId: roomInfo.room_id,
686
- uid: roomInfo.uid,
687
- token: roomInfo.token,
688
- appId: roomInfo.app_id
689
- });
690
- this._isTestEnv = TEST_APP_ID === roomInfo.app_id;
691
- // Step2 create engine
692
- this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo, this._config.videoConfig);
693
- // Step3 bind engine events
694
- this._client.bindEngineEvents();
695
- this._client.on(event_names.ALL, (eventName, data)=>{
696
- this.dispatch(eventName, data, false);
697
- });
698
- if (this._config.suppressStationaryNoise) {
699
- await this._client.enableAudioNoiseReduction();
700
- this.dispatch(event_names.SUPPRESS_STATIONARY_NOISE, {});
701
- }
702
- if (this._config.suppressNonStationaryNoise) try {
703
- await this._client.initAIAnsExtension();
704
- this._client.changeAIAnsExtension(true);
705
- this.dispatch(event_names.SUPPRESS_NON_STATIONARY_NOISE, {});
706
- } catch (error) {
707
- console.warn('Config suppressNonStationaryNoise is not supported', error);
708
- }
709
- var _this__config_audioMutedDefault, _this__config_videoConfig_videoOnDefault, _this__config_isAutoSubscribeAudio;
710
- // Step4 join room
711
- await this._client.joinRoom({
712
- token: roomInfo.token,
713
- roomId: roomInfo.room_id,
714
- uid: roomInfo.uid,
715
- audioMutedDefault: null !== (_this__config_audioMutedDefault = this._config.audioMutedDefault) && void 0 !== _this__config_audioMutedDefault && _this__config_audioMutedDefault,
716
- videoOnDefault: null === (_this__config_videoConfig_videoOnDefault = null === (_this__config_videoConfig = this._config.videoConfig) || void 0 === _this__config_videoConfig ? void 0 : _this__config_videoConfig.videoOnDefault) || void 0 === _this__config_videoConfig_videoOnDefault || _this__config_videoConfig_videoOnDefault,
717
- isAutoSubscribeAudio: null === (_this__config_isAutoSubscribeAudio = this._config.isAutoSubscribeAudio) || void 0 === _this__config_isAutoSubscribeAudio || _this__config_isAutoSubscribeAudio
718
- });
719
- // Step5 create local stream
720
- await this._client.createLocalStream(roomInfo.uid, this._config.videoConfig);
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
- * en: Interrupt the current conversation
732
- *
733
- * zh: 中断当前对话
734
- */ async interrupt() {
735
- var _this__client;
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
- async setVideoEnable(isEnable) {
771
- try {
662
+ disconnect() {
663
+ return src_async_to_generator(function*() {
772
664
  var _this__client;
773
- await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.changeVideoState(isEnable));
774
- this.dispatch(isEnable ? event_names.VIDEO_ON : event_names.VIDEO_OFF, {});
775
- } catch (e) {
776
- this.dispatch(event_names.VIDEO_ERROR, e);
777
- throw e;
778
- }
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
- * en: Enable audio properties reporting (debug mode only)
782
- *
783
- * zh: 启用音频属性报告(仅限调试模式)
784
- */ enableAudioPropertiesReport(config) {
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 === (_this__client = this._client) || void 0 === _this__client || _this__client.enableAudioPropertiesReport(config);
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
- * en: Start audio playback device test (debug mode only)
795
- *
796
- * zh: 开始音频播放设备测试(仅限调试模式)
797
- */ async startAudioPlaybackDeviceTest() {
798
- if (this._config.debug) {
799
- var _this__client;
800
- await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.startAudioPlaybackDeviceTest());
801
- } else console.warn('startAudioPlaybackDeviceTest is not supported in non-debug mode');
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 === (_this__client = this._client) || void 0 === _this__client || _this__client.stopAudioPlaybackDeviceTest();
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
- * en: Set the audio input device
815
- *
816
- * zh: 设置音频输入设备
817
- */ async setAudioInputDevice(deviceId) {
818
- var _this__client;
819
- await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setAudioInputDevice(deviceId));
820
- this.dispatch(event_names.AUDIO_INPUT_DEVICE_CHANGED, {
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
- * en: Set the video input device
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
- await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setVideoInputDevice(deviceId));
843
- this.dispatch(event_names.VIDEO_ON, {});
844
- } catch (e) {
845
- this.dispatch(event_names.VIDEO_ERROR, e);
846
- throw e;
847
- }
848
- this.dispatch(event_names.VIDEO_INPUT_DEVICE_CHANGED, {
849
- deviceId
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 === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.getRtcEngine();
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 !== (_this__config_baseURL = this._config.baseURL) && void 0 !== _this__config_baseURL ? _this__config_baseURL : 'https://api.coze.cn';
763
+ const defaultBaseURL = null != (_this__config_baseURL = this._config.baseURL) ? _this__config_baseURL : 'https://api.coze.cn';
909
764
  this._config.baseURL = defaultBaseURL;
910
- // init api
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