@zeewain/3d-avatar-sdk 1.2.1 → 1.2.3

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.
Files changed (55) hide show
  1. package/README.md +3 -4
  2. package/dist/assets/Build/webgl.data.unityweb +0 -0
  3. package/dist/assets/Build/webgl.framework.js.unityweb +0 -0
  4. package/dist/assets/Build/webgl.wasm.unityweb +0 -0
  5. package/dist/examples/test-umd/index.html +762 -0
  6. package/dist/examples/test-vue2/.eslintignore +45 -0
  7. package/dist/examples/test-vue2/.eslintrc.js +174 -0
  8. package/dist/examples/test-vue2/.stylelintignore +50 -0
  9. package/dist/examples/test-vue2/.stylelintrc.js +79 -0
  10. package/dist/examples/test-vue2/README.md +139 -0
  11. package/dist/examples/test-vue2/babel.config.js +14 -0
  12. package/dist/examples/test-vue2/package.json +53 -0
  13. package/dist/examples/test-vue2/pnpm-lock.yaml +8776 -0
  14. package/dist/examples/test-vue2/public/index.html +19 -0
  15. package/dist/examples/test-vue2/setup.js +170 -0
  16. package/dist/examples/test-vue2/src/App.vue +943 -0
  17. package/dist/examples/test-vue2/src/components/BroadcastAPI.vue +666 -0
  18. package/dist/examples/test-vue2/src/components/CameraAPI.vue +414 -0
  19. package/dist/examples/test-vue2/src/components/GlobalConfig.vue +200 -0
  20. package/dist/examples/test-vue2/src/components/InfoCards.vue +294 -0
  21. package/dist/examples/test-vue2/src/components/InitAPI.vue +334 -0
  22. package/dist/examples/test-vue2/src/components/LogPanel.vue +249 -0
  23. package/dist/examples/test-vue2/src/components/MotionControlAPI.vue +400 -0
  24. package/dist/examples/test-vue2/src/components/UnityPreview.vue +201 -0
  25. package/dist/examples/test-vue2/src/main.js +16 -0
  26. package/dist/examples/test-vue2/vue.config.js +41 -0
  27. package/dist/examples/test-vue3/.eslintrc +3 -0
  28. package/dist/examples/test-vue3/.stylelintignore +3 -0
  29. package/dist/examples/test-vue3/.stylelintrc +48 -0
  30. package/dist/examples/test-vue3/README.md +236 -0
  31. package/dist/examples/test-vue3/env.d.ts +8 -0
  32. package/dist/examples/test-vue3/index.html +95 -0
  33. package/dist/examples/test-vue3/package.json +55 -0
  34. package/dist/examples/test-vue3/pnpm-lock.yaml +4636 -0
  35. package/dist/examples/test-vue3/setup.js +167 -0
  36. package/dist/examples/test-vue3/src/App.vue +962 -0
  37. package/dist/examples/test-vue3/src/components/BroadcastAPI.vue +636 -0
  38. package/dist/examples/test-vue3/src/components/CameraAPI.vue +376 -0
  39. package/dist/examples/test-vue3/src/components/GlobalConfig.vue +213 -0
  40. package/dist/examples/test-vue3/src/components/InfoCards.vue +288 -0
  41. package/dist/examples/test-vue3/src/components/InitAPI.vue +339 -0
  42. package/dist/examples/test-vue3/src/components/LogPanel.vue +236 -0
  43. package/dist/examples/test-vue3/src/components/MotionControlAPI.vue +373 -0
  44. package/dist/examples/test-vue3/src/components/UnityPreview.vue +189 -0
  45. package/dist/examples/test-vue3/src/main.ts +12 -0
  46. package/dist/examples/test-vue3/src/types.ts +9 -0
  47. package/dist/examples/test-vue3/tsconfig.json +44 -0
  48. package/dist/examples/test-vue3/tsconfig.node.json +14 -0
  49. package/dist/examples/test-vue3/vite.config.ts +75 -0
  50. package/dist/index.d.ts +15 -9
  51. package/dist/index.es5.js +75 -27
  52. package/dist/index.es5.umd.js +75 -27
  53. package/dist/index.esm.js +78 -22
  54. package/dist/index.umd.cjs +78 -22
  55. package/package.json +4 -3
@@ -12150,7 +12150,7 @@
12150
12150
  NetworkErrorCode[NetworkErrorCode["CONNECTION_FAILED"] = 1001] = "CONNECTION_FAILED";
12151
12151
  /** 请求超时 */
12152
12152
  NetworkErrorCode[NetworkErrorCode["REQUEST_TIMEOUT"] = 1002] = "REQUEST_TIMEOUT";
12153
- /** 服务器错误 */
12153
+ /** 服务错误 */
12154
12154
  NetworkErrorCode[NetworkErrorCode["SERVER_ERROR"] = 1003] = "SERVER_ERROR";
12155
12155
  /** 未授权访问 */
12156
12156
  NetworkErrorCode[NetworkErrorCode["UNAUTHORIZED"] = 1004] = "UNAUTHORIZED";
@@ -12172,6 +12172,12 @@
12172
12172
  OperationErrorCode[OperationErrorCode["OPERATION_TIMEOUT"] = 2004] = "OPERATION_TIMEOUT";
12173
12173
  /** 操作被取消 */
12174
12174
  OperationErrorCode[OperationErrorCode["OPERATION_CANCELLED"] = 2005] = "OPERATION_CANCELLED";
12175
+ /** 用户权益额度不存在 */
12176
+ OperationErrorCode[OperationErrorCode["BROADCAST_EQUITY_NOT_EXIST"] = 2006] = "BROADCAST_EQUITY_NOT_EXIST";
12177
+ /** 用户权益额度不足 */
12178
+ OperationErrorCode[OperationErrorCode["BROADCAST_EQUITY_NOT_ENOUGH"] = 2007] = "BROADCAST_EQUITY_NOT_ENOUGH";
12179
+ /** 用户权益额度冻结失败 */
12180
+ OperationErrorCode[OperationErrorCode["BROADCAST_EQUITY_FREEZE_FAILED"] = 2008] = "BROADCAST_EQUITY_FREEZE_FAILED";
12175
12181
  })(exports.OperationErrorCode || (exports.OperationErrorCode = {}));
12176
12182
  /**
12177
12183
  * 资源错误码 (3xxx)
@@ -12257,6 +12263,15 @@
12257
12263
  }, _a[exports.OperationErrorCode.OPERATION_CANCELLED] = {
12258
12264
  category: exports.ErrorCategory.OPERATION,
12259
12265
  message: '操作被取消'
12266
+ }, _a[exports.OperationErrorCode.BROADCAST_EQUITY_NOT_EXIST] = {
12267
+ category: exports.ErrorCategory.OPERATION,
12268
+ message: '用户权益额度不存在'
12269
+ }, _a[exports.OperationErrorCode.BROADCAST_EQUITY_NOT_ENOUGH] = {
12270
+ category: exports.ErrorCategory.OPERATION,
12271
+ message: '用户权益额度不足'
12272
+ }, _a[exports.OperationErrorCode.BROADCAST_EQUITY_FREEZE_FAILED] = {
12273
+ category: exports.ErrorCategory.OPERATION,
12274
+ message: '用户权益额度冻结失败'
12260
12275
  },
12261
12276
  // 资源错误
12262
12277
  _a[exports.ResourceErrorCode.LOAD_FAILED] = {
@@ -12854,7 +12869,7 @@
12854
12869
  console.warn("[Unity Warning] ".concat(message), data);
12855
12870
  };
12856
12871
  SimpleLogger.prototype.error = function (message, error, data) {
12857
- console.error("[Unity Error] ".concat(message), error, data);
12872
+ console.error("[Unity Error] ".concat(message), error, error instanceof SDKError ? error.code : null, data);
12858
12873
  };
12859
12874
  return SimpleLogger;
12860
12875
  }();
@@ -13238,6 +13253,7 @@
13238
13253
  /**
13239
13254
  * 获取指定环境的配置
13240
13255
  * @param env - 环境类型,默认为'dev'
13256
+ * @param withApiModule - 是否包含API模块路径
13241
13257
  * @returns 返回对应环境的配置对象
13242
13258
  * @example
13243
13259
  * ```typescript
@@ -13245,17 +13261,17 @@
13245
13261
  * console.log(config.apiBaseUrl); // https://aiip.zeewain.com/api/dh-talker
13246
13262
  * ```
13247
13263
  */
13248
- function getEnvConfig(env, withModule) {
13264
+ function getEnvConfig(env, withApiModule) {
13249
13265
  if (env === void 0) {
13250
13266
  env = 'dev';
13251
13267
  }
13252
- if (withModule === void 0) {
13253
- withModule = true;
13268
+ if (withApiModule === void 0) {
13269
+ withApiModule = true;
13254
13270
  }
13255
13271
  var baseUrl = ENV_MAP[env];
13256
13272
  if (baseUrl) {
13257
13273
  return {
13258
- apiBaseUrl: "".concat(baseUrl.apiBaseUrl).concat(withModule ? '/api' : '')
13274
+ apiBaseUrl: "".concat(baseUrl.apiBaseUrl).concat(withApiModule ? '/api' : '')
13259
13275
  };
13260
13276
  }
13261
13277
  return null;
@@ -13328,19 +13344,20 @@
13328
13344
  };
13329
13345
  /**
13330
13346
  * 获取API基础URL
13331
- * @param withModule 是否包含模块路径
13347
+ * @param withApiModule 是否包含模块路径
13332
13348
  * @returns string API基础URL
13333
13349
  * @description 根据当前环境配置获取API基础URL
13334
13350
  */
13335
- ConfigManager.prototype.getApiBaseUrl = function (withModule) {
13351
+ ConfigManager.prototype.getApiBaseUrl = function (withApiModule) {
13336
13352
  var _a, _b, _c, _d;
13337
- if (withModule === void 0) {
13338
- withModule = true;
13353
+ if (withApiModule === void 0) {
13354
+ withApiModule = true;
13339
13355
  }
13340
13356
  if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.env) === 'custom' && ((_b = this.config) === null || _b === void 0 ? void 0 : _b.apiUrl)) {
13341
- return this.config.apiUrl;
13357
+ // 如果环境为自定义,则直接返回配置的API,无需添加模块路径
13358
+ return "".concat(this.config.apiUrl).concat(withApiModule ? '/api' : '');
13342
13359
  }
13343
- return ((_d = getEnvConfig(((_c = this.config) === null || _c === void 0 ? void 0 : _c.env) || 'prod', withModule)) === null || _d === void 0 ? void 0 : _d.apiBaseUrl) || '';
13360
+ return ((_d = getEnvConfig(((_c = this.config) === null || _c === void 0 ? void 0 : _c.env) || 'prod', withApiModule)) === null || _d === void 0 ? void 0 : _d.apiBaseUrl) || '';
13344
13361
  };
13345
13362
  /**
13346
13363
  * 获取自定义API URL
@@ -13830,6 +13847,9 @@
13830
13847
  this.logger.debug('Broadcast stopped callback triggered');
13831
13848
  break;
13832
13849
  }
13850
+ } else {
13851
+ var error = SDKError.createFromUnityError(code, "Unity operation '".concat(operation, "' failed: ").concat(message));
13852
+ this.handleError(error);
13833
13853
  }
13834
13854
  };
13835
13855
  /**
@@ -13903,7 +13923,7 @@
13903
13923
  _c.label = 2;
13904
13924
  case 2:
13905
13925
  _c.trys.push([2, 4,, 5]);
13906
- apiUrl = "".concat(this.getApiBaseUrl()).concat(this.getBroadcastApiPath(params.type));
13926
+ apiUrl = "".concat(ConfigManager.getInstance().getApiBaseUrl(true)).concat(this.getBroadcastApiPath(params.type));
13907
13927
  requestBody = {
13908
13928
  humanCode: params.humanCode,
13909
13929
  speed: params.speed,
@@ -13940,7 +13960,7 @@
13940
13960
  var response = JSON.parse(event.data);
13941
13961
  // 错误处理
13942
13962
  if (response.code !== 0) {
13943
- _this.handleError(new SDKError(exports.NetworkErrorCode.SERVER_ERROR, response.message || '未知服务器错误'));
13963
+ _this.handleBroadcastError(response.code);
13944
13964
  return;
13945
13965
  }
13946
13966
  // 流式播报
@@ -13979,7 +13999,10 @@
13979
13999
  },
13980
14000
  onerror: function onerror(error) {
13981
14001
  _this.logger.error('Broadcast stream error', error);
13982
- _this.handleError(new SDKError(exports.OperationErrorCode.OPERATION_FAILED, '播报流错误', error));
14002
+ var sdkError = new SDKError(exports.OperationErrorCode.OPERATION_FAILED, '服务出错了', error);
14003
+ _this.handleError(sdkError);
14004
+ // 必须抛出错误,否则会循环重试请求
14005
+ throw new Error("\u670D\u52A1\u51FA\u9519\u4E86".concat(sdkError.message));
13983
14006
  }
13984
14007
  })];
13985
14008
  case 3:
@@ -14151,16 +14174,6 @@
14151
14174
  enumerable: false,
14152
14175
  configurable: true
14153
14176
  });
14154
- /**
14155
- * 获取API基础URL
14156
- * @returns string 返回当前环境的API基础URL
14157
- * @description 根据当前环境配置获取API基础URL
14158
- * @private
14159
- */
14160
- BroadcastService.prototype.getApiBaseUrl = function () {
14161
- var configManager = ConfigManager.getInstance();
14162
- return configManager.getApiBaseUrl();
14163
- };
14164
14177
  /**
14165
14178
  * 获取播报API路径
14166
14179
  * @param type - 播报类型
@@ -14170,10 +14183,19 @@
14170
14183
  * @private
14171
14184
  */
14172
14185
  BroadcastService.prototype.getBroadcastApiPath = function (type) {
14186
+ var env = ConfigManager.getInstance().getEnv();
14173
14187
  switch (type) {
14174
14188
  case exports.BroadcastType.TEXT:
14189
+ // 临时处理,开发和测试环境使用新接口
14190
+ if (env === 'dev' || env === 'test') {
14191
+ return '/aiep-openapi/avatar-interaction/v1/broadcast/text';
14192
+ }
14175
14193
  return '/dh-talker/user/agent/broadcast/text';
14176
14194
  case exports.BroadcastType.AUDIO:
14195
+ // 临时处理,开发和测试环境使用新接口
14196
+ if (env === 'dev' || env === 'test') {
14197
+ return '/aiep-openapi/avatar-interaction/v1/broadcast/audio';
14198
+ }
14177
14199
  return '/dh-talker/user/agent/broadcast/customAudio';
14178
14200
  default:
14179
14201
  throw new SDKError(exports.ConfigErrorCode.INVALID_CONFIG, "\u672A\u77E5\u7684\u64AD\u62A5\u7C7B\u578B: ".concat(type));
@@ -14214,6 +14236,31 @@
14214
14236
  // 触发错误回调
14215
14237
  (_b = (_a = this.callbacks).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
14216
14238
  };
14239
+ /**
14240
+ * 处理播报错误
14241
+ * @param errorCode - 错误码
14242
+ * @description 处理播报过程中的错误
14243
+ * @private
14244
+ */
14245
+ BroadcastService.prototype.handleBroadcastError = function (errorCode) {
14246
+ // 用户权益额度不存在错误码 14001
14247
+ // 用户权益额度不足错误码 14002
14248
+ // 用户权益额度冻结失败 14003
14249
+ switch (errorCode) {
14250
+ case 14001:
14251
+ this.handleError(new SDKError(exports.OperationErrorCode.BROADCAST_EQUITY_NOT_EXIST, '用户权益额度不存在'));
14252
+ break;
14253
+ case 14002:
14254
+ this.handleError(new SDKError(exports.OperationErrorCode.BROADCAST_EQUITY_NOT_ENOUGH, '用户权益额度不足'));
14255
+ break;
14256
+ case 14003:
14257
+ this.handleError(new SDKError(exports.OperationErrorCode.BROADCAST_EQUITY_FREEZE_FAILED, '用户权益额度冻结失败'));
14258
+ break;
14259
+ default:
14260
+ this.handleError(new SDKError(exports.OperationErrorCode.OPERATION_FAILED, '播报服务错误'));
14261
+ break;
14262
+ }
14263
+ };
14217
14264
  return BroadcastService;
14218
14265
  }(UnityBaseService);
14219
14266
 
@@ -14352,11 +14399,12 @@
14352
14399
  * @protected
14353
14400
  */
14354
14401
  ZEEAvatarLoader.prototype.initGlobalConfig = function () {
14355
- var params = __assign(__assign({}, ConfigManager.getInstance().getConfig()), {
14402
+ var params = {
14356
14403
  token: ConfigManager.getInstance().getToken(),
14357
14404
  apiBaseUrl: ConfigManager.getInstance().getApiBaseUrl(false),
14405
+ idleMotionList: ConfigManager.getInstance().getConfig().idleMotionList,
14358
14406
  assetsUrl: ConfigManager.getInstance().getConfig().assetsUrl
14359
- });
14407
+ };
14360
14408
  console.warn('[ Send Unity message ]: AvatarSDK.InitializeConfig', params);
14361
14409
  this.unityInstance.SendMessage('AvatarSDK', 'InitializeConfig', JSON.stringify(params));
14362
14410
  };
package/dist/index.esm.js CHANGED
@@ -63,7 +63,7 @@ var NetworkErrorCode;
63
63
  NetworkErrorCode[NetworkErrorCode["CONNECTION_FAILED"] = 1001] = "CONNECTION_FAILED";
64
64
  /** 请求超时 */
65
65
  NetworkErrorCode[NetworkErrorCode["REQUEST_TIMEOUT"] = 1002] = "REQUEST_TIMEOUT";
66
- /** 服务器错误 */
66
+ /** 服务错误 */
67
67
  NetworkErrorCode[NetworkErrorCode["SERVER_ERROR"] = 1003] = "SERVER_ERROR";
68
68
  /** 未授权访问 */
69
69
  NetworkErrorCode[NetworkErrorCode["UNAUTHORIZED"] = 1004] = "UNAUTHORIZED";
@@ -85,6 +85,12 @@ var OperationErrorCode;
85
85
  OperationErrorCode[OperationErrorCode["OPERATION_TIMEOUT"] = 2004] = "OPERATION_TIMEOUT";
86
86
  /** 操作被取消 */
87
87
  OperationErrorCode[OperationErrorCode["OPERATION_CANCELLED"] = 2005] = "OPERATION_CANCELLED";
88
+ /** 用户权益额度不存在 */
89
+ OperationErrorCode[OperationErrorCode["BROADCAST_EQUITY_NOT_EXIST"] = 2006] = "BROADCAST_EQUITY_NOT_EXIST";
90
+ /** 用户权益额度不足 */
91
+ OperationErrorCode[OperationErrorCode["BROADCAST_EQUITY_NOT_ENOUGH"] = 2007] = "BROADCAST_EQUITY_NOT_ENOUGH";
92
+ /** 用户权益额度冻结失败 */
93
+ OperationErrorCode[OperationErrorCode["BROADCAST_EQUITY_FREEZE_FAILED"] = 2008] = "BROADCAST_EQUITY_FREEZE_FAILED";
88
94
  })(OperationErrorCode || (OperationErrorCode = {}));
89
95
  /**
90
96
  * 资源错误码 (3xxx)
@@ -178,6 +184,18 @@ const ERROR_CODE_MAP = {
178
184
  category: ErrorCategory.OPERATION,
179
185
  message: '操作被取消'
180
186
  },
187
+ [OperationErrorCode.BROADCAST_EQUITY_NOT_EXIST]: {
188
+ category: ErrorCategory.OPERATION,
189
+ message: '用户权益额度不存在'
190
+ },
191
+ [OperationErrorCode.BROADCAST_EQUITY_NOT_ENOUGH]: {
192
+ category: ErrorCategory.OPERATION,
193
+ message: '用户权益额度不足'
194
+ },
195
+ [OperationErrorCode.BROADCAST_EQUITY_FREEZE_FAILED]: {
196
+ category: ErrorCategory.OPERATION,
197
+ message: '用户权益额度冻结失败'
198
+ },
181
199
  // 资源错误
182
200
  [ResourceErrorCode.LOAD_FAILED]: {
183
201
  category: ErrorCategory.RESOURCE,
@@ -721,7 +739,7 @@ class SimpleLogger {
721
739
  console.warn(`[Unity Warning] ${message}`, data);
722
740
  }
723
741
  error(message, error, data) {
724
- console.error(`[Unity Error] ${message}`, error, data);
742
+ console.error(`[Unity Error] ${message}`, error, error instanceof SDKError ? error.code : null, data);
725
743
  }
726
744
  }
727
745
 
@@ -1001,6 +1019,7 @@ const ENV_MAP = {
1001
1019
  /**
1002
1020
  * 获取指定环境的配置
1003
1021
  * @param env - 环境类型,默认为'dev'
1022
+ * @param withApiModule - 是否包含API模块路径
1004
1023
  * @returns 返回对应环境的配置对象
1005
1024
  * @example
1006
1025
  * ```typescript
@@ -1008,11 +1027,11 @@ const ENV_MAP = {
1008
1027
  * console.log(config.apiBaseUrl); // https://aiip.zeewain.com/api/dh-talker
1009
1028
  * ```
1010
1029
  */
1011
- function getEnvConfig(env = 'dev', withModule = true) {
1030
+ function getEnvConfig(env = 'dev', withApiModule = true) {
1012
1031
  const baseUrl = ENV_MAP[env];
1013
1032
  if (baseUrl) {
1014
1033
  return {
1015
- apiBaseUrl: `${baseUrl.apiBaseUrl}${withModule ? '/api' : ''}`
1034
+ apiBaseUrl: `${baseUrl.apiBaseUrl}${withApiModule ? '/api' : ''}`
1016
1035
  };
1017
1036
  }
1018
1037
  return null;
@@ -1082,16 +1101,17 @@ class ConfigManager {
1082
1101
  }
1083
1102
  /**
1084
1103
  * 获取API基础URL
1085
- * @param withModule 是否包含模块路径
1104
+ * @param withApiModule 是否包含模块路径
1086
1105
  * @returns string API基础URL
1087
1106
  * @description 根据当前环境配置获取API基础URL
1088
1107
  */
1089
- getApiBaseUrl(withModule = true) {
1108
+ getApiBaseUrl(withApiModule = true) {
1090
1109
  var _a, _b, _c, _d;
1091
1110
  if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.env) === 'custom' && ((_b = this.config) === null || _b === void 0 ? void 0 : _b.apiUrl)) {
1092
- return this.config.apiUrl;
1111
+ // 如果环境为自定义,则直接返回配置的API,无需添加模块路径
1112
+ return `${this.config.apiUrl}${withApiModule ? '/api' : ''}`;
1093
1113
  }
1094
- return ((_d = getEnvConfig(((_c = this.config) === null || _c === void 0 ? void 0 : _c.env) || 'prod', withModule)) === null || _d === void 0 ? void 0 : _d.apiBaseUrl) || '';
1114
+ return ((_d = getEnvConfig(((_c = this.config) === null || _c === void 0 ? void 0 : _c.env) || 'prod', withApiModule)) === null || _d === void 0 ? void 0 : _d.apiBaseUrl) || '';
1095
1115
  }
1096
1116
  /**
1097
1117
  * 获取自定义API URL
@@ -1562,6 +1582,10 @@ class BroadcastService extends UnityBaseService {
1562
1582
  break;
1563
1583
  }
1564
1584
  }
1585
+ else {
1586
+ const error = SDKError.createFromUnityError(code, `Unity operation '${operation}' failed: ${message}`);
1587
+ this.handleError(error);
1588
+ }
1565
1589
  }
1566
1590
  /**
1567
1591
  * 开始播报
@@ -1622,7 +1646,7 @@ class BroadcastService extends UnityBaseService {
1622
1646
  motionPlayMode: params.motionPlayMode
1623
1647
  });
1624
1648
  try {
1625
- const apiUrl = `${this.getApiBaseUrl()}${this.getBroadcastApiPath(params.type)}`;
1649
+ const apiUrl = `${ConfigManager.getInstance().getApiBaseUrl(true)}${this.getBroadcastApiPath(params.type)}`;
1626
1650
  const requestBody = {
1627
1651
  humanCode: params.humanCode,
1628
1652
  speed: params.speed,
@@ -1656,7 +1680,7 @@ class BroadcastService extends UnityBaseService {
1656
1680
  const response = JSON.parse(event.data);
1657
1681
  // 错误处理
1658
1682
  if (response.code !== 0) {
1659
- this.handleError(new SDKError(NetworkErrorCode.SERVER_ERROR, response.message || '未知服务器错误'));
1683
+ this.handleBroadcastError(response.code);
1660
1684
  return;
1661
1685
  }
1662
1686
  // 流式播报
@@ -1695,7 +1719,10 @@ class BroadcastService extends UnityBaseService {
1695
1719
  },
1696
1720
  onerror: (error) => {
1697
1721
  this.logger.error('Broadcast stream error', error);
1698
- this.handleError(new SDKError(OperationErrorCode.OPERATION_FAILED, '播报流错误', error));
1722
+ const sdkError = new SDKError(OperationErrorCode.OPERATION_FAILED, '服务出错了', error);
1723
+ this.handleError(sdkError);
1724
+ // 必须抛出错误,否则会循环重试请求
1725
+ throw new Error(`服务出错了${sdkError.message}`);
1699
1726
  }
1700
1727
  });
1701
1728
  }
@@ -1819,16 +1846,6 @@ class BroadcastService extends UnityBaseService {
1819
1846
  get callbackFunctionName() {
1820
1847
  return 'uniBroadcastCallback';
1821
1848
  }
1822
- /**
1823
- * 获取API基础URL
1824
- * @returns string 返回当前环境的API基础URL
1825
- * @description 根据当前环境配置获取API基础URL
1826
- * @private
1827
- */
1828
- getApiBaseUrl() {
1829
- const configManager = ConfigManager.getInstance();
1830
- return configManager.getApiBaseUrl();
1831
- }
1832
1849
  /**
1833
1850
  * 获取播报API路径
1834
1851
  * @param type - 播报类型
@@ -1838,10 +1855,19 @@ class BroadcastService extends UnityBaseService {
1838
1855
  * @private
1839
1856
  */
1840
1857
  getBroadcastApiPath(type) {
1858
+ const env = ConfigManager.getInstance().getEnv();
1841
1859
  switch (type) {
1842
1860
  case BroadcastType.TEXT:
1861
+ // 临时处理,开发和测试环境使用新接口
1862
+ if (env === 'dev' || env === 'test') {
1863
+ return '/aiep-openapi/avatar-interaction/v1/broadcast/text';
1864
+ }
1843
1865
  return '/dh-talker/user/agent/broadcast/text';
1844
1866
  case BroadcastType.AUDIO:
1867
+ // 临时处理,开发和测试环境使用新接口
1868
+ if (env === 'dev' || env === 'test') {
1869
+ return '/aiep-openapi/avatar-interaction/v1/broadcast/audio';
1870
+ }
1845
1871
  return '/dh-talker/user/agent/broadcast/customAudio';
1846
1872
  default:
1847
1873
  throw new SDKError(ConfigErrorCode.INVALID_CONFIG, `未知的播报类型: ${type}`);
@@ -1883,6 +1909,31 @@ class BroadcastService extends UnityBaseService {
1883
1909
  // 触发错误回调
1884
1910
  (_b = (_a = this.callbacks).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
1885
1911
  }
1912
+ /**
1913
+ * 处理播报错误
1914
+ * @param errorCode - 错误码
1915
+ * @description 处理播报过程中的错误
1916
+ * @private
1917
+ */
1918
+ handleBroadcastError(errorCode) {
1919
+ // 用户权益额度不存在错误码 14001
1920
+ // 用户权益额度不足错误码 14002
1921
+ // 用户权益额度冻结失败 14003
1922
+ switch (errorCode) {
1923
+ case 14001:
1924
+ this.handleError(new SDKError(OperationErrorCode.BROADCAST_EQUITY_NOT_EXIST, '用户权益额度不存在'));
1925
+ break;
1926
+ case 14002:
1927
+ this.handleError(new SDKError(OperationErrorCode.BROADCAST_EQUITY_NOT_ENOUGH, '用户权益额度不足'));
1928
+ break;
1929
+ case 14003:
1930
+ this.handleError(new SDKError(OperationErrorCode.BROADCAST_EQUITY_FREEZE_FAILED, '用户权益额度冻结失败'));
1931
+ break;
1932
+ default:
1933
+ this.handleError(new SDKError(OperationErrorCode.OPERATION_FAILED, '播报服务错误'));
1934
+ break;
1935
+ }
1936
+ }
1886
1937
  }
1887
1938
 
1888
1939
  /**
@@ -2009,7 +2060,12 @@ class ZEEAvatarLoader {
2009
2060
  * @protected
2010
2061
  */
2011
2062
  initGlobalConfig() {
2012
- const params = Object.assign(Object.assign({}, ConfigManager.getInstance().getConfig()), { token: ConfigManager.getInstance().getToken(), apiBaseUrl: ConfigManager.getInstance().getApiBaseUrl(false), assetsUrl: ConfigManager.getInstance().getConfig().assetsUrl });
2063
+ const params = {
2064
+ token: ConfigManager.getInstance().getToken(),
2065
+ apiBaseUrl: ConfigManager.getInstance().getApiBaseUrl(false),
2066
+ idleMotionList: ConfigManager.getInstance().getConfig().idleMotionList,
2067
+ assetsUrl: ConfigManager.getInstance().getConfig().assetsUrl
2068
+ };
2013
2069
  console.warn('[ Send Unity message ]: AvatarSDK.InitializeConfig', params);
2014
2070
  this.unityInstance.SendMessage('AvatarSDK', 'InitializeConfig', JSON.stringify(params));
2015
2071
  }
@@ -69,7 +69,7 @@
69
69
  NetworkErrorCode[NetworkErrorCode["CONNECTION_FAILED"] = 1001] = "CONNECTION_FAILED";
70
70
  /** 请求超时 */
71
71
  NetworkErrorCode[NetworkErrorCode["REQUEST_TIMEOUT"] = 1002] = "REQUEST_TIMEOUT";
72
- /** 服务器错误 */
72
+ /** 服务错误 */
73
73
  NetworkErrorCode[NetworkErrorCode["SERVER_ERROR"] = 1003] = "SERVER_ERROR";
74
74
  /** 未授权访问 */
75
75
  NetworkErrorCode[NetworkErrorCode["UNAUTHORIZED"] = 1004] = "UNAUTHORIZED";
@@ -91,6 +91,12 @@
91
91
  OperationErrorCode[OperationErrorCode["OPERATION_TIMEOUT"] = 2004] = "OPERATION_TIMEOUT";
92
92
  /** 操作被取消 */
93
93
  OperationErrorCode[OperationErrorCode["OPERATION_CANCELLED"] = 2005] = "OPERATION_CANCELLED";
94
+ /** 用户权益额度不存在 */
95
+ OperationErrorCode[OperationErrorCode["BROADCAST_EQUITY_NOT_EXIST"] = 2006] = "BROADCAST_EQUITY_NOT_EXIST";
96
+ /** 用户权益额度不足 */
97
+ OperationErrorCode[OperationErrorCode["BROADCAST_EQUITY_NOT_ENOUGH"] = 2007] = "BROADCAST_EQUITY_NOT_ENOUGH";
98
+ /** 用户权益额度冻结失败 */
99
+ OperationErrorCode[OperationErrorCode["BROADCAST_EQUITY_FREEZE_FAILED"] = 2008] = "BROADCAST_EQUITY_FREEZE_FAILED";
94
100
  })(exports.OperationErrorCode || (exports.OperationErrorCode = {}));
95
101
  /**
96
102
  * 资源错误码 (3xxx)
@@ -184,6 +190,18 @@
184
190
  category: exports.ErrorCategory.OPERATION,
185
191
  message: '操作被取消'
186
192
  },
193
+ [exports.OperationErrorCode.BROADCAST_EQUITY_NOT_EXIST]: {
194
+ category: exports.ErrorCategory.OPERATION,
195
+ message: '用户权益额度不存在'
196
+ },
197
+ [exports.OperationErrorCode.BROADCAST_EQUITY_NOT_ENOUGH]: {
198
+ category: exports.ErrorCategory.OPERATION,
199
+ message: '用户权益额度不足'
200
+ },
201
+ [exports.OperationErrorCode.BROADCAST_EQUITY_FREEZE_FAILED]: {
202
+ category: exports.ErrorCategory.OPERATION,
203
+ message: '用户权益额度冻结失败'
204
+ },
187
205
  // 资源错误
188
206
  [exports.ResourceErrorCode.LOAD_FAILED]: {
189
207
  category: exports.ErrorCategory.RESOURCE,
@@ -727,7 +745,7 @@
727
745
  console.warn(`[Unity Warning] ${message}`, data);
728
746
  }
729
747
  error(message, error, data) {
730
- console.error(`[Unity Error] ${message}`, error, data);
748
+ console.error(`[Unity Error] ${message}`, error, error instanceof SDKError ? error.code : null, data);
731
749
  }
732
750
  }
733
751
 
@@ -1007,6 +1025,7 @@
1007
1025
  /**
1008
1026
  * 获取指定环境的配置
1009
1027
  * @param env - 环境类型,默认为'dev'
1028
+ * @param withApiModule - 是否包含API模块路径
1010
1029
  * @returns 返回对应环境的配置对象
1011
1030
  * @example
1012
1031
  * ```typescript
@@ -1014,11 +1033,11 @@
1014
1033
  * console.log(config.apiBaseUrl); // https://aiip.zeewain.com/api/dh-talker
1015
1034
  * ```
1016
1035
  */
1017
- function getEnvConfig(env = 'dev', withModule = true) {
1036
+ function getEnvConfig(env = 'dev', withApiModule = true) {
1018
1037
  const baseUrl = ENV_MAP[env];
1019
1038
  if (baseUrl) {
1020
1039
  return {
1021
- apiBaseUrl: `${baseUrl.apiBaseUrl}${withModule ? '/api' : ''}`
1040
+ apiBaseUrl: `${baseUrl.apiBaseUrl}${withApiModule ? '/api' : ''}`
1022
1041
  };
1023
1042
  }
1024
1043
  return null;
@@ -1088,16 +1107,17 @@
1088
1107
  }
1089
1108
  /**
1090
1109
  * 获取API基础URL
1091
- * @param withModule 是否包含模块路径
1110
+ * @param withApiModule 是否包含模块路径
1092
1111
  * @returns string API基础URL
1093
1112
  * @description 根据当前环境配置获取API基础URL
1094
1113
  */
1095
- getApiBaseUrl(withModule = true) {
1114
+ getApiBaseUrl(withApiModule = true) {
1096
1115
  var _a, _b, _c, _d;
1097
1116
  if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.env) === 'custom' && ((_b = this.config) === null || _b === void 0 ? void 0 : _b.apiUrl)) {
1098
- return this.config.apiUrl;
1117
+ // 如果环境为自定义,则直接返回配置的API,无需添加模块路径
1118
+ return `${this.config.apiUrl}${withApiModule ? '/api' : ''}`;
1099
1119
  }
1100
- return ((_d = getEnvConfig(((_c = this.config) === null || _c === void 0 ? void 0 : _c.env) || 'prod', withModule)) === null || _d === void 0 ? void 0 : _d.apiBaseUrl) || '';
1120
+ return ((_d = getEnvConfig(((_c = this.config) === null || _c === void 0 ? void 0 : _c.env) || 'prod', withApiModule)) === null || _d === void 0 ? void 0 : _d.apiBaseUrl) || '';
1101
1121
  }
1102
1122
  /**
1103
1123
  * 获取自定义API URL
@@ -1568,6 +1588,10 @@
1568
1588
  break;
1569
1589
  }
1570
1590
  }
1591
+ else {
1592
+ const error = SDKError.createFromUnityError(code, `Unity operation '${operation}' failed: ${message}`);
1593
+ this.handleError(error);
1594
+ }
1571
1595
  }
1572
1596
  /**
1573
1597
  * 开始播报
@@ -1628,7 +1652,7 @@
1628
1652
  motionPlayMode: params.motionPlayMode
1629
1653
  });
1630
1654
  try {
1631
- const apiUrl = `${this.getApiBaseUrl()}${this.getBroadcastApiPath(params.type)}`;
1655
+ const apiUrl = `${ConfigManager.getInstance().getApiBaseUrl(true)}${this.getBroadcastApiPath(params.type)}`;
1632
1656
  const requestBody = {
1633
1657
  humanCode: params.humanCode,
1634
1658
  speed: params.speed,
@@ -1662,7 +1686,7 @@
1662
1686
  const response = JSON.parse(event.data);
1663
1687
  // 错误处理
1664
1688
  if (response.code !== 0) {
1665
- this.handleError(new SDKError(exports.NetworkErrorCode.SERVER_ERROR, response.message || '未知服务器错误'));
1689
+ this.handleBroadcastError(response.code);
1666
1690
  return;
1667
1691
  }
1668
1692
  // 流式播报
@@ -1701,7 +1725,10 @@
1701
1725
  },
1702
1726
  onerror: (error) => {
1703
1727
  this.logger.error('Broadcast stream error', error);
1704
- this.handleError(new SDKError(exports.OperationErrorCode.OPERATION_FAILED, '播报流错误', error));
1728
+ const sdkError = new SDKError(exports.OperationErrorCode.OPERATION_FAILED, '服务出错了', error);
1729
+ this.handleError(sdkError);
1730
+ // 必须抛出错误,否则会循环重试请求
1731
+ throw new Error(`服务出错了${sdkError.message}`);
1705
1732
  }
1706
1733
  });
1707
1734
  }
@@ -1825,16 +1852,6 @@
1825
1852
  get callbackFunctionName() {
1826
1853
  return 'uniBroadcastCallback';
1827
1854
  }
1828
- /**
1829
- * 获取API基础URL
1830
- * @returns string 返回当前环境的API基础URL
1831
- * @description 根据当前环境配置获取API基础URL
1832
- * @private
1833
- */
1834
- getApiBaseUrl() {
1835
- const configManager = ConfigManager.getInstance();
1836
- return configManager.getApiBaseUrl();
1837
- }
1838
1855
  /**
1839
1856
  * 获取播报API路径
1840
1857
  * @param type - 播报类型
@@ -1844,10 +1861,19 @@
1844
1861
  * @private
1845
1862
  */
1846
1863
  getBroadcastApiPath(type) {
1864
+ const env = ConfigManager.getInstance().getEnv();
1847
1865
  switch (type) {
1848
1866
  case exports.BroadcastType.TEXT:
1867
+ // 临时处理,开发和测试环境使用新接口
1868
+ if (env === 'dev' || env === 'test') {
1869
+ return '/aiep-openapi/avatar-interaction/v1/broadcast/text';
1870
+ }
1849
1871
  return '/dh-talker/user/agent/broadcast/text';
1850
1872
  case exports.BroadcastType.AUDIO:
1873
+ // 临时处理,开发和测试环境使用新接口
1874
+ if (env === 'dev' || env === 'test') {
1875
+ return '/aiep-openapi/avatar-interaction/v1/broadcast/audio';
1876
+ }
1851
1877
  return '/dh-talker/user/agent/broadcast/customAudio';
1852
1878
  default:
1853
1879
  throw new SDKError(exports.ConfigErrorCode.INVALID_CONFIG, `未知的播报类型: ${type}`);
@@ -1889,6 +1915,31 @@
1889
1915
  // 触发错误回调
1890
1916
  (_b = (_a = this.callbacks).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
1891
1917
  }
1918
+ /**
1919
+ * 处理播报错误
1920
+ * @param errorCode - 错误码
1921
+ * @description 处理播报过程中的错误
1922
+ * @private
1923
+ */
1924
+ handleBroadcastError(errorCode) {
1925
+ // 用户权益额度不存在错误码 14001
1926
+ // 用户权益额度不足错误码 14002
1927
+ // 用户权益额度冻结失败 14003
1928
+ switch (errorCode) {
1929
+ case 14001:
1930
+ this.handleError(new SDKError(exports.OperationErrorCode.BROADCAST_EQUITY_NOT_EXIST, '用户权益额度不存在'));
1931
+ break;
1932
+ case 14002:
1933
+ this.handleError(new SDKError(exports.OperationErrorCode.BROADCAST_EQUITY_NOT_ENOUGH, '用户权益额度不足'));
1934
+ break;
1935
+ case 14003:
1936
+ this.handleError(new SDKError(exports.OperationErrorCode.BROADCAST_EQUITY_FREEZE_FAILED, '用户权益额度冻结失败'));
1937
+ break;
1938
+ default:
1939
+ this.handleError(new SDKError(exports.OperationErrorCode.OPERATION_FAILED, '播报服务错误'));
1940
+ break;
1941
+ }
1942
+ }
1892
1943
  }
1893
1944
 
1894
1945
  /**
@@ -2015,7 +2066,12 @@
2015
2066
  * @protected
2016
2067
  */
2017
2068
  initGlobalConfig() {
2018
- const params = Object.assign(Object.assign({}, ConfigManager.getInstance().getConfig()), { token: ConfigManager.getInstance().getToken(), apiBaseUrl: ConfigManager.getInstance().getApiBaseUrl(false), assetsUrl: ConfigManager.getInstance().getConfig().assetsUrl });
2069
+ const params = {
2070
+ token: ConfigManager.getInstance().getToken(),
2071
+ apiBaseUrl: ConfigManager.getInstance().getApiBaseUrl(false),
2072
+ idleMotionList: ConfigManager.getInstance().getConfig().idleMotionList,
2073
+ assetsUrl: ConfigManager.getInstance().getConfig().assetsUrl
2074
+ };
2019
2075
  console.warn('[ Send Unity message ]: AvatarSDK.InitializeConfig', params);
2020
2076
  this.unityInstance.SendMessage('AvatarSDK', 'InitializeConfig', JSON.stringify(params));
2021
2077
  }