@coze/realtime-api 1.3.0 → 1.3.2-alpha.f7fe14

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