@coze/realtime-api 1.1.1-beta.1 → 1.1.1-beta.2

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.
@@ -92,7 +92,7 @@ __webpack_require__.d(__webpack_exports__, {
92
92
  RealtimeAPIError: ()=>/* reexport */ RealtimeAPIError,
93
93
  RealtimeUtils: ()=>/* reexport */ src_utils_namespaceObject,
94
94
  RealtimeError: ()=>/* reexport */ error_RealtimeError,
95
- EventNames: ()=>/* reexport */ event_handler_EventNames,
95
+ EventNames: ()=>/* reexport */ event_names_EventNames,
96
96
  RealtimeClient: ()=>/* binding */ RealtimeClient
97
97
  });
98
98
  // NAMESPACE OBJECT: ../../common/temp/default/node_modules/.pnpm/axios@1.7.7_debug@4.3.7/node_modules/axios/lib/platform/common/utils.js
@@ -4660,7 +4660,7 @@ class WebSocketAPI {
4660
4660
  // EXTERNAL MODULE: os (ignored)
4661
4661
  var os_ignored_ = __webpack_require__("?9050");
4662
4662
  var os_ignored_default = /*#__PURE__*/ __webpack_require__.n(os_ignored_);
4663
- var package_namespaceObject = JSON.parse('{"name":"@coze/api","version":"1.1.1","description":"Official Coze Node.js SDK for seamless AI integration into your applications | 扣子官方 Node.js SDK,助您轻松集成 AI 能力到应用中","keywords":["coze","ai","nodejs","sdk","chatbot","typescript"],"homepage":"https://github.com/coze-dev/coze-js/tree/main/packages/coze-js","bugs":{"url":"https://github.com/coze-dev/coze-js/issues"},"repository":{"type":"git","url":"https://github.com/coze-dev/coze-js.git","directory":"packages/coze-js"},"license":"MIT","author":"Leeight <leeight@gmail.com>","exports":{".":"./src/index.ts","./ws-tools":"./src/ws-tools/index.ts"},"main":"src/index.ts","module":"src/index.ts","browser":{"crypto":false,"os":false,"jsonwebtoken":false,"node-fetch":false},"typesVersions":{"*":{".":["dist/types/index.d.ts"],"ws-tools":["dist/types/ws-tools/ws-tools/index.d.ts"]}},"files":["dist","LICENSE","README.md","README.zh-CN.md"],"scripts":{"build":"rslib build","format":"prettier --write .","lint":"eslint ./ --cache --quiet","start":"rslib build -w","test":"vitest","test:cov":"vitest --coverage --run"},"dependencies":{"jsonwebtoken":"^9.0.2","node-fetch":"^2.x","reconnecting-websocket":"^4.4.0","uuid":"^10.0.0","ws":"^8.11.0"},"devDependencies":{"@coze-infra/eslint-config":"workspace:*","@coze-infra/ts-config":"workspace:*","@coze-infra/vitest-config":"workspace:*","@rslib/core":"0.0.18","@swc/core":"^1.3.14","@types/jsonwebtoken":"^9.0.0","@types/node":"^20","@types/node-fetch":"^2.x","@types/uuid":"^9.0.1","@types/whatwg-fetch":"^0.0.33","@types/ws":"^8.5.1","@vitest/coverage-v8":"~2.1.4","axios":"^1.7.7","typescript":"^5.5.3","vitest":"~2.1.4"},"peerDependencies":{"axios":"^1.7.1"},"cozePublishConfig":{"exports":{".":{"require":"./dist/cjs/index.js","import":"./dist/esm/index.js","types":"./dist/types/index.d.ts"},"./ws-tools":{"require":"./dist/cjs/ws-tools/index.js","import":"./dist/esm/ws-tools/index.js","types":"./dist/types/ws-tools/ws-tools/index.d.ts"}},"main":"dist/cjs/index.js","module":"dist/esm/index.js","types":"dist/types/index.d.ts"}}'); // CONCATENATED MODULE: ../coze-js/src/version.ts
4663
+ var package_namespaceObject = JSON.parse('{"name":"@coze/api","version":"1.1.1-beta.1","description":"Official Coze Node.js SDK for seamless AI integration into your applications | 扣子官方 Node.js SDK,助您轻松集成 AI 能力到应用中","keywords":["coze","ai","nodejs","sdk","chatbot","typescript"],"homepage":"https://github.com/coze-dev/coze-js/tree/main/packages/coze-js","bugs":{"url":"https://github.com/coze-dev/coze-js/issues"},"repository":{"type":"git","url":"https://github.com/coze-dev/coze-js.git","directory":"packages/coze-js"},"license":"MIT","author":"Leeight <leeight@gmail.com>","exports":{".":"./src/index.ts","./ws-tools":"./src/ws-tools/index.ts"},"main":"src/index.ts","module":"src/index.ts","browser":{"crypto":false,"os":false,"jsonwebtoken":false,"node-fetch":false},"typesVersions":{"*":{".":["dist/types/index.d.ts"],"ws-tools":["dist/types/ws-tools/ws-tools/index.d.ts"]}},"files":["dist","LICENSE","README.md","README.zh-CN.md"],"scripts":{"build":"rslib build","format":"prettier --write .","lint":"eslint ./ --cache --quiet","start":"rslib build -w","test":"vitest","test:cov":"vitest --coverage --run"},"dependencies":{"jsonwebtoken":"^9.0.2","node-fetch":"^2.x","reconnecting-websocket":"^4.4.0","uuid":"^10.0.0","ws":"^8.11.0"},"devDependencies":{"@coze-infra/eslint-config":"workspace:*","@coze-infra/ts-config":"workspace:*","@coze-infra/vitest-config":"workspace:*","@rslib/core":"0.0.18","@swc/core":"^1.3.14","@types/jsonwebtoken":"^9.0.0","@types/node":"^20","@types/node-fetch":"^2.x","@types/uuid":"^9.0.1","@types/whatwg-fetch":"^0.0.33","@types/ws":"^8.5.1","@vitest/coverage-v8":"~2.1.4","axios":"^1.7.7","typescript":"^5.5.3","vitest":"~2.1.4"},"peerDependencies":{"axios":"^1.7.1"},"cozePublishConfig":{"exports":{".":{"require":"./dist/cjs/index.js","import":"./dist/esm/index.mjs","types":"./dist/types/index.d.ts"},"./ws-tools":{"require":"./dist/cjs/ws-tools/index.js","import":"./dist/esm/ws-tools/index.mjs","types":"./dist/types/ws-tools/ws-tools/index.d.ts"}},"main":"dist/cjs/index.js","module":"dist/esm/index.mjs","types":"dist/types/index.d.ts"}}'); // CONCATENATED MODULE: ../coze-js/src/version.ts
4664
4664
  const { version: version_version } = package_namespaceObject;
4665
4665
  const getEnv = ()=>{
4666
4666
  const nodeVersion = process.version.slice(1); // Remove 'v' prefix
@@ -39464,34 +39464,7 @@ const isScreenShareDevice = (deviceId)=>'screenShare' === deviceId;
39464
39464
  var _navigator_mediaDevices, _navigator;
39465
39465
  return !!(null === (_navigator = navigator) || void 0 === _navigator ? void 0 : null === (_navigator_mediaDevices = _navigator.mediaDevices) || void 0 === _navigator_mediaDevices ? void 0 : _navigator_mediaDevices.getDisplayMedia);
39466
39466
  }
39467
- var error_RealtimeError = /*#__PURE__*/ function(RealtimeError) {
39468
- RealtimeError["DEVICE_ACCESS_ERROR"] = "DEVICE_ACCESS_ERROR";
39469
- RealtimeError["STREAM_CREATION_ERROR"] = "STREAM_CREATION_ERROR";
39470
- RealtimeError["CONNECTION_ERROR"] = "CONNECTION_ERROR";
39471
- RealtimeError["DISCONNECTION_ERROR"] = "DISCONNECTION_ERROR";
39472
- RealtimeError["INTERRUPT_ERROR"] = "INTERRUPT_ERROR";
39473
- RealtimeError["EVENT_HANDLER_ERROR"] = "EVENT_HANDLER_ERROR";
39474
- RealtimeError["PERMISSION_DENIED"] = "PERMISSION_DENIED";
39475
- RealtimeError["NETWORK_ERROR"] = "NETWORK_ERROR";
39476
- RealtimeError["INVALID_STATE"] = "INVALID_STATE";
39477
- RealtimeError["CREATE_ROOM_ERROR"] = "CREATE_ROOM_ERROR";
39478
- RealtimeError["PARSE_MESSAGE_ERROR"] = "PARSE_MESSAGE_ERROR";
39479
- RealtimeError["HANDLER_MESSAGE_ERROR"] = "HANDLER_MESSAGE_ERROR";
39480
- return RealtimeError;
39481
- }({});
39482
- class RealtimeAPIError extends Error {
39483
- /**
39484
- * @param code - Error code
39485
- * @param message - Error message
39486
- * @param error - Error object
39487
- */ constructor(code, message, error){
39488
- super(`[${code}] ${message}`);
39489
- this.name = 'RealtimeAPIError';
39490
- this.code = code;
39491
- this.error = error;
39492
- }
39493
- }
39494
- var event_handler_EventNames = /*#__PURE__*/ function(EventNames) {
39467
+ var event_names_EventNames = /*#__PURE__*/ function(EventNames) {
39495
39468
  /**
39496
39469
  * en: All events
39497
39470
  * zh: 所有事件
@@ -39606,6 +39579,33 @@ var event_handler_EventNames = /*#__PURE__*/ function(EventNames) {
39606
39579
  */ EventNames["SESSION_UPDATE"] = "server.session.update";
39607
39580
  return EventNames;
39608
39581
  }({});
39582
+ var error_RealtimeError = /*#__PURE__*/ function(RealtimeError) {
39583
+ RealtimeError["DEVICE_ACCESS_ERROR"] = "DEVICE_ACCESS_ERROR";
39584
+ RealtimeError["STREAM_CREATION_ERROR"] = "STREAM_CREATION_ERROR";
39585
+ RealtimeError["CONNECTION_ERROR"] = "CONNECTION_ERROR";
39586
+ RealtimeError["DISCONNECTION_ERROR"] = "DISCONNECTION_ERROR";
39587
+ RealtimeError["INTERRUPT_ERROR"] = "INTERRUPT_ERROR";
39588
+ RealtimeError["EVENT_HANDLER_ERROR"] = "EVENT_HANDLER_ERROR";
39589
+ RealtimeError["PERMISSION_DENIED"] = "PERMISSION_DENIED";
39590
+ RealtimeError["NETWORK_ERROR"] = "NETWORK_ERROR";
39591
+ RealtimeError["INVALID_STATE"] = "INVALID_STATE";
39592
+ RealtimeError["CREATE_ROOM_ERROR"] = "CREATE_ROOM_ERROR";
39593
+ RealtimeError["PARSE_MESSAGE_ERROR"] = "PARSE_MESSAGE_ERROR";
39594
+ RealtimeError["HANDLER_MESSAGE_ERROR"] = "HANDLER_MESSAGE_ERROR";
39595
+ return RealtimeError;
39596
+ }({});
39597
+ class RealtimeAPIError extends Error {
39598
+ /**
39599
+ * @param code - Error code
39600
+ * @param message - Error message
39601
+ * @param error - Error object
39602
+ */ constructor(code, message, error){
39603
+ super(`[${code}] ${message}`);
39604
+ this.name = 'RealtimeAPIError';
39605
+ this.code = code;
39606
+ this.error = error;
39607
+ }
39608
+ }
39609
39609
  class RealtimeEventHandler {
39610
39610
  clearEventHandlers() {
39611
39611
  this.eventHandlers = {};
@@ -39641,11 +39641,11 @@ class RealtimeEventHandler {
39641
39641
  if (consoleLog) this._log(`dispatch ${eventName} event`, event);
39642
39642
  const handlers = (this.eventHandlers[eventName] || []).slice();
39643
39643
  this._dispatchToHandlers(eventName, event, handlers);
39644
- const allHandlers = (this.eventHandlers["realtime.event"] || []).slice();
39644
+ const allHandlers = (this.eventHandlers[event_names_EventNames.ALL] || []).slice();
39645
39645
  this._dispatchToHandlers(eventName, event, allHandlers);
39646
- const allClientHandlers = (this.eventHandlers["client.*"] || []).slice();
39646
+ const allClientHandlers = (this.eventHandlers[event_names_EventNames.ALL_CLIENT] || []).slice();
39647
39647
  this._dispatchToHandlers(eventName, event, allClientHandlers, 'client.');
39648
- const allServerHandlers = (this.eventHandlers["server.*"] || []).slice();
39648
+ const allServerHandlers = (this.eventHandlers[event_names_EventNames.ALL_SERVER] || []).slice();
39649
39649
  this._dispatchToHandlers(eventName, event, allServerHandlers, 'server.');
39650
39650
  }
39651
39651
  _log(message, event) {
@@ -42940,32 +42940,32 @@ class EngineClient extends RealtimeEventHandler {
42940
42940
  this.dispatch(`server.${message.event_type}`, message);
42941
42941
  } catch (e) {
42942
42942
  if (e instanceof RealtimeAPIError) {
42943
- if (e.code === error_RealtimeError.PARSE_MESSAGE_ERROR) this.dispatch(event_handler_EventNames.ERROR, {
42943
+ if (e.code === error_RealtimeError.PARSE_MESSAGE_ERROR) this.dispatch(event_names_EventNames.ERROR, {
42944
42944
  message: `Failed to parse message: ${event.message}`,
42945
42945
  error: e
42946
42946
  });
42947
- else if (e.code === error_RealtimeError.HANDLER_MESSAGE_ERROR) this.dispatch(event_handler_EventNames.ERROR, {
42947
+ else if (e.code === error_RealtimeError.HANDLER_MESSAGE_ERROR) this.dispatch(event_names_EventNames.ERROR, {
42948
42948
  message: `Failed to handle message: ${event.message}`,
42949
42949
  error: e
42950
42950
  });
42951
- } else this.dispatch(event_handler_EventNames.ERROR, e);
42951
+ } else this.dispatch(event_names_EventNames.ERROR, e);
42952
42952
  }
42953
42953
  }
42954
42954
  handleEventError(e) {
42955
- this.dispatch(event_handler_EventNames.ERROR, e);
42955
+ this.dispatch(event_names_EventNames.ERROR, e);
42956
42956
  }
42957
42957
  handleUserJoin(event) {
42958
42958
  this.joinUserId = event.userInfo.userId;
42959
- this.dispatch(event_handler_EventNames.BOT_JOIN, event);
42959
+ this.dispatch(event_names_EventNames.BOT_JOIN, event);
42960
42960
  }
42961
42961
  handleUserLeave(event) {
42962
- this.dispatch(event_handler_EventNames.BOT_LEAVE, event);
42962
+ this.dispatch(event_names_EventNames.BOT_LEAVE, event);
42963
42963
  }
42964
42964
  handlePlayerEvent(event) {
42965
- this.dispatch(event_handler_EventNames.PLAYER_EVENT, event);
42965
+ this.dispatch(event_names_EventNames.PLAYER_EVENT, event);
42966
42966
  }
42967
42967
  handleNetworkQuality(uplinkNetworkQuality, downlinkNetworkQuality) {
42968
- this.dispatch(event_handler_EventNames.NETWORK_QUALITY, {
42968
+ this.dispatch(event_names_EventNames.NETWORK_QUALITY, {
42969
42969
  uplinkNetworkQuality,
42970
42970
  downlinkNetworkQuality
42971
42971
  });
@@ -43041,7 +43041,7 @@ class EngineClient extends RealtimeEventHandler {
43041
43041
  this.clearEventHandlers();
43042
43042
  index_esm_min_index.destroyEngine(this.engine);
43043
43043
  } catch (e) {
43044
- this.dispatch(event_handler_EventNames.ERROR, e);
43044
+ this.dispatch(event_names_EventNames.ERROR, e);
43045
43045
  throw e;
43046
43046
  }
43047
43047
  }
@@ -43050,7 +43050,7 @@ class EngineClient extends RealtimeEventHandler {
43050
43050
  if (isMicOn) await this.engine.publishStream(MediaType$1.AUDIO);
43051
43051
  else await this.engine.unpublishStream(MediaType$1.AUDIO);
43052
43052
  } catch (e) {
43053
- this.dispatch(event_handler_EventNames.ERROR, e);
43053
+ this.dispatch(event_names_EventNames.ERROR, e);
43054
43054
  throw e;
43055
43055
  }
43056
43056
  }
@@ -43070,7 +43070,7 @@ class EngineClient extends RealtimeEventHandler {
43070
43070
  await this.engine.unpublishScreen(MediaType$1.VIDEO);
43071
43071
  }
43072
43072
  } catch (e) {
43073
- this.dispatch(event_handler_EventNames.ERROR, e);
43073
+ this.dispatch(event_names_EventNames.ERROR, e);
43074
43074
  throw e;
43075
43075
  }
43076
43076
  }
@@ -43083,7 +43083,7 @@ class EngineClient extends RealtimeEventHandler {
43083
43083
  }));
43084
43084
  this._log(`interrupt ${this.joinUserId} ${result}`);
43085
43085
  } catch (e) {
43086
- this.dispatch(event_handler_EventNames.ERROR, e);
43086
+ this.dispatch(event_names_EventNames.ERROR, e);
43087
43087
  throw e;
43088
43088
  }
43089
43089
  }
@@ -43092,7 +43092,7 @@ class EngineClient extends RealtimeEventHandler {
43092
43092
  const result = await this.engine.sendUserMessage(this.joinUserId, JSON.stringify(message));
43093
43093
  this._log(`sendMessage ${this.joinUserId} ${JSON.stringify(message)} ${result}`);
43094
43094
  } catch (e) {
43095
- this.dispatch(event_handler_EventNames.ERROR, e);
43095
+ this.dispatch(event_names_EventNames.ERROR, e);
43096
43096
  throw e;
43097
43097
  }
43098
43098
  }
@@ -43133,7 +43133,7 @@ class EngineClient extends RealtimeEventHandler {
43133
43133
  try {
43134
43134
  await this.engine.startAudioPlaybackDeviceTest('audio-test.wav', 200);
43135
43135
  } catch (e) {
43136
- this.dispatch(event_handler_EventNames.ERROR, e);
43136
+ this.dispatch(event_names_EventNames.ERROR, e);
43137
43137
  throw e;
43138
43138
  }
43139
43139
  }
@@ -43141,7 +43141,7 @@ class EngineClient extends RealtimeEventHandler {
43141
43141
  try {
43142
43142
  this.engine.stopAudioPlaybackDeviceTest();
43143
43143
  } catch (e) {
43144
- this.dispatch(event_handler_EventNames.ERROR, e);
43144
+ this.dispatch(event_names_EventNames.ERROR, e);
43145
43145
  throw e;
43146
43146
  }
43147
43147
  }
@@ -43178,7 +43178,7 @@ class RealtimeClient extends RealtimeEventHandler {
43178
43178
  */ async connect() {
43179
43179
  var _this__config_videoConfig;
43180
43180
  const { botId, conversationId, voiceId, getRoomInfo } = this._config;
43181
- this.dispatch(event_handler_EventNames.CONNECTING, {});
43181
+ this.dispatch(event_names_EventNames.CONNECTING, {});
43182
43182
  let roomInfo;
43183
43183
  try {
43184
43184
  // Step1 get token
@@ -43205,7 +43205,7 @@ class RealtimeClient extends RealtimeEventHandler {
43205
43205
  });
43206
43206
  }
43207
43207
  } catch (error) {
43208
- this.dispatch(event_handler_EventNames.ERROR, error);
43208
+ this.dispatch(event_names_EventNames.ERROR, error);
43209
43209
  throw new RealtimeAPIError(error_RealtimeError.CREATE_ROOM_ERROR, error instanceof Error ? error.message : 'Unknown error', error);
43210
43210
  }
43211
43211
  this._isTestEnv = TEST_APP_ID === roomInfo.app_id;
@@ -43213,17 +43213,17 @@ class RealtimeClient extends RealtimeEventHandler {
43213
43213
  this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo, this._config.videoConfig);
43214
43214
  // Step3 bind engine events
43215
43215
  this._client.bindEngineEvents();
43216
- this._client.on(event_handler_EventNames.ALL, (eventName, data)=>{
43216
+ this._client.on(event_names_EventNames.ALL, (eventName, data)=>{
43217
43217
  this.dispatch(eventName, data, false);
43218
43218
  });
43219
43219
  if (this._config.suppressStationaryNoise) {
43220
43220
  await this._client.enableAudioNoiseReduction();
43221
- this.dispatch(event_handler_EventNames.SUPPRESS_STATIONARY_NOISE, {});
43221
+ this.dispatch(event_names_EventNames.SUPPRESS_STATIONARY_NOISE, {});
43222
43222
  }
43223
43223
  if (this._config.suppressNonStationaryNoise) try {
43224
43224
  await this._client.initAIAnsExtension();
43225
43225
  this._client.changeAIAnsExtension(true);
43226
- this.dispatch(event_handler_EventNames.SUPPRESS_NON_STATIONARY_NOISE, {});
43226
+ this.dispatch(event_names_EventNames.SUPPRESS_NON_STATIONARY_NOISE, {});
43227
43227
  } catch (error) {
43228
43228
  console.warn('Config suppressNonStationaryNoise is not supported', error);
43229
43229
  }
@@ -43241,7 +43241,7 @@ class RealtimeClient extends RealtimeEventHandler {
43241
43241
  await this._client.createLocalStream(roomInfo.uid, this._config.videoConfig);
43242
43242
  // step6 set connected and dispatch connected event
43243
43243
  this.isConnected = true;
43244
- this.dispatch(event_handler_EventNames.CONNECTED, {
43244
+ this.dispatch(event_names_EventNames.CONNECTED, {
43245
43245
  roomId: roomInfo.room_id,
43246
43246
  uid: roomInfo.uid,
43247
43247
  token: roomInfo.token,
@@ -43255,7 +43255,7 @@ class RealtimeClient extends RealtimeEventHandler {
43255
43255
  */ async interrupt() {
43256
43256
  var _this__client;
43257
43257
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.stop());
43258
- this.dispatch(event_handler_EventNames.INTERRUPTED, {});
43258
+ this.dispatch(event_names_EventNames.INTERRUPTED, {});
43259
43259
  }
43260
43260
  /**
43261
43261
  * en: Disconnect from the current session
@@ -43266,7 +43266,7 @@ class RealtimeClient extends RealtimeEventHandler {
43266
43266
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.disconnect());
43267
43267
  this.isConnected = false;
43268
43268
  this._client = null;
43269
- this.dispatch(event_handler_EventNames.DISCONNECTED, {});
43269
+ this.dispatch(event_names_EventNames.DISCONNECTED, {});
43270
43270
  }
43271
43271
  /**
43272
43272
  * en: Send a message to the bot
@@ -43285,14 +43285,14 @@ class RealtimeClient extends RealtimeEventHandler {
43285
43285
  */ async setAudioEnable(isEnable) {
43286
43286
  var _this__client;
43287
43287
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.changeAudioState(isEnable));
43288
- if (isEnable) this.dispatch(event_handler_EventNames.AUDIO_UNMUTED, {});
43289
- else this.dispatch(event_handler_EventNames.AUDIO_MUTED, {});
43288
+ if (isEnable) this.dispatch(event_names_EventNames.AUDIO_UNMUTED, {});
43289
+ else this.dispatch(event_names_EventNames.AUDIO_MUTED, {});
43290
43290
  }
43291
43291
  async setVideoEnable(isEnable) {
43292
43292
  var _this__client;
43293
43293
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.changeVideoState(isEnable));
43294
- if (isEnable) this.dispatch(event_handler_EventNames.VIDEO_ON, {});
43295
- else this.dispatch(event_handler_EventNames.VIDEO_OFF, {});
43294
+ if (isEnable) this.dispatch(event_names_EventNames.VIDEO_ON, {});
43295
+ else this.dispatch(event_names_EventNames.VIDEO_OFF, {});
43296
43296
  }
43297
43297
  /**
43298
43298
  * en: Enable audio properties reporting (debug mode only)
@@ -43334,7 +43334,7 @@ class RealtimeClient extends RealtimeEventHandler {
43334
43334
  */ async setAudioInputDevice(deviceId) {
43335
43335
  var _this__client;
43336
43336
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setAudioInputDevice(deviceId));
43337
- this.dispatch(event_handler_EventNames.AUDIO_INPUT_DEVICE_CHANGED, {
43337
+ this.dispatch(event_names_EventNames.AUDIO_INPUT_DEVICE_CHANGED, {
43338
43338
  deviceId
43339
43339
  });
43340
43340
  }
@@ -43345,14 +43345,14 @@ class RealtimeClient extends RealtimeEventHandler {
43345
43345
  */ async setAudioOutputDevice(deviceId) {
43346
43346
  var _this__client;
43347
43347
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setAudioOutputDevice(deviceId));
43348
- this.dispatch(event_handler_EventNames.AUDIO_OUTPUT_DEVICE_CHANGED, {
43348
+ this.dispatch(event_names_EventNames.AUDIO_OUTPUT_DEVICE_CHANGED, {
43349
43349
  deviceId
43350
43350
  });
43351
43351
  }
43352
43352
  async setVideoInputDevice(deviceId) {
43353
43353
  var _this__client;
43354
43354
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setVideoInputDevice(deviceId));
43355
- this.dispatch(event_handler_EventNames.VIDEO_INPUT_DEVICE_CHANGED, {
43355
+ this.dispatch(event_names_EventNames.VIDEO_INPUT_DEVICE_CHANGED, {
43356
43356
  deviceId
43357
43357
  });
43358
43358
  }
package/dist/esm/index.js CHANGED
@@ -4648,7 +4648,7 @@ class WebSocketAPI {
4648
4648
  // EXTERNAL MODULE: os (ignored)
4649
4649
  var os_ignored_ = __webpack_require__("?9050");
4650
4650
  var os_ignored_default = /*#__PURE__*/ __webpack_require__.n(os_ignored_);
4651
- var package_namespaceObject = JSON.parse('{"name":"@coze/api","version":"1.1.1","description":"Official Coze Node.js SDK for seamless AI integration into your applications | 扣子官方 Node.js SDK,助您轻松集成 AI 能力到应用中","keywords":["coze","ai","nodejs","sdk","chatbot","typescript"],"homepage":"https://github.com/coze-dev/coze-js/tree/main/packages/coze-js","bugs":{"url":"https://github.com/coze-dev/coze-js/issues"},"repository":{"type":"git","url":"https://github.com/coze-dev/coze-js.git","directory":"packages/coze-js"},"license":"MIT","author":"Leeight <leeight@gmail.com>","exports":{".":"./src/index.ts","./ws-tools":"./src/ws-tools/index.ts"},"main":"src/index.ts","module":"src/index.ts","browser":{"crypto":false,"os":false,"jsonwebtoken":false,"node-fetch":false},"typesVersions":{"*":{".":["dist/types/index.d.ts"],"ws-tools":["dist/types/ws-tools/ws-tools/index.d.ts"]}},"files":["dist","LICENSE","README.md","README.zh-CN.md"],"scripts":{"build":"rslib build","format":"prettier --write .","lint":"eslint ./ --cache --quiet","start":"rslib build -w","test":"vitest","test:cov":"vitest --coverage --run"},"dependencies":{"jsonwebtoken":"^9.0.2","node-fetch":"^2.x","reconnecting-websocket":"^4.4.0","uuid":"^10.0.0","ws":"^8.11.0"},"devDependencies":{"@coze-infra/eslint-config":"workspace:*","@coze-infra/ts-config":"workspace:*","@coze-infra/vitest-config":"workspace:*","@rslib/core":"0.0.18","@swc/core":"^1.3.14","@types/jsonwebtoken":"^9.0.0","@types/node":"^20","@types/node-fetch":"^2.x","@types/uuid":"^9.0.1","@types/whatwg-fetch":"^0.0.33","@types/ws":"^8.5.1","@vitest/coverage-v8":"~2.1.4","axios":"^1.7.7","typescript":"^5.5.3","vitest":"~2.1.4"},"peerDependencies":{"axios":"^1.7.1"},"cozePublishConfig":{"exports":{".":{"require":"./dist/cjs/index.js","import":"./dist/esm/index.js","types":"./dist/types/index.d.ts"},"./ws-tools":{"require":"./dist/cjs/ws-tools/index.js","import":"./dist/esm/ws-tools/index.js","types":"./dist/types/ws-tools/ws-tools/index.d.ts"}},"main":"dist/cjs/index.js","module":"dist/esm/index.js","types":"dist/types/index.d.ts"}}'); // CONCATENATED MODULE: ../coze-js/src/version.ts
4651
+ var package_namespaceObject = JSON.parse('{"name":"@coze/api","version":"1.1.1-beta.1","description":"Official Coze Node.js SDK for seamless AI integration into your applications | 扣子官方 Node.js SDK,助您轻松集成 AI 能力到应用中","keywords":["coze","ai","nodejs","sdk","chatbot","typescript"],"homepage":"https://github.com/coze-dev/coze-js/tree/main/packages/coze-js","bugs":{"url":"https://github.com/coze-dev/coze-js/issues"},"repository":{"type":"git","url":"https://github.com/coze-dev/coze-js.git","directory":"packages/coze-js"},"license":"MIT","author":"Leeight <leeight@gmail.com>","exports":{".":"./src/index.ts","./ws-tools":"./src/ws-tools/index.ts"},"main":"src/index.ts","module":"src/index.ts","browser":{"crypto":false,"os":false,"jsonwebtoken":false,"node-fetch":false},"typesVersions":{"*":{".":["dist/types/index.d.ts"],"ws-tools":["dist/types/ws-tools/ws-tools/index.d.ts"]}},"files":["dist","LICENSE","README.md","README.zh-CN.md"],"scripts":{"build":"rslib build","format":"prettier --write .","lint":"eslint ./ --cache --quiet","start":"rslib build -w","test":"vitest","test:cov":"vitest --coverage --run"},"dependencies":{"jsonwebtoken":"^9.0.2","node-fetch":"^2.x","reconnecting-websocket":"^4.4.0","uuid":"^10.0.0","ws":"^8.11.0"},"devDependencies":{"@coze-infra/eslint-config":"workspace:*","@coze-infra/ts-config":"workspace:*","@coze-infra/vitest-config":"workspace:*","@rslib/core":"0.0.18","@swc/core":"^1.3.14","@types/jsonwebtoken":"^9.0.0","@types/node":"^20","@types/node-fetch":"^2.x","@types/uuid":"^9.0.1","@types/whatwg-fetch":"^0.0.33","@types/ws":"^8.5.1","@vitest/coverage-v8":"~2.1.4","axios":"^1.7.7","typescript":"^5.5.3","vitest":"~2.1.4"},"peerDependencies":{"axios":"^1.7.1"},"cozePublishConfig":{"exports":{".":{"require":"./dist/cjs/index.js","import":"./dist/esm/index.mjs","types":"./dist/types/index.d.ts"},"./ws-tools":{"require":"./dist/cjs/ws-tools/index.js","import":"./dist/esm/ws-tools/index.mjs","types":"./dist/types/ws-tools/ws-tools/index.d.ts"}},"main":"dist/cjs/index.js","module":"dist/esm/index.mjs","types":"dist/types/index.d.ts"}}'); // CONCATENATED MODULE: ../coze-js/src/version.ts
4652
4652
  const { version: version_version } = package_namespaceObject;
4653
4653
  const getEnv = ()=>{
4654
4654
  const nodeVersion = process.version.slice(1); // Remove 'v' prefix
@@ -39452,34 +39452,7 @@ const isScreenShareDevice = (deviceId)=>'screenShare' === deviceId;
39452
39452
  var _navigator_mediaDevices, _navigator;
39453
39453
  return !!(null === (_navigator = navigator) || void 0 === _navigator ? void 0 : null === (_navigator_mediaDevices = _navigator.mediaDevices) || void 0 === _navigator_mediaDevices ? void 0 : _navigator_mediaDevices.getDisplayMedia);
39454
39454
  }
39455
- var error_RealtimeError = /*#__PURE__*/ function(RealtimeError) {
39456
- RealtimeError["DEVICE_ACCESS_ERROR"] = "DEVICE_ACCESS_ERROR";
39457
- RealtimeError["STREAM_CREATION_ERROR"] = "STREAM_CREATION_ERROR";
39458
- RealtimeError["CONNECTION_ERROR"] = "CONNECTION_ERROR";
39459
- RealtimeError["DISCONNECTION_ERROR"] = "DISCONNECTION_ERROR";
39460
- RealtimeError["INTERRUPT_ERROR"] = "INTERRUPT_ERROR";
39461
- RealtimeError["EVENT_HANDLER_ERROR"] = "EVENT_HANDLER_ERROR";
39462
- RealtimeError["PERMISSION_DENIED"] = "PERMISSION_DENIED";
39463
- RealtimeError["NETWORK_ERROR"] = "NETWORK_ERROR";
39464
- RealtimeError["INVALID_STATE"] = "INVALID_STATE";
39465
- RealtimeError["CREATE_ROOM_ERROR"] = "CREATE_ROOM_ERROR";
39466
- RealtimeError["PARSE_MESSAGE_ERROR"] = "PARSE_MESSAGE_ERROR";
39467
- RealtimeError["HANDLER_MESSAGE_ERROR"] = "HANDLER_MESSAGE_ERROR";
39468
- return RealtimeError;
39469
- }({});
39470
- class RealtimeAPIError extends Error {
39471
- /**
39472
- * @param code - Error code
39473
- * @param message - Error message
39474
- * @param error - Error object
39475
- */ constructor(code, message, error){
39476
- super(`[${code}] ${message}`);
39477
- this.name = 'RealtimeAPIError';
39478
- this.code = code;
39479
- this.error = error;
39480
- }
39481
- }
39482
- var event_handler_EventNames = /*#__PURE__*/ function(EventNames) {
39455
+ var event_names_EventNames = /*#__PURE__*/ function(EventNames) {
39483
39456
  /**
39484
39457
  * en: All events
39485
39458
  * zh: 所有事件
@@ -39594,6 +39567,33 @@ var event_handler_EventNames = /*#__PURE__*/ function(EventNames) {
39594
39567
  */ EventNames["SESSION_UPDATE"] = "server.session.update";
39595
39568
  return EventNames;
39596
39569
  }({});
39570
+ var error_RealtimeError = /*#__PURE__*/ function(RealtimeError) {
39571
+ RealtimeError["DEVICE_ACCESS_ERROR"] = "DEVICE_ACCESS_ERROR";
39572
+ RealtimeError["STREAM_CREATION_ERROR"] = "STREAM_CREATION_ERROR";
39573
+ RealtimeError["CONNECTION_ERROR"] = "CONNECTION_ERROR";
39574
+ RealtimeError["DISCONNECTION_ERROR"] = "DISCONNECTION_ERROR";
39575
+ RealtimeError["INTERRUPT_ERROR"] = "INTERRUPT_ERROR";
39576
+ RealtimeError["EVENT_HANDLER_ERROR"] = "EVENT_HANDLER_ERROR";
39577
+ RealtimeError["PERMISSION_DENIED"] = "PERMISSION_DENIED";
39578
+ RealtimeError["NETWORK_ERROR"] = "NETWORK_ERROR";
39579
+ RealtimeError["INVALID_STATE"] = "INVALID_STATE";
39580
+ RealtimeError["CREATE_ROOM_ERROR"] = "CREATE_ROOM_ERROR";
39581
+ RealtimeError["PARSE_MESSAGE_ERROR"] = "PARSE_MESSAGE_ERROR";
39582
+ RealtimeError["HANDLER_MESSAGE_ERROR"] = "HANDLER_MESSAGE_ERROR";
39583
+ return RealtimeError;
39584
+ }({});
39585
+ class RealtimeAPIError extends Error {
39586
+ /**
39587
+ * @param code - Error code
39588
+ * @param message - Error message
39589
+ * @param error - Error object
39590
+ */ constructor(code, message, error){
39591
+ super(`[${code}] ${message}`);
39592
+ this.name = 'RealtimeAPIError';
39593
+ this.code = code;
39594
+ this.error = error;
39595
+ }
39596
+ }
39597
39597
  class RealtimeEventHandler {
39598
39598
  clearEventHandlers() {
39599
39599
  this.eventHandlers = {};
@@ -39629,11 +39629,11 @@ class RealtimeEventHandler {
39629
39629
  if (consoleLog) this._log(`dispatch ${eventName} event`, event);
39630
39630
  const handlers = (this.eventHandlers[eventName] || []).slice();
39631
39631
  this._dispatchToHandlers(eventName, event, handlers);
39632
- const allHandlers = (this.eventHandlers["realtime.event"] || []).slice();
39632
+ const allHandlers = (this.eventHandlers[event_names_EventNames.ALL] || []).slice();
39633
39633
  this._dispatchToHandlers(eventName, event, allHandlers);
39634
- const allClientHandlers = (this.eventHandlers["client.*"] || []).slice();
39634
+ const allClientHandlers = (this.eventHandlers[event_names_EventNames.ALL_CLIENT] || []).slice();
39635
39635
  this._dispatchToHandlers(eventName, event, allClientHandlers, 'client.');
39636
- const allServerHandlers = (this.eventHandlers["server.*"] || []).slice();
39636
+ const allServerHandlers = (this.eventHandlers[event_names_EventNames.ALL_SERVER] || []).slice();
39637
39637
  this._dispatchToHandlers(eventName, event, allServerHandlers, 'server.');
39638
39638
  }
39639
39639
  _log(message, event) {
@@ -42928,32 +42928,32 @@ class EngineClient extends RealtimeEventHandler {
42928
42928
  this.dispatch(`server.${message.event_type}`, message);
42929
42929
  } catch (e) {
42930
42930
  if (e instanceof RealtimeAPIError) {
42931
- if (e.code === error_RealtimeError.PARSE_MESSAGE_ERROR) this.dispatch(event_handler_EventNames.ERROR, {
42931
+ if (e.code === error_RealtimeError.PARSE_MESSAGE_ERROR) this.dispatch(event_names_EventNames.ERROR, {
42932
42932
  message: `Failed to parse message: ${event.message}`,
42933
42933
  error: e
42934
42934
  });
42935
- else if (e.code === error_RealtimeError.HANDLER_MESSAGE_ERROR) this.dispatch(event_handler_EventNames.ERROR, {
42935
+ else if (e.code === error_RealtimeError.HANDLER_MESSAGE_ERROR) this.dispatch(event_names_EventNames.ERROR, {
42936
42936
  message: `Failed to handle message: ${event.message}`,
42937
42937
  error: e
42938
42938
  });
42939
- } else this.dispatch(event_handler_EventNames.ERROR, e);
42939
+ } else this.dispatch(event_names_EventNames.ERROR, e);
42940
42940
  }
42941
42941
  }
42942
42942
  handleEventError(e) {
42943
- this.dispatch(event_handler_EventNames.ERROR, e);
42943
+ this.dispatch(event_names_EventNames.ERROR, e);
42944
42944
  }
42945
42945
  handleUserJoin(event) {
42946
42946
  this.joinUserId = event.userInfo.userId;
42947
- this.dispatch(event_handler_EventNames.BOT_JOIN, event);
42947
+ this.dispatch(event_names_EventNames.BOT_JOIN, event);
42948
42948
  }
42949
42949
  handleUserLeave(event) {
42950
- this.dispatch(event_handler_EventNames.BOT_LEAVE, event);
42950
+ this.dispatch(event_names_EventNames.BOT_LEAVE, event);
42951
42951
  }
42952
42952
  handlePlayerEvent(event) {
42953
- this.dispatch(event_handler_EventNames.PLAYER_EVENT, event);
42953
+ this.dispatch(event_names_EventNames.PLAYER_EVENT, event);
42954
42954
  }
42955
42955
  handleNetworkQuality(uplinkNetworkQuality, downlinkNetworkQuality) {
42956
- this.dispatch(event_handler_EventNames.NETWORK_QUALITY, {
42956
+ this.dispatch(event_names_EventNames.NETWORK_QUALITY, {
42957
42957
  uplinkNetworkQuality,
42958
42958
  downlinkNetworkQuality
42959
42959
  });
@@ -43029,7 +43029,7 @@ class EngineClient extends RealtimeEventHandler {
43029
43029
  this.clearEventHandlers();
43030
43030
  index_esm_min_index.destroyEngine(this.engine);
43031
43031
  } catch (e) {
43032
- this.dispatch(event_handler_EventNames.ERROR, e);
43032
+ this.dispatch(event_names_EventNames.ERROR, e);
43033
43033
  throw e;
43034
43034
  }
43035
43035
  }
@@ -43038,7 +43038,7 @@ class EngineClient extends RealtimeEventHandler {
43038
43038
  if (isMicOn) await this.engine.publishStream(MediaType$1.AUDIO);
43039
43039
  else await this.engine.unpublishStream(MediaType$1.AUDIO);
43040
43040
  } catch (e) {
43041
- this.dispatch(event_handler_EventNames.ERROR, e);
43041
+ this.dispatch(event_names_EventNames.ERROR, e);
43042
43042
  throw e;
43043
43043
  }
43044
43044
  }
@@ -43058,7 +43058,7 @@ class EngineClient extends RealtimeEventHandler {
43058
43058
  await this.engine.unpublishScreen(MediaType$1.VIDEO);
43059
43059
  }
43060
43060
  } catch (e) {
43061
- this.dispatch(event_handler_EventNames.ERROR, e);
43061
+ this.dispatch(event_names_EventNames.ERROR, e);
43062
43062
  throw e;
43063
43063
  }
43064
43064
  }
@@ -43071,7 +43071,7 @@ class EngineClient extends RealtimeEventHandler {
43071
43071
  }));
43072
43072
  this._log(`interrupt ${this.joinUserId} ${result}`);
43073
43073
  } catch (e) {
43074
- this.dispatch(event_handler_EventNames.ERROR, e);
43074
+ this.dispatch(event_names_EventNames.ERROR, e);
43075
43075
  throw e;
43076
43076
  }
43077
43077
  }
@@ -43080,7 +43080,7 @@ class EngineClient extends RealtimeEventHandler {
43080
43080
  const result = await this.engine.sendUserMessage(this.joinUserId, JSON.stringify(message));
43081
43081
  this._log(`sendMessage ${this.joinUserId} ${JSON.stringify(message)} ${result}`);
43082
43082
  } catch (e) {
43083
- this.dispatch(event_handler_EventNames.ERROR, e);
43083
+ this.dispatch(event_names_EventNames.ERROR, e);
43084
43084
  throw e;
43085
43085
  }
43086
43086
  }
@@ -43121,7 +43121,7 @@ class EngineClient extends RealtimeEventHandler {
43121
43121
  try {
43122
43122
  await this.engine.startAudioPlaybackDeviceTest('audio-test.wav', 200);
43123
43123
  } catch (e) {
43124
- this.dispatch(event_handler_EventNames.ERROR, e);
43124
+ this.dispatch(event_names_EventNames.ERROR, e);
43125
43125
  throw e;
43126
43126
  }
43127
43127
  }
@@ -43129,7 +43129,7 @@ class EngineClient extends RealtimeEventHandler {
43129
43129
  try {
43130
43130
  this.engine.stopAudioPlaybackDeviceTest();
43131
43131
  } catch (e) {
43132
- this.dispatch(event_handler_EventNames.ERROR, e);
43132
+ this.dispatch(event_names_EventNames.ERROR, e);
43133
43133
  throw e;
43134
43134
  }
43135
43135
  }
@@ -43166,7 +43166,7 @@ class RealtimeClient extends RealtimeEventHandler {
43166
43166
  */ async connect() {
43167
43167
  var _this__config_videoConfig;
43168
43168
  const { botId, conversationId, voiceId, getRoomInfo } = this._config;
43169
- this.dispatch(event_handler_EventNames.CONNECTING, {});
43169
+ this.dispatch(event_names_EventNames.CONNECTING, {});
43170
43170
  let roomInfo;
43171
43171
  try {
43172
43172
  // Step1 get token
@@ -43193,7 +43193,7 @@ class RealtimeClient extends RealtimeEventHandler {
43193
43193
  });
43194
43194
  }
43195
43195
  } catch (error) {
43196
- this.dispatch(event_handler_EventNames.ERROR, error);
43196
+ this.dispatch(event_names_EventNames.ERROR, error);
43197
43197
  throw new RealtimeAPIError(error_RealtimeError.CREATE_ROOM_ERROR, error instanceof Error ? error.message : 'Unknown error', error);
43198
43198
  }
43199
43199
  this._isTestEnv = TEST_APP_ID === roomInfo.app_id;
@@ -43201,17 +43201,17 @@ class RealtimeClient extends RealtimeEventHandler {
43201
43201
  this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo, this._config.videoConfig);
43202
43202
  // Step3 bind engine events
43203
43203
  this._client.bindEngineEvents();
43204
- this._client.on(event_handler_EventNames.ALL, (eventName, data)=>{
43204
+ this._client.on(event_names_EventNames.ALL, (eventName, data)=>{
43205
43205
  this.dispatch(eventName, data, false);
43206
43206
  });
43207
43207
  if (this._config.suppressStationaryNoise) {
43208
43208
  await this._client.enableAudioNoiseReduction();
43209
- this.dispatch(event_handler_EventNames.SUPPRESS_STATIONARY_NOISE, {});
43209
+ this.dispatch(event_names_EventNames.SUPPRESS_STATIONARY_NOISE, {});
43210
43210
  }
43211
43211
  if (this._config.suppressNonStationaryNoise) try {
43212
43212
  await this._client.initAIAnsExtension();
43213
43213
  this._client.changeAIAnsExtension(true);
43214
- this.dispatch(event_handler_EventNames.SUPPRESS_NON_STATIONARY_NOISE, {});
43214
+ this.dispatch(event_names_EventNames.SUPPRESS_NON_STATIONARY_NOISE, {});
43215
43215
  } catch (error) {
43216
43216
  console.warn('Config suppressNonStationaryNoise is not supported', error);
43217
43217
  }
@@ -43229,7 +43229,7 @@ class RealtimeClient extends RealtimeEventHandler {
43229
43229
  await this._client.createLocalStream(roomInfo.uid, this._config.videoConfig);
43230
43230
  // step6 set connected and dispatch connected event
43231
43231
  this.isConnected = true;
43232
- this.dispatch(event_handler_EventNames.CONNECTED, {
43232
+ this.dispatch(event_names_EventNames.CONNECTED, {
43233
43233
  roomId: roomInfo.room_id,
43234
43234
  uid: roomInfo.uid,
43235
43235
  token: roomInfo.token,
@@ -43243,7 +43243,7 @@ class RealtimeClient extends RealtimeEventHandler {
43243
43243
  */ async interrupt() {
43244
43244
  var _this__client;
43245
43245
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.stop());
43246
- this.dispatch(event_handler_EventNames.INTERRUPTED, {});
43246
+ this.dispatch(event_names_EventNames.INTERRUPTED, {});
43247
43247
  }
43248
43248
  /**
43249
43249
  * en: Disconnect from the current session
@@ -43254,7 +43254,7 @@ class RealtimeClient extends RealtimeEventHandler {
43254
43254
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.disconnect());
43255
43255
  this.isConnected = false;
43256
43256
  this._client = null;
43257
- this.dispatch(event_handler_EventNames.DISCONNECTED, {});
43257
+ this.dispatch(event_names_EventNames.DISCONNECTED, {});
43258
43258
  }
43259
43259
  /**
43260
43260
  * en: Send a message to the bot
@@ -43273,14 +43273,14 @@ class RealtimeClient extends RealtimeEventHandler {
43273
43273
  */ async setAudioEnable(isEnable) {
43274
43274
  var _this__client;
43275
43275
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.changeAudioState(isEnable));
43276
- if (isEnable) this.dispatch(event_handler_EventNames.AUDIO_UNMUTED, {});
43277
- else this.dispatch(event_handler_EventNames.AUDIO_MUTED, {});
43276
+ if (isEnable) this.dispatch(event_names_EventNames.AUDIO_UNMUTED, {});
43277
+ else this.dispatch(event_names_EventNames.AUDIO_MUTED, {});
43278
43278
  }
43279
43279
  async setVideoEnable(isEnable) {
43280
43280
  var _this__client;
43281
43281
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.changeVideoState(isEnable));
43282
- if (isEnable) this.dispatch(event_handler_EventNames.VIDEO_ON, {});
43283
- else this.dispatch(event_handler_EventNames.VIDEO_OFF, {});
43282
+ if (isEnable) this.dispatch(event_names_EventNames.VIDEO_ON, {});
43283
+ else this.dispatch(event_names_EventNames.VIDEO_OFF, {});
43284
43284
  }
43285
43285
  /**
43286
43286
  * en: Enable audio properties reporting (debug mode only)
@@ -43322,7 +43322,7 @@ class RealtimeClient extends RealtimeEventHandler {
43322
43322
  */ async setAudioInputDevice(deviceId) {
43323
43323
  var _this__client;
43324
43324
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setAudioInputDevice(deviceId));
43325
- this.dispatch(event_handler_EventNames.AUDIO_INPUT_DEVICE_CHANGED, {
43325
+ this.dispatch(event_names_EventNames.AUDIO_INPUT_DEVICE_CHANGED, {
43326
43326
  deviceId
43327
43327
  });
43328
43328
  }
@@ -43333,14 +43333,14 @@ class RealtimeClient extends RealtimeEventHandler {
43333
43333
  */ async setAudioOutputDevice(deviceId) {
43334
43334
  var _this__client;
43335
43335
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setAudioOutputDevice(deviceId));
43336
- this.dispatch(event_handler_EventNames.AUDIO_OUTPUT_DEVICE_CHANGED, {
43336
+ this.dispatch(event_names_EventNames.AUDIO_OUTPUT_DEVICE_CHANGED, {
43337
43337
  deviceId
43338
43338
  });
43339
43339
  }
43340
43340
  async setVideoInputDevice(deviceId) {
43341
43341
  var _this__client;
43342
43342
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setVideoInputDevice(deviceId));
43343
- this.dispatch(event_handler_EventNames.VIDEO_INPUT_DEVICE_CHANGED, {
43343
+ this.dispatch(event_names_EventNames.VIDEO_INPUT_DEVICE_CHANGED, {
43344
43344
  deviceId
43345
43345
  });
43346
43346
  }
@@ -43409,4 +43409,4 @@ class RealtimeClient extends RealtimeEventHandler {
43409
43409
  this._isSupportVideo = !!config.videoConfig;
43410
43410
  }
43411
43411
  }
43412
- export { event_handler_EventNames as EventNames, RealtimeAPIError, RealtimeClient, error_RealtimeError as RealtimeError, src_utils_namespaceObject as RealtimeUtils };
43412
+ export { event_names_EventNames as EventNames, RealtimeAPIError, RealtimeClient, error_RealtimeError as RealtimeError, src_utils_namespaceObject as RealtimeUtils };
@@ -1,145 +1,3 @@
1
- export declare enum EventNames {
2
- /**
3
- * en: All events
4
- * zh: 所有事件
5
- */
6
- ALL = "realtime.event",
7
- /**
8
- * en: All client events
9
- * zh: 所有客户端事件
10
- */
11
- ALL_CLIENT = "client.*",
12
- /**
13
- * en: All server events
14
- * zh: 所有服务端事件
15
- */
16
- ALL_SERVER = "server.*",
17
- /**
18
- * en: Client connected
19
- * zh: 客户端连接
20
- */
21
- CONNECTED = "client.connected",
22
- /**
23
- * en: Client connecting
24
- * zh: 客户端连接中
25
- */
26
- CONNECTING = "client.connecting",
27
- /**
28
- * en: Client interrupted
29
- * zh: 客户端中断
30
- */
31
- INTERRUPTED = "client.interrupted",
32
- /**
33
- * en: Client disconnected
34
- * zh: 客户端断开
35
- */
36
- DISCONNECTED = "client.disconnected",
37
- /**
38
- * en: Client audio unmuted
39
- * zh: 客户端音频未静音
40
- */
41
- AUDIO_UNMUTED = "client.audio.unmuted",
42
- /**
43
- * en: Client audio muted
44
- * zh: 客户端音频静音
45
- */
46
- AUDIO_MUTED = "client.audio.muted",
47
- /**
48
- * en: Client video on
49
- * zh: 客户端视频开启
50
- */
51
- VIDEO_ON = "client.video.on",
52
- /**
53
- * en: Client video off
54
- * zh: 客户端视频关闭
55
- */
56
- VIDEO_OFF = "client.video.off",
57
- /**
58
- * en: Client video event
59
- * zh: 客户端视频事件
60
- */
61
- PLAYER_EVENT = "client.video.event",
62
- /**
63
- * en: Client error
64
- * zh: 客户端错误
65
- */
66
- ERROR = "client.error",
67
- /**
68
- * en: Audio noise reduction enabled
69
- * zh: 抑制平稳噪声
70
- */
71
- SUPPRESS_STATIONARY_NOISE = "client.suppress.stationary.noise",
72
- /**
73
- * en: Suppress non-stationary noise
74
- * zh: 抑制非平稳噪声
75
- */
76
- SUPPRESS_NON_STATIONARY_NOISE = "client.suppress.non.stationary.noise",
77
- /**
78
- * en: Audio input device changed
79
- * zh: 音频输入设备改变
80
- */
81
- AUDIO_INPUT_DEVICE_CHANGED = "client.input.device.changed",
82
- /**
83
- * en: Audio output device changed
84
- * zh: 音频输出设备改变
85
- */
86
- AUDIO_OUTPUT_DEVICE_CHANGED = "client.output.device.changed",
87
- /**
88
- * en: Video input device changed
89
- * zh: 视频输入设备改变
90
- */
91
- VIDEO_INPUT_DEVICE_CHANGED = "client.video.input.device.changed",
92
- /**
93
- * en: Network quality changed
94
- * zh: 网络质量改变
95
- */
96
- NETWORK_QUALITY = "client.network.quality",
97
- /**
98
- * en: Bot joined
99
- * zh: Bot 加入
100
- */
101
- BOT_JOIN = "server.bot.join",
102
- /**
103
- * en: Bot left
104
- * zh: Bot 离开
105
- */
106
- BOT_LEAVE = "server.bot.leave",
107
- /**
108
- * en: Audio speech started
109
- * zh: 开始说话
110
- */
111
- AUDIO_AGENT_SPEECH_STARTED = "server.audio.agent.speech_started",
112
- /**
113
- * en: Audio speech stopped
114
- * zh: 停止说话
115
- */
116
- AUDIO_AGENT_SPEECH_STOPPED = "server.audio.agent.speech_stopped",
117
- /**
118
- * en: Server error
119
- * zh: 服务端错误
120
- */
121
- SERVER_ERROR = "server.error",
122
- /**
123
- * en: User speech started
124
- * zh: 用户开始说话
125
- */
126
- AUDIO_USER_SPEECH_STARTED = "server.audio.user.speech_started",
127
- /**
128
- * en: User speech stopped
129
- * zh: 用户停止说话
130
- */
131
- AUDIO_USER_SPEECH_STOPPED = "server.audio.user.speech_stopped",
132
- /**
133
- * en: User successfully enters the room
134
- * zh: 用户成功进入房间后,会收到该事件
135
- */
136
- SESSION_CREATED = "server.session.created",
137
- /**
138
- * en: Session updated
139
- * zh: 会话更新
140
- */
141
- SESSION_UPDATE = "server.session.update"
142
- }
143
1
  export type EventCallback = (eventName: string, event: unknown) => void;
144
2
  export declare class RealtimeEventHandler {
145
3
  private eventHandlers;
@@ -0,0 +1,142 @@
1
+ export declare enum EventNames {
2
+ /**
3
+ * en: All events
4
+ * zh: 所有事件
5
+ */
6
+ ALL = "realtime.event",
7
+ /**
8
+ * en: All client events
9
+ * zh: 所有客户端事件
10
+ */
11
+ ALL_CLIENT = "client.*",
12
+ /**
13
+ * en: All server events
14
+ * zh: 所有服务端事件
15
+ */
16
+ ALL_SERVER = "server.*",
17
+ /**
18
+ * en: Client connected
19
+ * zh: 客户端连接
20
+ */
21
+ CONNECTED = "client.connected",
22
+ /**
23
+ * en: Client connecting
24
+ * zh: 客户端连接中
25
+ */
26
+ CONNECTING = "client.connecting",
27
+ /**
28
+ * en: Client interrupted
29
+ * zh: 客户端中断
30
+ */
31
+ INTERRUPTED = "client.interrupted",
32
+ /**
33
+ * en: Client disconnected
34
+ * zh: 客户端断开
35
+ */
36
+ DISCONNECTED = "client.disconnected",
37
+ /**
38
+ * en: Client audio unmuted
39
+ * zh: 客户端音频未静音
40
+ */
41
+ AUDIO_UNMUTED = "client.audio.unmuted",
42
+ /**
43
+ * en: Client audio muted
44
+ * zh: 客户端音频静音
45
+ */
46
+ AUDIO_MUTED = "client.audio.muted",
47
+ /**
48
+ * en: Client video on
49
+ * zh: 客户端视频开启
50
+ */
51
+ VIDEO_ON = "client.video.on",
52
+ /**
53
+ * en: Client video off
54
+ * zh: 客户端视频关闭
55
+ */
56
+ VIDEO_OFF = "client.video.off",
57
+ /**
58
+ * en: Client video event
59
+ * zh: 客户端视频事件
60
+ */
61
+ PLAYER_EVENT = "client.video.event",
62
+ /**
63
+ * en: Client error
64
+ * zh: 客户端错误
65
+ */
66
+ ERROR = "client.error",
67
+ /**
68
+ * en: Audio noise reduction enabled
69
+ * zh: 抑制平稳噪声
70
+ */
71
+ SUPPRESS_STATIONARY_NOISE = "client.suppress.stationary.noise",
72
+ /**
73
+ * en: Suppress non-stationary noise
74
+ * zh: 抑制非平稳噪声
75
+ */
76
+ SUPPRESS_NON_STATIONARY_NOISE = "client.suppress.non.stationary.noise",
77
+ /**
78
+ * en: Audio input device changed
79
+ * zh: 音频输入设备改变
80
+ */
81
+ AUDIO_INPUT_DEVICE_CHANGED = "client.input.device.changed",
82
+ /**
83
+ * en: Audio output device changed
84
+ * zh: 音频输出设备改变
85
+ */
86
+ AUDIO_OUTPUT_DEVICE_CHANGED = "client.output.device.changed",
87
+ /**
88
+ * en: Video input device changed
89
+ * zh: 视频输入设备改变
90
+ */
91
+ VIDEO_INPUT_DEVICE_CHANGED = "client.video.input.device.changed",
92
+ /**
93
+ * en: Network quality changed
94
+ * zh: 网络质量改变
95
+ */
96
+ NETWORK_QUALITY = "client.network.quality",
97
+ /**
98
+ * en: Bot joined
99
+ * zh: Bot 加入
100
+ */
101
+ BOT_JOIN = "server.bot.join",
102
+ /**
103
+ * en: Bot left
104
+ * zh: Bot 离开
105
+ */
106
+ BOT_LEAVE = "server.bot.leave",
107
+ /**
108
+ * en: Audio speech started
109
+ * zh: 开始说话
110
+ */
111
+ AUDIO_AGENT_SPEECH_STARTED = "server.audio.agent.speech_started",
112
+ /**
113
+ * en: Audio speech stopped
114
+ * zh: 停止说话
115
+ */
116
+ AUDIO_AGENT_SPEECH_STOPPED = "server.audio.agent.speech_stopped",
117
+ /**
118
+ * en: Server error
119
+ * zh: 服务端错误
120
+ */
121
+ SERVER_ERROR = "server.error",
122
+ /**
123
+ * en: User speech started
124
+ * zh: 用户开始说话
125
+ */
126
+ AUDIO_USER_SPEECH_STARTED = "server.audio.user.speech_started",
127
+ /**
128
+ * en: User speech stopped
129
+ * zh: 用户停止说话
130
+ */
131
+ AUDIO_USER_SPEECH_STOPPED = "server.audio.user.speech_stopped",
132
+ /**
133
+ * en: User successfully enters the room
134
+ * zh: 用户成功进入房间后,会收到该事件
135
+ */
136
+ SESSION_CREATED = "server.session.created",
137
+ /**
138
+ * en: Session updated
139
+ * zh: 会话更新
140
+ */
141
+ SESSION_UPDATE = "server.session.update"
142
+ }
@@ -1,7 +1,8 @@
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 { RealtimeEventHandler, EventNames } from './event-handler';
4
+ import { EventNames } from './event-names';
5
+ import { RealtimeEventHandler } from './event-handler';
5
6
  import { RealtimeAPIError, RealtimeError } from './error';
6
7
  export interface VideoConfig {
7
8
  videoOnDefault?: boolean /** optional, Whether to turn on video by default, defaults to true */;
package/dist/umd/index.js CHANGED
@@ -98,7 +98,7 @@
98
98
  RealtimeAPIError: ()=>/* reexport */ RealtimeAPIError,
99
99
  RealtimeUtils: ()=>/* reexport */ src_utils_namespaceObject,
100
100
  RealtimeError: ()=>/* reexport */ error_RealtimeError,
101
- EventNames: ()=>/* reexport */ event_handler_EventNames,
101
+ EventNames: ()=>/* reexport */ event_names_EventNames,
102
102
  RealtimeClient: ()=>/* binding */ RealtimeClient
103
103
  });
104
104
  // NAMESPACE OBJECT: ../../common/temp/default/node_modules/.pnpm/axios@1.7.7_debug@4.3.7/node_modules/axios/lib/platform/common/utils.js
@@ -4666,7 +4666,7 @@ and limitations under the License.
4666
4666
  // EXTERNAL MODULE: os (ignored)
4667
4667
  var os_ignored_ = __webpack_require__("?9050");
4668
4668
  var os_ignored_default = /*#__PURE__*/ __webpack_require__.n(os_ignored_);
4669
- var package_namespaceObject = JSON.parse('{"name":"@coze/api","version":"1.1.1","description":"Official Coze Node.js SDK for seamless AI integration into your applications | 扣子官方 Node.js SDK,助您轻松集成 AI 能力到应用中","keywords":["coze","ai","nodejs","sdk","chatbot","typescript"],"homepage":"https://github.com/coze-dev/coze-js/tree/main/packages/coze-js","bugs":{"url":"https://github.com/coze-dev/coze-js/issues"},"repository":{"type":"git","url":"https://github.com/coze-dev/coze-js.git","directory":"packages/coze-js"},"license":"MIT","author":"Leeight <leeight@gmail.com>","exports":{".":"./src/index.ts","./ws-tools":"./src/ws-tools/index.ts"},"main":"src/index.ts","module":"src/index.ts","browser":{"crypto":false,"os":false,"jsonwebtoken":false,"node-fetch":false},"typesVersions":{"*":{".":["dist/types/index.d.ts"],"ws-tools":["dist/types/ws-tools/ws-tools/index.d.ts"]}},"files":["dist","LICENSE","README.md","README.zh-CN.md"],"scripts":{"build":"rslib build","format":"prettier --write .","lint":"eslint ./ --cache --quiet","start":"rslib build -w","test":"vitest","test:cov":"vitest --coverage --run"},"dependencies":{"jsonwebtoken":"^9.0.2","node-fetch":"^2.x","reconnecting-websocket":"^4.4.0","uuid":"^10.0.0","ws":"^8.11.0"},"devDependencies":{"@coze-infra/eslint-config":"workspace:*","@coze-infra/ts-config":"workspace:*","@coze-infra/vitest-config":"workspace:*","@rslib/core":"0.0.18","@swc/core":"^1.3.14","@types/jsonwebtoken":"^9.0.0","@types/node":"^20","@types/node-fetch":"^2.x","@types/uuid":"^9.0.1","@types/whatwg-fetch":"^0.0.33","@types/ws":"^8.5.1","@vitest/coverage-v8":"~2.1.4","axios":"^1.7.7","typescript":"^5.5.3","vitest":"~2.1.4"},"peerDependencies":{"axios":"^1.7.1"},"cozePublishConfig":{"exports":{".":{"require":"./dist/cjs/index.js","import":"./dist/esm/index.js","types":"./dist/types/index.d.ts"},"./ws-tools":{"require":"./dist/cjs/ws-tools/index.js","import":"./dist/esm/ws-tools/index.js","types":"./dist/types/ws-tools/ws-tools/index.d.ts"}},"main":"dist/cjs/index.js","module":"dist/esm/index.js","types":"dist/types/index.d.ts"}}'); // CONCATENATED MODULE: ../coze-js/src/version.ts
4669
+ var package_namespaceObject = JSON.parse('{"name":"@coze/api","version":"1.1.1-beta.1","description":"Official Coze Node.js SDK for seamless AI integration into your applications | 扣子官方 Node.js SDK,助您轻松集成 AI 能力到应用中","keywords":["coze","ai","nodejs","sdk","chatbot","typescript"],"homepage":"https://github.com/coze-dev/coze-js/tree/main/packages/coze-js","bugs":{"url":"https://github.com/coze-dev/coze-js/issues"},"repository":{"type":"git","url":"https://github.com/coze-dev/coze-js.git","directory":"packages/coze-js"},"license":"MIT","author":"Leeight <leeight@gmail.com>","exports":{".":"./src/index.ts","./ws-tools":"./src/ws-tools/index.ts"},"main":"src/index.ts","module":"src/index.ts","browser":{"crypto":false,"os":false,"jsonwebtoken":false,"node-fetch":false},"typesVersions":{"*":{".":["dist/types/index.d.ts"],"ws-tools":["dist/types/ws-tools/ws-tools/index.d.ts"]}},"files":["dist","LICENSE","README.md","README.zh-CN.md"],"scripts":{"build":"rslib build","format":"prettier --write .","lint":"eslint ./ --cache --quiet","start":"rslib build -w","test":"vitest","test:cov":"vitest --coverage --run"},"dependencies":{"jsonwebtoken":"^9.0.2","node-fetch":"^2.x","reconnecting-websocket":"^4.4.0","uuid":"^10.0.0","ws":"^8.11.0"},"devDependencies":{"@coze-infra/eslint-config":"workspace:*","@coze-infra/ts-config":"workspace:*","@coze-infra/vitest-config":"workspace:*","@rslib/core":"0.0.18","@swc/core":"^1.3.14","@types/jsonwebtoken":"^9.0.0","@types/node":"^20","@types/node-fetch":"^2.x","@types/uuid":"^9.0.1","@types/whatwg-fetch":"^0.0.33","@types/ws":"^8.5.1","@vitest/coverage-v8":"~2.1.4","axios":"^1.7.7","typescript":"^5.5.3","vitest":"~2.1.4"},"peerDependencies":{"axios":"^1.7.1"},"cozePublishConfig":{"exports":{".":{"require":"./dist/cjs/index.js","import":"./dist/esm/index.mjs","types":"./dist/types/index.d.ts"},"./ws-tools":{"require":"./dist/cjs/ws-tools/index.js","import":"./dist/esm/ws-tools/index.mjs","types":"./dist/types/ws-tools/ws-tools/index.d.ts"}},"main":"dist/cjs/index.js","module":"dist/esm/index.mjs","types":"dist/types/index.d.ts"}}'); // CONCATENATED MODULE: ../coze-js/src/version.ts
4670
4670
  const { version: version_version } = package_namespaceObject;
4671
4671
  const getEnv = ()=>{
4672
4672
  const nodeVersion = process.version.slice(1); // Remove 'v' prefix
@@ -39470,34 +39470,7 @@ and limitations under the License.
39470
39470
  var _navigator_mediaDevices, _navigator;
39471
39471
  return !!(null === (_navigator = navigator) || void 0 === _navigator ? void 0 : null === (_navigator_mediaDevices = _navigator.mediaDevices) || void 0 === _navigator_mediaDevices ? void 0 : _navigator_mediaDevices.getDisplayMedia);
39472
39472
  }
39473
- var error_RealtimeError = /*#__PURE__*/ function(RealtimeError) {
39474
- RealtimeError["DEVICE_ACCESS_ERROR"] = "DEVICE_ACCESS_ERROR";
39475
- RealtimeError["STREAM_CREATION_ERROR"] = "STREAM_CREATION_ERROR";
39476
- RealtimeError["CONNECTION_ERROR"] = "CONNECTION_ERROR";
39477
- RealtimeError["DISCONNECTION_ERROR"] = "DISCONNECTION_ERROR";
39478
- RealtimeError["INTERRUPT_ERROR"] = "INTERRUPT_ERROR";
39479
- RealtimeError["EVENT_HANDLER_ERROR"] = "EVENT_HANDLER_ERROR";
39480
- RealtimeError["PERMISSION_DENIED"] = "PERMISSION_DENIED";
39481
- RealtimeError["NETWORK_ERROR"] = "NETWORK_ERROR";
39482
- RealtimeError["INVALID_STATE"] = "INVALID_STATE";
39483
- RealtimeError["CREATE_ROOM_ERROR"] = "CREATE_ROOM_ERROR";
39484
- RealtimeError["PARSE_MESSAGE_ERROR"] = "PARSE_MESSAGE_ERROR";
39485
- RealtimeError["HANDLER_MESSAGE_ERROR"] = "HANDLER_MESSAGE_ERROR";
39486
- return RealtimeError;
39487
- }({});
39488
- class RealtimeAPIError extends Error {
39489
- /**
39490
- * @param code - Error code
39491
- * @param message - Error message
39492
- * @param error - Error object
39493
- */ constructor(code, message, error){
39494
- super(`[${code}] ${message}`);
39495
- this.name = 'RealtimeAPIError';
39496
- this.code = code;
39497
- this.error = error;
39498
- }
39499
- }
39500
- var event_handler_EventNames = /*#__PURE__*/ function(EventNames) {
39473
+ var event_names_EventNames = /*#__PURE__*/ function(EventNames) {
39501
39474
  /**
39502
39475
  * en: All events
39503
39476
  * zh: 所有事件
@@ -39612,6 +39585,33 @@ and limitations under the License.
39612
39585
  */ EventNames["SESSION_UPDATE"] = "server.session.update";
39613
39586
  return EventNames;
39614
39587
  }({});
39588
+ var error_RealtimeError = /*#__PURE__*/ function(RealtimeError) {
39589
+ RealtimeError["DEVICE_ACCESS_ERROR"] = "DEVICE_ACCESS_ERROR";
39590
+ RealtimeError["STREAM_CREATION_ERROR"] = "STREAM_CREATION_ERROR";
39591
+ RealtimeError["CONNECTION_ERROR"] = "CONNECTION_ERROR";
39592
+ RealtimeError["DISCONNECTION_ERROR"] = "DISCONNECTION_ERROR";
39593
+ RealtimeError["INTERRUPT_ERROR"] = "INTERRUPT_ERROR";
39594
+ RealtimeError["EVENT_HANDLER_ERROR"] = "EVENT_HANDLER_ERROR";
39595
+ RealtimeError["PERMISSION_DENIED"] = "PERMISSION_DENIED";
39596
+ RealtimeError["NETWORK_ERROR"] = "NETWORK_ERROR";
39597
+ RealtimeError["INVALID_STATE"] = "INVALID_STATE";
39598
+ RealtimeError["CREATE_ROOM_ERROR"] = "CREATE_ROOM_ERROR";
39599
+ RealtimeError["PARSE_MESSAGE_ERROR"] = "PARSE_MESSAGE_ERROR";
39600
+ RealtimeError["HANDLER_MESSAGE_ERROR"] = "HANDLER_MESSAGE_ERROR";
39601
+ return RealtimeError;
39602
+ }({});
39603
+ class RealtimeAPIError extends Error {
39604
+ /**
39605
+ * @param code - Error code
39606
+ * @param message - Error message
39607
+ * @param error - Error object
39608
+ */ constructor(code, message, error){
39609
+ super(`[${code}] ${message}`);
39610
+ this.name = 'RealtimeAPIError';
39611
+ this.code = code;
39612
+ this.error = error;
39613
+ }
39614
+ }
39615
39615
  class RealtimeEventHandler {
39616
39616
  clearEventHandlers() {
39617
39617
  this.eventHandlers = {};
@@ -39647,11 +39647,11 @@ and limitations under the License.
39647
39647
  if (consoleLog) this._log(`dispatch ${eventName} event`, event);
39648
39648
  const handlers = (this.eventHandlers[eventName] || []).slice();
39649
39649
  this._dispatchToHandlers(eventName, event, handlers);
39650
- const allHandlers = (this.eventHandlers["realtime.event"] || []).slice();
39650
+ const allHandlers = (this.eventHandlers[event_names_EventNames.ALL] || []).slice();
39651
39651
  this._dispatchToHandlers(eventName, event, allHandlers);
39652
- const allClientHandlers = (this.eventHandlers["client.*"] || []).slice();
39652
+ const allClientHandlers = (this.eventHandlers[event_names_EventNames.ALL_CLIENT] || []).slice();
39653
39653
  this._dispatchToHandlers(eventName, event, allClientHandlers, 'client.');
39654
- const allServerHandlers = (this.eventHandlers["server.*"] || []).slice();
39654
+ const allServerHandlers = (this.eventHandlers[event_names_EventNames.ALL_SERVER] || []).slice();
39655
39655
  this._dispatchToHandlers(eventName, event, allServerHandlers, 'server.');
39656
39656
  }
39657
39657
  _log(message, event) {
@@ -42946,32 +42946,32 @@ and limitations under the License.
42946
42946
  this.dispatch(`server.${message.event_type}`, message);
42947
42947
  } catch (e) {
42948
42948
  if (e instanceof RealtimeAPIError) {
42949
- if (e.code === error_RealtimeError.PARSE_MESSAGE_ERROR) this.dispatch(event_handler_EventNames.ERROR, {
42949
+ if (e.code === error_RealtimeError.PARSE_MESSAGE_ERROR) this.dispatch(event_names_EventNames.ERROR, {
42950
42950
  message: `Failed to parse message: ${event.message}`,
42951
42951
  error: e
42952
42952
  });
42953
- else if (e.code === error_RealtimeError.HANDLER_MESSAGE_ERROR) this.dispatch(event_handler_EventNames.ERROR, {
42953
+ else if (e.code === error_RealtimeError.HANDLER_MESSAGE_ERROR) this.dispatch(event_names_EventNames.ERROR, {
42954
42954
  message: `Failed to handle message: ${event.message}`,
42955
42955
  error: e
42956
42956
  });
42957
- } else this.dispatch(event_handler_EventNames.ERROR, e);
42957
+ } else this.dispatch(event_names_EventNames.ERROR, e);
42958
42958
  }
42959
42959
  }
42960
42960
  handleEventError(e) {
42961
- this.dispatch(event_handler_EventNames.ERROR, e);
42961
+ this.dispatch(event_names_EventNames.ERROR, e);
42962
42962
  }
42963
42963
  handleUserJoin(event) {
42964
42964
  this.joinUserId = event.userInfo.userId;
42965
- this.dispatch(event_handler_EventNames.BOT_JOIN, event);
42965
+ this.dispatch(event_names_EventNames.BOT_JOIN, event);
42966
42966
  }
42967
42967
  handleUserLeave(event) {
42968
- this.dispatch(event_handler_EventNames.BOT_LEAVE, event);
42968
+ this.dispatch(event_names_EventNames.BOT_LEAVE, event);
42969
42969
  }
42970
42970
  handlePlayerEvent(event) {
42971
- this.dispatch(event_handler_EventNames.PLAYER_EVENT, event);
42971
+ this.dispatch(event_names_EventNames.PLAYER_EVENT, event);
42972
42972
  }
42973
42973
  handleNetworkQuality(uplinkNetworkQuality, downlinkNetworkQuality) {
42974
- this.dispatch(event_handler_EventNames.NETWORK_QUALITY, {
42974
+ this.dispatch(event_names_EventNames.NETWORK_QUALITY, {
42975
42975
  uplinkNetworkQuality,
42976
42976
  downlinkNetworkQuality
42977
42977
  });
@@ -43047,7 +43047,7 @@ and limitations under the License.
43047
43047
  this.clearEventHandlers();
43048
43048
  index_esm_min_index.destroyEngine(this.engine);
43049
43049
  } catch (e) {
43050
- this.dispatch(event_handler_EventNames.ERROR, e);
43050
+ this.dispatch(event_names_EventNames.ERROR, e);
43051
43051
  throw e;
43052
43052
  }
43053
43053
  }
@@ -43056,7 +43056,7 @@ and limitations under the License.
43056
43056
  if (isMicOn) await this.engine.publishStream(MediaType$1.AUDIO);
43057
43057
  else await this.engine.unpublishStream(MediaType$1.AUDIO);
43058
43058
  } catch (e) {
43059
- this.dispatch(event_handler_EventNames.ERROR, e);
43059
+ this.dispatch(event_names_EventNames.ERROR, e);
43060
43060
  throw e;
43061
43061
  }
43062
43062
  }
@@ -43076,7 +43076,7 @@ and limitations under the License.
43076
43076
  await this.engine.unpublishScreen(MediaType$1.VIDEO);
43077
43077
  }
43078
43078
  } catch (e) {
43079
- this.dispatch(event_handler_EventNames.ERROR, e);
43079
+ this.dispatch(event_names_EventNames.ERROR, e);
43080
43080
  throw e;
43081
43081
  }
43082
43082
  }
@@ -43089,7 +43089,7 @@ and limitations under the License.
43089
43089
  }));
43090
43090
  this._log(`interrupt ${this.joinUserId} ${result}`);
43091
43091
  } catch (e) {
43092
- this.dispatch(event_handler_EventNames.ERROR, e);
43092
+ this.dispatch(event_names_EventNames.ERROR, e);
43093
43093
  throw e;
43094
43094
  }
43095
43095
  }
@@ -43098,7 +43098,7 @@ and limitations under the License.
43098
43098
  const result = await this.engine.sendUserMessage(this.joinUserId, JSON.stringify(message));
43099
43099
  this._log(`sendMessage ${this.joinUserId} ${JSON.stringify(message)} ${result}`);
43100
43100
  } catch (e) {
43101
- this.dispatch(event_handler_EventNames.ERROR, e);
43101
+ this.dispatch(event_names_EventNames.ERROR, e);
43102
43102
  throw e;
43103
43103
  }
43104
43104
  }
@@ -43139,7 +43139,7 @@ and limitations under the License.
43139
43139
  try {
43140
43140
  await this.engine.startAudioPlaybackDeviceTest('audio-test.wav', 200);
43141
43141
  } catch (e) {
43142
- this.dispatch(event_handler_EventNames.ERROR, e);
43142
+ this.dispatch(event_names_EventNames.ERROR, e);
43143
43143
  throw e;
43144
43144
  }
43145
43145
  }
@@ -43147,7 +43147,7 @@ and limitations under the License.
43147
43147
  try {
43148
43148
  this.engine.stopAudioPlaybackDeviceTest();
43149
43149
  } catch (e) {
43150
- this.dispatch(event_handler_EventNames.ERROR, e);
43150
+ this.dispatch(event_names_EventNames.ERROR, e);
43151
43151
  throw e;
43152
43152
  }
43153
43153
  }
@@ -43184,7 +43184,7 @@ and limitations under the License.
43184
43184
  */ async connect() {
43185
43185
  var _this__config_videoConfig;
43186
43186
  const { botId, conversationId, voiceId, getRoomInfo } = this._config;
43187
- this.dispatch(event_handler_EventNames.CONNECTING, {});
43187
+ this.dispatch(event_names_EventNames.CONNECTING, {});
43188
43188
  let roomInfo;
43189
43189
  try {
43190
43190
  // Step1 get token
@@ -43211,7 +43211,7 @@ and limitations under the License.
43211
43211
  });
43212
43212
  }
43213
43213
  } catch (error) {
43214
- this.dispatch(event_handler_EventNames.ERROR, error);
43214
+ this.dispatch(event_names_EventNames.ERROR, error);
43215
43215
  throw new RealtimeAPIError(error_RealtimeError.CREATE_ROOM_ERROR, error instanceof Error ? error.message : 'Unknown error', error);
43216
43216
  }
43217
43217
  this._isTestEnv = TEST_APP_ID === roomInfo.app_id;
@@ -43219,17 +43219,17 @@ and limitations under the License.
43219
43219
  this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo, this._config.videoConfig);
43220
43220
  // Step3 bind engine events
43221
43221
  this._client.bindEngineEvents();
43222
- this._client.on(event_handler_EventNames.ALL, (eventName, data)=>{
43222
+ this._client.on(event_names_EventNames.ALL, (eventName, data)=>{
43223
43223
  this.dispatch(eventName, data, false);
43224
43224
  });
43225
43225
  if (this._config.suppressStationaryNoise) {
43226
43226
  await this._client.enableAudioNoiseReduction();
43227
- this.dispatch(event_handler_EventNames.SUPPRESS_STATIONARY_NOISE, {});
43227
+ this.dispatch(event_names_EventNames.SUPPRESS_STATIONARY_NOISE, {});
43228
43228
  }
43229
43229
  if (this._config.suppressNonStationaryNoise) try {
43230
43230
  await this._client.initAIAnsExtension();
43231
43231
  this._client.changeAIAnsExtension(true);
43232
- this.dispatch(event_handler_EventNames.SUPPRESS_NON_STATIONARY_NOISE, {});
43232
+ this.dispatch(event_names_EventNames.SUPPRESS_NON_STATIONARY_NOISE, {});
43233
43233
  } catch (error) {
43234
43234
  console.warn('Config suppressNonStationaryNoise is not supported', error);
43235
43235
  }
@@ -43247,7 +43247,7 @@ and limitations under the License.
43247
43247
  await this._client.createLocalStream(roomInfo.uid, this._config.videoConfig);
43248
43248
  // step6 set connected and dispatch connected event
43249
43249
  this.isConnected = true;
43250
- this.dispatch(event_handler_EventNames.CONNECTED, {
43250
+ this.dispatch(event_names_EventNames.CONNECTED, {
43251
43251
  roomId: roomInfo.room_id,
43252
43252
  uid: roomInfo.uid,
43253
43253
  token: roomInfo.token,
@@ -43261,7 +43261,7 @@ and limitations under the License.
43261
43261
  */ async interrupt() {
43262
43262
  var _this__client;
43263
43263
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.stop());
43264
- this.dispatch(event_handler_EventNames.INTERRUPTED, {});
43264
+ this.dispatch(event_names_EventNames.INTERRUPTED, {});
43265
43265
  }
43266
43266
  /**
43267
43267
  * en: Disconnect from the current session
@@ -43272,7 +43272,7 @@ and limitations under the License.
43272
43272
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.disconnect());
43273
43273
  this.isConnected = false;
43274
43274
  this._client = null;
43275
- this.dispatch(event_handler_EventNames.DISCONNECTED, {});
43275
+ this.dispatch(event_names_EventNames.DISCONNECTED, {});
43276
43276
  }
43277
43277
  /**
43278
43278
  * en: Send a message to the bot
@@ -43291,14 +43291,14 @@ and limitations under the License.
43291
43291
  */ async setAudioEnable(isEnable) {
43292
43292
  var _this__client;
43293
43293
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.changeAudioState(isEnable));
43294
- if (isEnable) this.dispatch(event_handler_EventNames.AUDIO_UNMUTED, {});
43295
- else this.dispatch(event_handler_EventNames.AUDIO_MUTED, {});
43294
+ if (isEnable) this.dispatch(event_names_EventNames.AUDIO_UNMUTED, {});
43295
+ else this.dispatch(event_names_EventNames.AUDIO_MUTED, {});
43296
43296
  }
43297
43297
  async setVideoEnable(isEnable) {
43298
43298
  var _this__client;
43299
43299
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.changeVideoState(isEnable));
43300
- if (isEnable) this.dispatch(event_handler_EventNames.VIDEO_ON, {});
43301
- else this.dispatch(event_handler_EventNames.VIDEO_OFF, {});
43300
+ if (isEnable) this.dispatch(event_names_EventNames.VIDEO_ON, {});
43301
+ else this.dispatch(event_names_EventNames.VIDEO_OFF, {});
43302
43302
  }
43303
43303
  /**
43304
43304
  * en: Enable audio properties reporting (debug mode only)
@@ -43340,7 +43340,7 @@ and limitations under the License.
43340
43340
  */ async setAudioInputDevice(deviceId) {
43341
43341
  var _this__client;
43342
43342
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setAudioInputDevice(deviceId));
43343
- this.dispatch(event_handler_EventNames.AUDIO_INPUT_DEVICE_CHANGED, {
43343
+ this.dispatch(event_names_EventNames.AUDIO_INPUT_DEVICE_CHANGED, {
43344
43344
  deviceId
43345
43345
  });
43346
43346
  }
@@ -43351,14 +43351,14 @@ and limitations under the License.
43351
43351
  */ async setAudioOutputDevice(deviceId) {
43352
43352
  var _this__client;
43353
43353
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setAudioOutputDevice(deviceId));
43354
- this.dispatch(event_handler_EventNames.AUDIO_OUTPUT_DEVICE_CHANGED, {
43354
+ this.dispatch(event_names_EventNames.AUDIO_OUTPUT_DEVICE_CHANGED, {
43355
43355
  deviceId
43356
43356
  });
43357
43357
  }
43358
43358
  async setVideoInputDevice(deviceId) {
43359
43359
  var _this__client;
43360
43360
  await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setVideoInputDevice(deviceId));
43361
- this.dispatch(event_handler_EventNames.VIDEO_INPUT_DEVICE_CHANGED, {
43361
+ this.dispatch(event_names_EventNames.VIDEO_INPUT_DEVICE_CHANGED, {
43362
43362
  deviceId
43363
43363
  });
43364
43364
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coze/realtime-api",
3
- "version": "1.1.1-beta.1",
3
+ "version": "1.1.1-beta.2",
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",
@@ -49,7 +49,7 @@
49
49
  "test:cov": "vitest --coverage --run"
50
50
  },
51
51
  "dependencies": {
52
- "@coze/api": "1.1.1",
52
+ "@coze/api": "1.1.1-beta.1",
53
53
  "@volcengine/rtc": "^4.62.1"
54
54
  },
55
55
  "devDependencies": {