@coze/realtime-api 1.1.1-beta.3 → 1.1.1-beta.4

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.
@@ -31,8 +31,8 @@ var __webpack_require__ = {};
31
31
  /************************************************************************/ var __webpack_exports__ = {};
32
32
  __webpack_require__.r(__webpack_exports__);
33
33
  __webpack_require__.d(__webpack_exports__, {
34
- EventNames: function() {
35
- return EventNames;
34
+ default: function() {
35
+ return __WEBPACK_DEFAULT_EXPORT__;
36
36
  }
37
37
  });
38
38
  var EventNames = /*#__PURE__*/ function(EventNames) {
@@ -149,7 +149,8 @@ var EventNames = /*#__PURE__*/ function(EventNames) {
149
149
  * zh: 会话更新
150
150
  */ EventNames["SESSION_UPDATE"] = "server.session.update";
151
151
  return EventNames;
152
- }({});
152
+ }(EventNames || {});
153
+ /* ESM default export */ const __WEBPACK_DEFAULT_EXPORT__ = EventNames;
153
154
  var __webpack_export_target__ = exports;
154
155
  for(var i in __webpack_exports__)__webpack_export_target__[i] = __webpack_exports__[i];
155
156
  if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
@@ -51,7 +51,7 @@ __webpack_require__.d(__webpack_exports__, {
51
51
  RealtimeAPIError: ()=>/* reexport */ RealtimeAPIError,
52
52
  RealtimeUtils: ()=>/* reexport */ utils_namespaceObject,
53
53
  RealtimeError: ()=>/* reexport */ error_RealtimeError,
54
- EventNames: ()=>/* reexport */ event_names_EventNames,
54
+ EventNames: ()=>/* reexport */ event_names,
55
55
  RealtimeClient: ()=>/* binding */ RealtimeClient
56
56
  });
57
57
  // NAMESPACE OBJECT: ./src/utils.ts
@@ -256,7 +256,8 @@ var event_names_EventNames = /*#__PURE__*/ function(EventNames) {
256
256
  * zh: 会话更新
257
257
  */ EventNames["SESSION_UPDATE"] = "server.session.update";
258
258
  return EventNames;
259
- }({});
259
+ }(event_names_EventNames || {});
260
+ /* ESM default export */ const event_names = event_names_EventNames;
260
261
  var error_RealtimeError = /*#__PURE__*/ function(RealtimeError) {
261
262
  RealtimeError["DEVICE_ACCESS_ERROR"] = "DEVICE_ACCESS_ERROR";
262
263
  RealtimeError["STREAM_CREATION_ERROR"] = "STREAM_CREATION_ERROR";
@@ -319,11 +320,11 @@ class RealtimeEventHandler {
319
320
  if (consoleLog) this._log(`dispatch ${eventName} event`, event);
320
321
  const handlers = (this.eventHandlers[eventName] || []).slice();
321
322
  this._dispatchToHandlers(eventName, event, handlers);
322
- const allHandlers = (this.eventHandlers[event_names_EventNames.ALL] || []).slice();
323
+ const allHandlers = (this.eventHandlers[event_names.ALL] || []).slice();
323
324
  this._dispatchToHandlers(eventName, event, allHandlers);
324
- const allClientHandlers = (this.eventHandlers[event_names_EventNames.ALL_CLIENT] || []).slice();
325
+ const allClientHandlers = (this.eventHandlers[event_names.ALL_CLIENT] || []).slice();
325
326
  this._dispatchToHandlers(eventName, event, allClientHandlers, 'client.');
326
- const allServerHandlers = (this.eventHandlers[event_names_EventNames.ALL_SERVER] || []).slice();
327
+ const allServerHandlers = (this.eventHandlers[event_names.ALL_SERVER] || []).slice();
327
328
  this._dispatchToHandlers(eventName, event, allServerHandlers, 'server.');
328
329
  }
329
330
  _log(message, event) {
@@ -375,32 +376,32 @@ class EngineClient extends RealtimeEventHandler {
375
376
  this.dispatch(`server.${message.event_type}`, message);
376
377
  } catch (e) {
377
378
  if (e instanceof RealtimeAPIError) {
378
- if (e.code === error_RealtimeError.PARSE_MESSAGE_ERROR) this.dispatch(event_names_EventNames.ERROR, {
379
+ if (e.code === error_RealtimeError.PARSE_MESSAGE_ERROR) this.dispatch(event_names.ERROR, {
379
380
  message: `Failed to parse message: ${event.message}`,
380
381
  error: e
381
382
  });
382
- else if (e.code === error_RealtimeError.HANDLER_MESSAGE_ERROR) this.dispatch(event_names_EventNames.ERROR, {
383
+ else if (e.code === error_RealtimeError.HANDLER_MESSAGE_ERROR) this.dispatch(event_names.ERROR, {
383
384
  message: `Failed to handle message: ${event.message}`,
384
385
  error: e
385
386
  });
386
- } else this.dispatch(event_names_EventNames.ERROR, e);
387
+ } else this.dispatch(event_names.ERROR, e);
387
388
  }
388
389
  }
389
390
  handleEventError(e) {
390
- this.dispatch(event_names_EventNames.ERROR, e);
391
+ this.dispatch(event_names.ERROR, e);
391
392
  }
392
393
  handleUserJoin(event) {
393
394
  this.joinUserId = event.userInfo.userId;
394
- this.dispatch(event_names_EventNames.BOT_JOIN, event);
395
+ this.dispatch(event_names.BOT_JOIN, event);
395
396
  }
396
397
  handleUserLeave(event) {
397
- this.dispatch(event_names_EventNames.BOT_LEAVE, event);
398
+ this.dispatch(event_names.BOT_LEAVE, event);
398
399
  }
399
400
  handlePlayerEvent(event) {
400
- this.dispatch(event_names_EventNames.PLAYER_EVENT, event);
401
+ this.dispatch(event_names.PLAYER_EVENT, event);
401
402
  }
402
403
  handleNetworkQuality(uplinkNetworkQuality, downlinkNetworkQuality) {
403
- this.dispatch(event_names_EventNames.NETWORK_QUALITY, {
404
+ this.dispatch(event_names.NETWORK_QUALITY, {
404
405
  uplinkNetworkQuality,
405
406
  downlinkNetworkQuality
406
407
  });
@@ -476,7 +477,7 @@ class EngineClient extends RealtimeEventHandler {
476
477
  this.clearEventHandlers();
477
478
  rtc_default().destroyEngine(this.engine);
478
479
  } catch (e) {
479
- this.dispatch(event_names_EventNames.ERROR, e);
480
+ this.dispatch(event_names.ERROR, e);
480
481
  throw e;
481
482
  }
482
483
  }
@@ -485,7 +486,7 @@ class EngineClient extends RealtimeEventHandler {
485
486
  if (isMicOn) await this.engine.publishStream(rtc_namespaceObject.MediaType.AUDIO);
486
487
  else await this.engine.unpublishStream(rtc_namespaceObject.MediaType.AUDIO);
487
488
  } catch (e) {
488
- this.dispatch(event_names_EventNames.ERROR, e);
489
+ this.dispatch(event_names.ERROR, e);
489
490
  throw e;
490
491
  }
491
492
  }
@@ -505,7 +506,7 @@ class EngineClient extends RealtimeEventHandler {
505
506
  await this.engine.unpublishScreen(rtc_namespaceObject.MediaType.VIDEO);
506
507
  }
507
508
  } catch (e) {
508
- this.dispatch(event_names_EventNames.ERROR, e);
509
+ this.dispatch(event_names.ERROR, e);
509
510
  throw e;
510
511
  }
511
512
  }
@@ -518,7 +519,7 @@ class EngineClient extends RealtimeEventHandler {
518
519
  }));
519
520
  this._log(`interrupt ${this.joinUserId} ${result}`);
520
521
  } catch (e) {
521
- this.dispatch(event_names_EventNames.ERROR, e);
522
+ this.dispatch(event_names.ERROR, e);
522
523
  throw e;
523
524
  }
524
525
  }
@@ -527,7 +528,7 @@ class EngineClient extends RealtimeEventHandler {
527
528
  const result = await this.engine.sendUserMessage(this.joinUserId, JSON.stringify(message));
528
529
  this._log(`sendMessage ${this.joinUserId} ${JSON.stringify(message)} ${result}`);
529
530
  } catch (e) {
530
- this.dispatch(event_names_EventNames.ERROR, e);
531
+ this.dispatch(event_names.ERROR, e);
531
532
  throw e;
532
533
  }
533
534
  }
@@ -568,7 +569,7 @@ class EngineClient extends RealtimeEventHandler {
568
569
  try {
569
570
  await this.engine.startAudioPlaybackDeviceTest('audio-test.wav', 200);
570
571
  } catch (e) {
571
- this.dispatch(event_names_EventNames.ERROR, e);
572
+ this.dispatch(event_names.ERROR, e);
572
573
  throw e;
573
574
  }
574
575
  }
@@ -576,7 +577,7 @@ class EngineClient extends RealtimeEventHandler {
576
577
  try {
577
578
  this.engine.stopAudioPlaybackDeviceTest();
578
579
  } catch (e) {
579
- this.dispatch(event_names_EventNames.ERROR, e);
580
+ this.dispatch(event_names.ERROR, e);
580
581
  throw e;
581
582
  }
582
583
  }
@@ -613,7 +614,7 @@ class RealtimeClient extends RealtimeEventHandler {
613
614
  */ async connect() {
614
615
  var _this__config_videoConfig;
615
616
  const { botId, conversationId, voiceId, getRoomInfo } = this._config;
616
- this.dispatch(event_names_EventNames.CONNECTING, {});
617
+ this.dispatch(event_names.CONNECTING, {});
617
618
  let roomInfo;
618
619
  try {
619
620
  // Step1 get token
@@ -640,7 +641,7 @@ class RealtimeClient extends RealtimeEventHandler {
640
641
  });
641
642
  }
642
643
  } catch (error) {
643
- this.dispatch(event_names_EventNames.ERROR, error);
644
+ this.dispatch(event_names.ERROR, error);
644
645
  throw new RealtimeAPIError(error_RealtimeError.CREATE_ROOM_ERROR, error instanceof Error ? error.message : 'Unknown error', error);
645
646
  }
646
647
  this._isTestEnv = TEST_APP_ID === roomInfo.app_id;
@@ -648,17 +649,17 @@ class RealtimeClient extends RealtimeEventHandler {
648
649
  this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo, this._config.videoConfig);
649
650
  // Step3 bind engine events
650
651
  this._client.bindEngineEvents();
651
- this._client.on(event_names_EventNames.ALL, (eventName, data)=>{
652
+ this._client.on(event_names.ALL, (eventName, data)=>{
652
653
  this.dispatch(eventName, data, false);
653
654
  });
654
655
  if (this._config.suppressStationaryNoise) {
655
656
  await this._client.enableAudioNoiseReduction();
656
- this.dispatch(event_names_EventNames.SUPPRESS_STATIONARY_NOISE, {});
657
+ this.dispatch(event_names.SUPPRESS_STATIONARY_NOISE, {});
657
658
  }
658
659
  if (this._config.suppressNonStationaryNoise) try {
659
660
  await this._client.initAIAnsExtension();
660
661
  this._client.changeAIAnsExtension(true);
661
- this.dispatch(event_names_EventNames.SUPPRESS_NON_STATIONARY_NOISE, {});
662
+ this.dispatch(event_names.SUPPRESS_NON_STATIONARY_NOISE, {});
662
663
  } catch (error) {
663
664
  console.warn('Config suppressNonStationaryNoise is not supported', error);
664
665
  }
@@ -676,7 +677,7 @@ class RealtimeClient extends RealtimeEventHandler {
676
677
  await this._client.createLocalStream(roomInfo.uid, this._config.videoConfig);
677
678
  // step6 set connected and dispatch connected event
678
679
  this.isConnected = true;
679
- this.dispatch(event_names_EventNames.CONNECTED, {
680
+ this.dispatch(event_names.CONNECTED, {
680
681
  roomId: roomInfo.room_id,
681
682
  uid: roomInfo.uid,
682
683
  token: roomInfo.token,
@@ -690,7 +691,7 @@ class RealtimeClient extends RealtimeEventHandler {
690
691
  */ async interrupt() {
691
692
  var _this__client;
692
693
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.stop());
693
- this.dispatch(event_names_EventNames.INTERRUPTED, {});
694
+ this.dispatch(event_names.INTERRUPTED, {});
694
695
  }
695
696
  /**
696
697
  * en: Disconnect from the current session
@@ -701,7 +702,7 @@ class RealtimeClient extends RealtimeEventHandler {
701
702
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.disconnect());
702
703
  this.isConnected = false;
703
704
  this._client = null;
704
- this.dispatch(event_names_EventNames.DISCONNECTED, {});
705
+ this.dispatch(event_names.DISCONNECTED, {});
705
706
  }
706
707
  /**
707
708
  * en: Send a message to the bot
@@ -720,14 +721,14 @@ class RealtimeClient extends RealtimeEventHandler {
720
721
  */ async setAudioEnable(isEnable) {
721
722
  var _this__client;
722
723
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.changeAudioState(isEnable));
723
- if (isEnable) this.dispatch(event_names_EventNames.AUDIO_UNMUTED, {});
724
- else this.dispatch(event_names_EventNames.AUDIO_MUTED, {});
724
+ if (isEnable) this.dispatch(event_names.AUDIO_UNMUTED, {});
725
+ else this.dispatch(event_names.AUDIO_MUTED, {});
725
726
  }
726
727
  async setVideoEnable(isEnable) {
727
728
  var _this__client;
728
729
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.changeVideoState(isEnable));
729
- if (isEnable) this.dispatch(event_names_EventNames.VIDEO_ON, {});
730
- else this.dispatch(event_names_EventNames.VIDEO_OFF, {});
730
+ if (isEnable) this.dispatch(event_names.VIDEO_ON, {});
731
+ else this.dispatch(event_names.VIDEO_OFF, {});
731
732
  }
732
733
  /**
733
734
  * en: Enable audio properties reporting (debug mode only)
@@ -769,7 +770,7 @@ class RealtimeClient extends RealtimeEventHandler {
769
770
  */ async setAudioInputDevice(deviceId) {
770
771
  var _this__client;
771
772
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setAudioInputDevice(deviceId));
772
- this.dispatch(event_names_EventNames.AUDIO_INPUT_DEVICE_CHANGED, {
773
+ this.dispatch(event_names.AUDIO_INPUT_DEVICE_CHANGED, {
773
774
  deviceId
774
775
  });
775
776
  }
@@ -780,14 +781,14 @@ class RealtimeClient extends RealtimeEventHandler {
780
781
  */ async setAudioOutputDevice(deviceId) {
781
782
  var _this__client;
782
783
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setAudioOutputDevice(deviceId));
783
- this.dispatch(event_names_EventNames.AUDIO_OUTPUT_DEVICE_CHANGED, {
784
+ this.dispatch(event_names.AUDIO_OUTPUT_DEVICE_CHANGED, {
784
785
  deviceId
785
786
  });
786
787
  }
787
788
  async setVideoInputDevice(deviceId) {
788
789
  var _this__client;
789
790
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setVideoInputDevice(deviceId));
790
- this.dispatch(event_names_EventNames.VIDEO_INPUT_DEVICE_CHANGED, {
791
+ this.dispatch(event_names.VIDEO_INPUT_DEVICE_CHANGED, {
791
792
  deviceId
792
793
  });
793
794
  }
@@ -112,5 +112,6 @@ var event_names_EventNames = /*#__PURE__*/ function(EventNames) {
112
112
  * zh: 会话更新
113
113
  */ EventNames["SESSION_UPDATE"] = "server.session.update";
114
114
  return EventNames;
115
- }({});
116
- export { event_names_EventNames as EventNames };
115
+ }(event_names_EventNames || {});
116
+ /* ESM default export */ const event_names = event_names_EventNames;
117
+ export { event_names as default };
@@ -229,7 +229,8 @@ var event_names_EventNames = /*#__PURE__*/ function(EventNames) {
229
229
  * zh: 会话更新
230
230
  */ EventNames["SESSION_UPDATE"] = "server.session.update";
231
231
  return EventNames;
232
- }({});
232
+ }(event_names_EventNames || {});
233
+ /* ESM default export */ const event_names = event_names_EventNames;
233
234
  var error_RealtimeError = /*#__PURE__*/ function(RealtimeError) {
234
235
  RealtimeError["DEVICE_ACCESS_ERROR"] = "DEVICE_ACCESS_ERROR";
235
236
  RealtimeError["STREAM_CREATION_ERROR"] = "STREAM_CREATION_ERROR";
@@ -292,11 +293,11 @@ class RealtimeEventHandler {
292
293
  if (consoleLog) this._log(`dispatch ${eventName} event`, event);
293
294
  const handlers = (this.eventHandlers[eventName] || []).slice();
294
295
  this._dispatchToHandlers(eventName, event, handlers);
295
- const allHandlers = (this.eventHandlers[event_names_EventNames.ALL] || []).slice();
296
+ const allHandlers = (this.eventHandlers[event_names.ALL] || []).slice();
296
297
  this._dispatchToHandlers(eventName, event, allHandlers);
297
- const allClientHandlers = (this.eventHandlers[event_names_EventNames.ALL_CLIENT] || []).slice();
298
+ const allClientHandlers = (this.eventHandlers[event_names.ALL_CLIENT] || []).slice();
298
299
  this._dispatchToHandlers(eventName, event, allClientHandlers, 'client.');
299
- const allServerHandlers = (this.eventHandlers[event_names_EventNames.ALL_SERVER] || []).slice();
300
+ const allServerHandlers = (this.eventHandlers[event_names.ALL_SERVER] || []).slice();
300
301
  this._dispatchToHandlers(eventName, event, allServerHandlers, 'server.');
301
302
  }
302
303
  _log(message, event) {
@@ -346,32 +347,32 @@ class EngineClient extends RealtimeEventHandler {
346
347
  this.dispatch(`server.${message.event_type}`, message);
347
348
  } catch (e) {
348
349
  if (e instanceof RealtimeAPIError) {
349
- if (e.code === error_RealtimeError.PARSE_MESSAGE_ERROR) this.dispatch(event_names_EventNames.ERROR, {
350
+ if (e.code === error_RealtimeError.PARSE_MESSAGE_ERROR) this.dispatch(event_names.ERROR, {
350
351
  message: `Failed to parse message: ${event.message}`,
351
352
  error: e
352
353
  });
353
- else if (e.code === error_RealtimeError.HANDLER_MESSAGE_ERROR) this.dispatch(event_names_EventNames.ERROR, {
354
+ else if (e.code === error_RealtimeError.HANDLER_MESSAGE_ERROR) this.dispatch(event_names.ERROR, {
354
355
  message: `Failed to handle message: ${event.message}`,
355
356
  error: e
356
357
  });
357
- } else this.dispatch(event_names_EventNames.ERROR, e);
358
+ } else this.dispatch(event_names.ERROR, e);
358
359
  }
359
360
  }
360
361
  handleEventError(e) {
361
- this.dispatch(event_names_EventNames.ERROR, e);
362
+ this.dispatch(event_names.ERROR, e);
362
363
  }
363
364
  handleUserJoin(event) {
364
365
  this.joinUserId = event.userInfo.userId;
365
- this.dispatch(event_names_EventNames.BOT_JOIN, event);
366
+ this.dispatch(event_names.BOT_JOIN, event);
366
367
  }
367
368
  handleUserLeave(event) {
368
- this.dispatch(event_names_EventNames.BOT_LEAVE, event);
369
+ this.dispatch(event_names.BOT_LEAVE, event);
369
370
  }
370
371
  handlePlayerEvent(event) {
371
- this.dispatch(event_names_EventNames.PLAYER_EVENT, event);
372
+ this.dispatch(event_names.PLAYER_EVENT, event);
372
373
  }
373
374
  handleNetworkQuality(uplinkNetworkQuality, downlinkNetworkQuality) {
374
- this.dispatch(event_names_EventNames.NETWORK_QUALITY, {
375
+ this.dispatch(event_names.NETWORK_QUALITY, {
375
376
  uplinkNetworkQuality,
376
377
  downlinkNetworkQuality
377
378
  });
@@ -447,7 +448,7 @@ class EngineClient extends RealtimeEventHandler {
447
448
  this.clearEventHandlers();
448
449
  __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].destroyEngine(this.engine);
449
450
  } catch (e) {
450
- this.dispatch(event_names_EventNames.ERROR, e);
451
+ this.dispatch(event_names.ERROR, e);
451
452
  throw e;
452
453
  }
453
454
  }
@@ -456,7 +457,7 @@ class EngineClient extends RealtimeEventHandler {
456
457
  if (isMicOn) await this.engine.publishStream(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.MediaType.AUDIO);
457
458
  else await this.engine.unpublishStream(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.MediaType.AUDIO);
458
459
  } catch (e) {
459
- this.dispatch(event_names_EventNames.ERROR, e);
460
+ this.dispatch(event_names.ERROR, e);
460
461
  throw e;
461
462
  }
462
463
  }
@@ -476,7 +477,7 @@ class EngineClient extends RealtimeEventHandler {
476
477
  await this.engine.unpublishScreen(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.MediaType.VIDEO);
477
478
  }
478
479
  } catch (e) {
479
- this.dispatch(event_names_EventNames.ERROR, e);
480
+ this.dispatch(event_names.ERROR, e);
480
481
  throw e;
481
482
  }
482
483
  }
@@ -489,7 +490,7 @@ class EngineClient extends RealtimeEventHandler {
489
490
  }));
490
491
  this._log(`interrupt ${this.joinUserId} ${result}`);
491
492
  } catch (e) {
492
- this.dispatch(event_names_EventNames.ERROR, e);
493
+ this.dispatch(event_names.ERROR, e);
493
494
  throw e;
494
495
  }
495
496
  }
@@ -498,7 +499,7 @@ class EngineClient extends RealtimeEventHandler {
498
499
  const result = await this.engine.sendUserMessage(this.joinUserId, JSON.stringify(message));
499
500
  this._log(`sendMessage ${this.joinUserId} ${JSON.stringify(message)} ${result}`);
500
501
  } catch (e) {
501
- this.dispatch(event_names_EventNames.ERROR, e);
502
+ this.dispatch(event_names.ERROR, e);
502
503
  throw e;
503
504
  }
504
505
  }
@@ -539,7 +540,7 @@ class EngineClient extends RealtimeEventHandler {
539
540
  try {
540
541
  await this.engine.startAudioPlaybackDeviceTest('audio-test.wav', 200);
541
542
  } catch (e) {
542
- this.dispatch(event_names_EventNames.ERROR, e);
543
+ this.dispatch(event_names.ERROR, e);
543
544
  throw e;
544
545
  }
545
546
  }
@@ -547,7 +548,7 @@ class EngineClient extends RealtimeEventHandler {
547
548
  try {
548
549
  this.engine.stopAudioPlaybackDeviceTest();
549
550
  } catch (e) {
550
- this.dispatch(event_names_EventNames.ERROR, e);
551
+ this.dispatch(event_names.ERROR, e);
551
552
  throw e;
552
553
  }
553
554
  }
@@ -584,7 +585,7 @@ class RealtimeClient extends RealtimeEventHandler {
584
585
  */ async connect() {
585
586
  var _this__config_videoConfig;
586
587
  const { botId, conversationId, voiceId, getRoomInfo } = this._config;
587
- this.dispatch(event_names_EventNames.CONNECTING, {});
588
+ this.dispatch(event_names.CONNECTING, {});
588
589
  let roomInfo;
589
590
  try {
590
591
  // Step1 get token
@@ -611,7 +612,7 @@ class RealtimeClient extends RealtimeEventHandler {
611
612
  });
612
613
  }
613
614
  } catch (error) {
614
- this.dispatch(event_names_EventNames.ERROR, error);
615
+ this.dispatch(event_names.ERROR, error);
615
616
  throw new RealtimeAPIError(error_RealtimeError.CREATE_ROOM_ERROR, error instanceof Error ? error.message : 'Unknown error', error);
616
617
  }
617
618
  this._isTestEnv = TEST_APP_ID === roomInfo.app_id;
@@ -619,17 +620,17 @@ class RealtimeClient extends RealtimeEventHandler {
619
620
  this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo, this._config.videoConfig);
620
621
  // Step3 bind engine events
621
622
  this._client.bindEngineEvents();
622
- this._client.on(event_names_EventNames.ALL, (eventName, data)=>{
623
+ this._client.on(event_names.ALL, (eventName, data)=>{
623
624
  this.dispatch(eventName, data, false);
624
625
  });
625
626
  if (this._config.suppressStationaryNoise) {
626
627
  await this._client.enableAudioNoiseReduction();
627
- this.dispatch(event_names_EventNames.SUPPRESS_STATIONARY_NOISE, {});
628
+ this.dispatch(event_names.SUPPRESS_STATIONARY_NOISE, {});
628
629
  }
629
630
  if (this._config.suppressNonStationaryNoise) try {
630
631
  await this._client.initAIAnsExtension();
631
632
  this._client.changeAIAnsExtension(true);
632
- this.dispatch(event_names_EventNames.SUPPRESS_NON_STATIONARY_NOISE, {});
633
+ this.dispatch(event_names.SUPPRESS_NON_STATIONARY_NOISE, {});
633
634
  } catch (error) {
634
635
  console.warn('Config suppressNonStationaryNoise is not supported', error);
635
636
  }
@@ -647,7 +648,7 @@ class RealtimeClient extends RealtimeEventHandler {
647
648
  await this._client.createLocalStream(roomInfo.uid, this._config.videoConfig);
648
649
  // step6 set connected and dispatch connected event
649
650
  this.isConnected = true;
650
- this.dispatch(event_names_EventNames.CONNECTED, {
651
+ this.dispatch(event_names.CONNECTED, {
651
652
  roomId: roomInfo.room_id,
652
653
  uid: roomInfo.uid,
653
654
  token: roomInfo.token,
@@ -661,7 +662,7 @@ class RealtimeClient extends RealtimeEventHandler {
661
662
  */ async interrupt() {
662
663
  var _this__client;
663
664
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.stop());
664
- this.dispatch(event_names_EventNames.INTERRUPTED, {});
665
+ this.dispatch(event_names.INTERRUPTED, {});
665
666
  }
666
667
  /**
667
668
  * en: Disconnect from the current session
@@ -672,7 +673,7 @@ class RealtimeClient extends RealtimeEventHandler {
672
673
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.disconnect());
673
674
  this.isConnected = false;
674
675
  this._client = null;
675
- this.dispatch(event_names_EventNames.DISCONNECTED, {});
676
+ this.dispatch(event_names.DISCONNECTED, {});
676
677
  }
677
678
  /**
678
679
  * en: Send a message to the bot
@@ -691,14 +692,14 @@ class RealtimeClient extends RealtimeEventHandler {
691
692
  */ async setAudioEnable(isEnable) {
692
693
  var _this__client;
693
694
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.changeAudioState(isEnable));
694
- if (isEnable) this.dispatch(event_names_EventNames.AUDIO_UNMUTED, {});
695
- else this.dispatch(event_names_EventNames.AUDIO_MUTED, {});
695
+ if (isEnable) this.dispatch(event_names.AUDIO_UNMUTED, {});
696
+ else this.dispatch(event_names.AUDIO_MUTED, {});
696
697
  }
697
698
  async setVideoEnable(isEnable) {
698
699
  var _this__client;
699
700
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.changeVideoState(isEnable));
700
- if (isEnable) this.dispatch(event_names_EventNames.VIDEO_ON, {});
701
- else this.dispatch(event_names_EventNames.VIDEO_OFF, {});
701
+ if (isEnable) this.dispatch(event_names.VIDEO_ON, {});
702
+ else this.dispatch(event_names.VIDEO_OFF, {});
702
703
  }
703
704
  /**
704
705
  * en: Enable audio properties reporting (debug mode only)
@@ -740,7 +741,7 @@ class RealtimeClient extends RealtimeEventHandler {
740
741
  */ async setAudioInputDevice(deviceId) {
741
742
  var _this__client;
742
743
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setAudioInputDevice(deviceId));
743
- this.dispatch(event_names_EventNames.AUDIO_INPUT_DEVICE_CHANGED, {
744
+ this.dispatch(event_names.AUDIO_INPUT_DEVICE_CHANGED, {
744
745
  deviceId
745
746
  });
746
747
  }
@@ -751,14 +752,14 @@ class RealtimeClient extends RealtimeEventHandler {
751
752
  */ async setAudioOutputDevice(deviceId) {
752
753
  var _this__client;
753
754
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setAudioOutputDevice(deviceId));
754
- this.dispatch(event_names_EventNames.AUDIO_OUTPUT_DEVICE_CHANGED, {
755
+ this.dispatch(event_names.AUDIO_OUTPUT_DEVICE_CHANGED, {
755
756
  deviceId
756
757
  });
757
758
  }
758
759
  async setVideoInputDevice(deviceId) {
759
760
  var _this__client;
760
761
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setVideoInputDevice(deviceId));
761
- this.dispatch(event_names_EventNames.VIDEO_INPUT_DEVICE_CHANGED, {
762
+ this.dispatch(event_names.VIDEO_INPUT_DEVICE_CHANGED, {
762
763
  deviceId
763
764
  });
764
765
  }
@@ -827,4 +828,4 @@ class RealtimeClient extends RealtimeEventHandler {
827
828
  this._isSupportVideo = !!config.videoConfig;
828
829
  }
829
830
  }
830
- export { event_names_EventNames as EventNames, RealtimeAPIError, RealtimeClient, error_RealtimeError as RealtimeError, utils_namespaceObject as RealtimeUtils };
831
+ export { event_names as EventNames, RealtimeAPIError, RealtimeClient, error_RealtimeError as RealtimeError, utils_namespaceObject as RealtimeUtils };
@@ -1,4 +1,4 @@
1
- export declare enum EventNames {
1
+ declare enum EventNames {
2
2
  /**
3
3
  * en: All events
4
4
  * zh: 所有事件
@@ -140,3 +140,4 @@ export declare enum EventNames {
140
140
  */
141
141
  SESSION_UPDATE = "server.session.update"
142
142
  }
143
+ export default EventNames;
@@ -1,7 +1,7 @@
1
1
  import { type ScreenConfig, type AudioPropertiesConfig, type IRTCEngine } from '@volcengine/rtc';
2
2
  import { type CreateRoomData, type GetToken } from '@coze/api';
3
3
  import * as RealtimeUtils from './utils';
4
- import { EventNames } from './event-names';
4
+ import EventNames from './event-names';
5
5
  import { RealtimeEventHandler } from './event-handler';
6
6
  import { RealtimeAPIError, RealtimeError } from './error';
7
7
  export interface VideoConfig {
@@ -1,4 +1,4 @@
1
- export declare enum EventNames {
1
+ declare enum EventNames {
2
2
  /**
3
3
  * en: All events
4
4
  * zh: 所有事件
@@ -140,3 +140,4 @@ export declare enum EventNames {
140
140
  */
141
141
  SESSION_UPDATE = "server.session.update"
142
142
  }
143
+ export default EventNames;
@@ -1,7 +1,7 @@
1
1
  import { type ScreenConfig, type AudioPropertiesConfig, type IRTCEngine } from '@volcengine/rtc';
2
2
  import { type CreateRoomData, type GetToken } from '@coze/api';
3
3
  import * as RealtimeUtils from './utils';
4
- import { EventNames } from './event-names';
4
+ import EventNames from './event-names';
5
5
  import { RealtimeEventHandler } from './event-handler';
6
6
  import { RealtimeAPIError, RealtimeError } from './error';
7
7
  export interface VideoConfig {
package/dist/umd/index.js CHANGED
@@ -86,7 +86,7 @@
86
86
  RealtimeAPIError: ()=>/* reexport */ RealtimeAPIError,
87
87
  RealtimeUtils: ()=>/* reexport */ utils_namespaceObject,
88
88
  RealtimeError: ()=>/* reexport */ error_RealtimeError,
89
- EventNames: ()=>/* reexport */ event_names_EventNames,
89
+ EventNames: ()=>/* reexport */ event_names,
90
90
  RealtimeClient: ()=>/* binding */ RealtimeClient
91
91
  });
92
92
  // NAMESPACE OBJECT: ./src/utils.ts
@@ -293,7 +293,8 @@
293
293
  * zh: 会话更新
294
294
  */ EventNames["SESSION_UPDATE"] = "server.session.update";
295
295
  return EventNames;
296
- }({});
296
+ }(event_names_EventNames || {});
297
+ /* ESM default export */ const event_names = event_names_EventNames;
297
298
  var error_RealtimeError = /*#__PURE__*/ function(RealtimeError) {
298
299
  RealtimeError["DEVICE_ACCESS_ERROR"] = "DEVICE_ACCESS_ERROR";
299
300
  RealtimeError["STREAM_CREATION_ERROR"] = "STREAM_CREATION_ERROR";
@@ -356,11 +357,11 @@
356
357
  if (consoleLog) this._log(`dispatch ${eventName} event`, event);
357
358
  const handlers = (this.eventHandlers[eventName] || []).slice();
358
359
  this._dispatchToHandlers(eventName, event, handlers);
359
- const allHandlers = (this.eventHandlers[event_names_EventNames.ALL] || []).slice();
360
+ const allHandlers = (this.eventHandlers[event_names.ALL] || []).slice();
360
361
  this._dispatchToHandlers(eventName, event, allHandlers);
361
- const allClientHandlers = (this.eventHandlers[event_names_EventNames.ALL_CLIENT] || []).slice();
362
+ const allClientHandlers = (this.eventHandlers[event_names.ALL_CLIENT] || []).slice();
362
363
  this._dispatchToHandlers(eventName, event, allClientHandlers, 'client.');
363
- const allServerHandlers = (this.eventHandlers[event_names_EventNames.ALL_SERVER] || []).slice();
364
+ const allServerHandlers = (this.eventHandlers[event_names.ALL_SERVER] || []).slice();
364
365
  this._dispatchToHandlers(eventName, event, allServerHandlers, 'server.');
365
366
  }
366
367
  _log(message, event) {
@@ -413,32 +414,32 @@
413
414
  this.dispatch(`server.${message.event_type}`, message);
414
415
  } catch (e) {
415
416
  if (e instanceof RealtimeAPIError) {
416
- if (e.code === error_RealtimeError.PARSE_MESSAGE_ERROR) this.dispatch(event_names_EventNames.ERROR, {
417
+ if (e.code === error_RealtimeError.PARSE_MESSAGE_ERROR) this.dispatch(event_names.ERROR, {
417
418
  message: `Failed to parse message: ${event.message}`,
418
419
  error: e
419
420
  });
420
- else if (e.code === error_RealtimeError.HANDLER_MESSAGE_ERROR) this.dispatch(event_names_EventNames.ERROR, {
421
+ else if (e.code === error_RealtimeError.HANDLER_MESSAGE_ERROR) this.dispatch(event_names.ERROR, {
421
422
  message: `Failed to handle message: ${event.message}`,
422
423
  error: e
423
424
  });
424
- } else this.dispatch(event_names_EventNames.ERROR, e);
425
+ } else this.dispatch(event_names.ERROR, e);
425
426
  }
426
427
  }
427
428
  handleEventError(e) {
428
- this.dispatch(event_names_EventNames.ERROR, e);
429
+ this.dispatch(event_names.ERROR, e);
429
430
  }
430
431
  handleUserJoin(event) {
431
432
  this.joinUserId = event.userInfo.userId;
432
- this.dispatch(event_names_EventNames.BOT_JOIN, event);
433
+ this.dispatch(event_names.BOT_JOIN, event);
433
434
  }
434
435
  handleUserLeave(event) {
435
- this.dispatch(event_names_EventNames.BOT_LEAVE, event);
436
+ this.dispatch(event_names.BOT_LEAVE, event);
436
437
  }
437
438
  handlePlayerEvent(event) {
438
- this.dispatch(event_names_EventNames.PLAYER_EVENT, event);
439
+ this.dispatch(event_names.PLAYER_EVENT, event);
439
440
  }
440
441
  handleNetworkQuality(uplinkNetworkQuality, downlinkNetworkQuality) {
441
- this.dispatch(event_names_EventNames.NETWORK_QUALITY, {
442
+ this.dispatch(event_names.NETWORK_QUALITY, {
442
443
  uplinkNetworkQuality,
443
444
  downlinkNetworkQuality
444
445
  });
@@ -514,7 +515,7 @@
514
515
  this.clearEventHandlers();
515
516
  rtc_default().destroyEngine(this.engine);
516
517
  } catch (e) {
517
- this.dispatch(event_names_EventNames.ERROR, e);
518
+ this.dispatch(event_names.ERROR, e);
518
519
  throw e;
519
520
  }
520
521
  }
@@ -523,7 +524,7 @@
523
524
  if (isMicOn) await this.engine.publishStream(rtc_.MediaType.AUDIO);
524
525
  else await this.engine.unpublishStream(rtc_.MediaType.AUDIO);
525
526
  } catch (e) {
526
- this.dispatch(event_names_EventNames.ERROR, e);
527
+ this.dispatch(event_names.ERROR, e);
527
528
  throw e;
528
529
  }
529
530
  }
@@ -543,7 +544,7 @@
543
544
  await this.engine.unpublishScreen(rtc_.MediaType.VIDEO);
544
545
  }
545
546
  } catch (e) {
546
- this.dispatch(event_names_EventNames.ERROR, e);
547
+ this.dispatch(event_names.ERROR, e);
547
548
  throw e;
548
549
  }
549
550
  }
@@ -556,7 +557,7 @@
556
557
  }));
557
558
  this._log(`interrupt ${this.joinUserId} ${result}`);
558
559
  } catch (e) {
559
- this.dispatch(event_names_EventNames.ERROR, e);
560
+ this.dispatch(event_names.ERROR, e);
560
561
  throw e;
561
562
  }
562
563
  }
@@ -565,7 +566,7 @@
565
566
  const result = await this.engine.sendUserMessage(this.joinUserId, JSON.stringify(message));
566
567
  this._log(`sendMessage ${this.joinUserId} ${JSON.stringify(message)} ${result}`);
567
568
  } catch (e) {
568
- this.dispatch(event_names_EventNames.ERROR, e);
569
+ this.dispatch(event_names.ERROR, e);
569
570
  throw e;
570
571
  }
571
572
  }
@@ -606,7 +607,7 @@
606
607
  try {
607
608
  await this.engine.startAudioPlaybackDeviceTest('audio-test.wav', 200);
608
609
  } catch (e) {
609
- this.dispatch(event_names_EventNames.ERROR, e);
610
+ this.dispatch(event_names.ERROR, e);
610
611
  throw e;
611
612
  }
612
613
  }
@@ -614,7 +615,7 @@
614
615
  try {
615
616
  this.engine.stopAudioPlaybackDeviceTest();
616
617
  } catch (e) {
617
- this.dispatch(event_names_EventNames.ERROR, e);
618
+ this.dispatch(event_names.ERROR, e);
618
619
  throw e;
619
620
  }
620
621
  }
@@ -651,7 +652,7 @@
651
652
  */ async connect() {
652
653
  var _this__config_videoConfig;
653
654
  const { botId, conversationId, voiceId, getRoomInfo } = this._config;
654
- this.dispatch(event_names_EventNames.CONNECTING, {});
655
+ this.dispatch(event_names.CONNECTING, {});
655
656
  let roomInfo;
656
657
  try {
657
658
  // Step1 get token
@@ -678,7 +679,7 @@
678
679
  });
679
680
  }
680
681
  } catch (error) {
681
- this.dispatch(event_names_EventNames.ERROR, error);
682
+ this.dispatch(event_names.ERROR, error);
682
683
  throw new RealtimeAPIError(error_RealtimeError.CREATE_ROOM_ERROR, error instanceof Error ? error.message : 'Unknown error', error);
683
684
  }
684
685
  this._isTestEnv = TEST_APP_ID === roomInfo.app_id;
@@ -686,17 +687,17 @@
686
687
  this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo, this._config.videoConfig);
687
688
  // Step3 bind engine events
688
689
  this._client.bindEngineEvents();
689
- this._client.on(event_names_EventNames.ALL, (eventName, data)=>{
690
+ this._client.on(event_names.ALL, (eventName, data)=>{
690
691
  this.dispatch(eventName, data, false);
691
692
  });
692
693
  if (this._config.suppressStationaryNoise) {
693
694
  await this._client.enableAudioNoiseReduction();
694
- this.dispatch(event_names_EventNames.SUPPRESS_STATIONARY_NOISE, {});
695
+ this.dispatch(event_names.SUPPRESS_STATIONARY_NOISE, {});
695
696
  }
696
697
  if (this._config.suppressNonStationaryNoise) try {
697
698
  await this._client.initAIAnsExtension();
698
699
  this._client.changeAIAnsExtension(true);
699
- this.dispatch(event_names_EventNames.SUPPRESS_NON_STATIONARY_NOISE, {});
700
+ this.dispatch(event_names.SUPPRESS_NON_STATIONARY_NOISE, {});
700
701
  } catch (error) {
701
702
  console.warn('Config suppressNonStationaryNoise is not supported', error);
702
703
  }
@@ -714,7 +715,7 @@
714
715
  await this._client.createLocalStream(roomInfo.uid, this._config.videoConfig);
715
716
  // step6 set connected and dispatch connected event
716
717
  this.isConnected = true;
717
- this.dispatch(event_names_EventNames.CONNECTED, {
718
+ this.dispatch(event_names.CONNECTED, {
718
719
  roomId: roomInfo.room_id,
719
720
  uid: roomInfo.uid,
720
721
  token: roomInfo.token,
@@ -728,7 +729,7 @@
728
729
  */ async interrupt() {
729
730
  var _this__client;
730
731
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.stop());
731
- this.dispatch(event_names_EventNames.INTERRUPTED, {});
732
+ this.dispatch(event_names.INTERRUPTED, {});
732
733
  }
733
734
  /**
734
735
  * en: Disconnect from the current session
@@ -739,7 +740,7 @@
739
740
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.disconnect());
740
741
  this.isConnected = false;
741
742
  this._client = null;
742
- this.dispatch(event_names_EventNames.DISCONNECTED, {});
743
+ this.dispatch(event_names.DISCONNECTED, {});
743
744
  }
744
745
  /**
745
746
  * en: Send a message to the bot
@@ -758,14 +759,14 @@
758
759
  */ async setAudioEnable(isEnable) {
759
760
  var _this__client;
760
761
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.changeAudioState(isEnable));
761
- if (isEnable) this.dispatch(event_names_EventNames.AUDIO_UNMUTED, {});
762
- else this.dispatch(event_names_EventNames.AUDIO_MUTED, {});
762
+ if (isEnable) this.dispatch(event_names.AUDIO_UNMUTED, {});
763
+ else this.dispatch(event_names.AUDIO_MUTED, {});
763
764
  }
764
765
  async setVideoEnable(isEnable) {
765
766
  var _this__client;
766
767
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.changeVideoState(isEnable));
767
- if (isEnable) this.dispatch(event_names_EventNames.VIDEO_ON, {});
768
- else this.dispatch(event_names_EventNames.VIDEO_OFF, {});
768
+ if (isEnable) this.dispatch(event_names.VIDEO_ON, {});
769
+ else this.dispatch(event_names.VIDEO_OFF, {});
769
770
  }
770
771
  /**
771
772
  * en: Enable audio properties reporting (debug mode only)
@@ -807,7 +808,7 @@
807
808
  */ async setAudioInputDevice(deviceId) {
808
809
  var _this__client;
809
810
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setAudioInputDevice(deviceId));
810
- this.dispatch(event_names_EventNames.AUDIO_INPUT_DEVICE_CHANGED, {
811
+ this.dispatch(event_names.AUDIO_INPUT_DEVICE_CHANGED, {
811
812
  deviceId
812
813
  });
813
814
  }
@@ -818,14 +819,14 @@
818
819
  */ async setAudioOutputDevice(deviceId) {
819
820
  var _this__client;
820
821
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setAudioOutputDevice(deviceId));
821
- this.dispatch(event_names_EventNames.AUDIO_OUTPUT_DEVICE_CHANGED, {
822
+ this.dispatch(event_names.AUDIO_OUTPUT_DEVICE_CHANGED, {
822
823
  deviceId
823
824
  });
824
825
  }
825
826
  async setVideoInputDevice(deviceId) {
826
827
  var _this__client;
827
828
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setVideoInputDevice(deviceId));
828
- this.dispatch(event_names_EventNames.VIDEO_INPUT_DEVICE_CHANGED, {
829
+ this.dispatch(event_names.VIDEO_INPUT_DEVICE_CHANGED, {
829
830
  deviceId
830
831
  });
831
832
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coze/realtime-api",
3
- "version": "1.1.1-beta.3",
3
+ "version": "1.1.1-beta.4",
4
4
  "description": "A powerful real-time communication SDK for voice interactions with Coze AI bots | 扣子官方实时通信 SDK,用于与 Coze AI bots 进行语音交互",
5
5
  "keywords": [
6
6
  "coze",
@@ -21,7 +21,6 @@
21
21
  },
22
22
  "license": "MIT",
23
23
  "author": "jackshen <jackshen310@gmail.com>",
24
- "type": "module",
25
24
  "exports": {
26
25
  ".": {
27
26
  "require": "./dist/cjs/index.cjs",
@@ -31,7 +30,7 @@
31
30
  "./event-names": {
32
31
  "require": "./dist/cjs/event-names/index.cjs",
33
32
  "import": "./dist/esm/event-names/index.js",
34
- "types": "./dist/types/event-names/index.d.ts"
33
+ "types": "./dist/types/event-names/event-names.d.ts"
35
34
  }
36
35
  },
37
36
  "main": "dist/cjs/index.cjs",
@@ -81,7 +80,7 @@
81
80
  "./event-names": {
82
81
  "require": "./dist/cjs/event-names/index.cjs",
83
82
  "import": "./dist/esm/event-names/index.js",
84
- "types": "./dist/types/event-names/index.d.ts"
83
+ "types": "./dist/types/event-names/event-names.d.ts"
85
84
  }
86
85
  },
87
86
  "main": "dist/cjs/index.cjs",