@zeewain/3d-avatar-sdk 1.2.1 → 1.2.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.
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 +64 -17
  52. package/dist/index.es5.umd.js +64 -17
  53. package/dist/index.esm.js +71 -16
  54. package/dist/index.umd.cjs +71 -16
  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
  }();
@@ -13338,6 +13353,7 @@
13338
13353
  withModule = true;
13339
13354
  }
13340
13355
  if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.env) === 'custom' && ((_b = this.config) === null || _b === void 0 ? void 0 : _b.apiUrl)) {
13356
+ // 如果环境为自定义,则直接返回配置的API,无需添加模块路径
13341
13357
  return this.config.apiUrl;
13342
13358
  }
13343
13359
  return ((_d = getEnvConfig(((_c = this.config) === null || _c === void 0 ? void 0 : _c.env) || 'prod', withModule)) === null || _d === void 0 ? void 0 : _d.apiBaseUrl) || '';
@@ -13830,6 +13846,9 @@
13830
13846
  this.logger.debug('Broadcast stopped callback triggered');
13831
13847
  break;
13832
13848
  }
13849
+ } else {
13850
+ var error = SDKError.createFromUnityError(code, "Unity operation '".concat(operation, "' failed: ").concat(message));
13851
+ this.handleError(error);
13833
13852
  }
13834
13853
  };
13835
13854
  /**
@@ -13903,7 +13922,7 @@
13903
13922
  _c.label = 2;
13904
13923
  case 2:
13905
13924
  _c.trys.push([2, 4,, 5]);
13906
- apiUrl = "".concat(this.getApiBaseUrl()).concat(this.getBroadcastApiPath(params.type));
13925
+ apiUrl = "".concat(ConfigManager.getInstance().getApiBaseUrl(true)).concat(this.getBroadcastApiPath(params.type));
13907
13926
  requestBody = {
13908
13927
  humanCode: params.humanCode,
13909
13928
  speed: params.speed,
@@ -13940,7 +13959,7 @@
13940
13959
  var response = JSON.parse(event.data);
13941
13960
  // 错误处理
13942
13961
  if (response.code !== 0) {
13943
- _this.handleError(new SDKError(exports.NetworkErrorCode.SERVER_ERROR, response.message || '未知服务器错误'));
13962
+ _this.handleBroadcastError(response.code);
13944
13963
  return;
13945
13964
  }
13946
13965
  // 流式播报
@@ -13979,7 +13998,10 @@
13979
13998
  },
13980
13999
  onerror: function onerror(error) {
13981
14000
  _this.logger.error('Broadcast stream error', error);
13982
- _this.handleError(new SDKError(exports.OperationErrorCode.OPERATION_FAILED, '播报流错误', error));
14001
+ var sdkError = new SDKError(exports.OperationErrorCode.OPERATION_FAILED, '服务出错了', error);
14002
+ _this.handleError(sdkError);
14003
+ // 必须抛出错误,否则会循环重试请求
14004
+ throw new Error("\u670D\u52A1\u51FA\u9519\u4E86".concat(sdkError.message));
13983
14005
  }
13984
14006
  })];
13985
14007
  case 3:
@@ -14151,16 +14173,6 @@
14151
14173
  enumerable: false,
14152
14174
  configurable: true
14153
14175
  });
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
14176
  /**
14165
14177
  * 获取播报API路径
14166
14178
  * @param type - 播报类型
@@ -14170,10 +14182,19 @@
14170
14182
  * @private
14171
14183
  */
14172
14184
  BroadcastService.prototype.getBroadcastApiPath = function (type) {
14185
+ var env = ConfigManager.getInstance().getEnv();
14173
14186
  switch (type) {
14174
14187
  case exports.BroadcastType.TEXT:
14188
+ // 临时处理,开发和测试环境使用新接口
14189
+ if (env === 'dev' || env === 'test') {
14190
+ return '/aiep-openapi/avatar-interaction/v1/broadcast/text';
14191
+ }
14175
14192
  return '/dh-talker/user/agent/broadcast/text';
14176
14193
  case exports.BroadcastType.AUDIO:
14194
+ // 临时处理,开发和测试环境使用新接口
14195
+ if (env === 'dev' || env === 'test') {
14196
+ return '/aiep-openapi/avatar-interaction/v1/broadcast/audio';
14197
+ }
14177
14198
  return '/dh-talker/user/agent/broadcast/customAudio';
14178
14199
  default:
14179
14200
  throw new SDKError(exports.ConfigErrorCode.INVALID_CONFIG, "\u672A\u77E5\u7684\u64AD\u62A5\u7C7B\u578B: ".concat(type));
@@ -14214,6 +14235,31 @@
14214
14235
  // 触发错误回调
14215
14236
  (_b = (_a = this.callbacks).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
14216
14237
  };
14238
+ /**
14239
+ * 处理播报错误
14240
+ * @param errorCode - 错误码
14241
+ * @description 处理播报过程中的错误
14242
+ * @private
14243
+ */
14244
+ BroadcastService.prototype.handleBroadcastError = function (errorCode) {
14245
+ // 用户权益额度不存在错误码 14001
14246
+ // 用户权益额度不足错误码 14002
14247
+ // 用户权益额度冻结失败 14003
14248
+ switch (errorCode) {
14249
+ case 14001:
14250
+ this.handleError(new SDKError(exports.OperationErrorCode.BROADCAST_EQUITY_NOT_EXIST, '用户权益额度不存在'));
14251
+ break;
14252
+ case 14002:
14253
+ this.handleError(new SDKError(exports.OperationErrorCode.BROADCAST_EQUITY_NOT_ENOUGH, '用户权益额度不足'));
14254
+ break;
14255
+ case 14003:
14256
+ this.handleError(new SDKError(exports.OperationErrorCode.BROADCAST_EQUITY_FREEZE_FAILED, '用户权益额度冻结失败'));
14257
+ break;
14258
+ default:
14259
+ this.handleError(new SDKError(exports.OperationErrorCode.OPERATION_FAILED, '播报服务错误'));
14260
+ break;
14261
+ }
14262
+ };
14217
14263
  return BroadcastService;
14218
14264
  }(UnityBaseService);
14219
14265
 
@@ -14352,11 +14398,12 @@
14352
14398
  * @protected
14353
14399
  */
14354
14400
  ZEEAvatarLoader.prototype.initGlobalConfig = function () {
14355
- var params = __assign(__assign({}, ConfigManager.getInstance().getConfig()), {
14401
+ var params = {
14356
14402
  token: ConfigManager.getInstance().getToken(),
14357
14403
  apiBaseUrl: ConfigManager.getInstance().getApiBaseUrl(false),
14404
+ idleMotionList: ConfigManager.getInstance().getConfig().idleMotionList,
14358
14405
  assetsUrl: ConfigManager.getInstance().getConfig().assetsUrl
14359
- });
14406
+ };
14360
14407
  console.warn('[ Send Unity message ]: AvatarSDK.InitializeConfig', params);
14361
14408
  this.unityInstance.SendMessage('AvatarSDK', 'InitializeConfig', JSON.stringify(params));
14362
14409
  };
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
 
@@ -1089,6 +1107,7 @@ class ConfigManager {
1089
1107
  getApiBaseUrl(withModule = true) {
1090
1108
  var _a, _b, _c, _d;
1091
1109
  if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.env) === 'custom' && ((_b = this.config) === null || _b === void 0 ? void 0 : _b.apiUrl)) {
1110
+ // 如果环境为自定义,则直接返回配置的API,无需添加模块路径
1092
1111
  return this.config.apiUrl;
1093
1112
  }
1094
1113
  return ((_d = getEnvConfig(((_c = this.config) === null || _c === void 0 ? void 0 : _c.env) || 'prod', withModule)) === null || _d === void 0 ? void 0 : _d.apiBaseUrl) || '';
@@ -1562,6 +1581,10 @@ class BroadcastService extends UnityBaseService {
1562
1581
  break;
1563
1582
  }
1564
1583
  }
1584
+ else {
1585
+ const error = SDKError.createFromUnityError(code, `Unity operation '${operation}' failed: ${message}`);
1586
+ this.handleError(error);
1587
+ }
1565
1588
  }
1566
1589
  /**
1567
1590
  * 开始播报
@@ -1622,7 +1645,7 @@ class BroadcastService extends UnityBaseService {
1622
1645
  motionPlayMode: params.motionPlayMode
1623
1646
  });
1624
1647
  try {
1625
- const apiUrl = `${this.getApiBaseUrl()}${this.getBroadcastApiPath(params.type)}`;
1648
+ const apiUrl = `${ConfigManager.getInstance().getApiBaseUrl(true)}${this.getBroadcastApiPath(params.type)}`;
1626
1649
  const requestBody = {
1627
1650
  humanCode: params.humanCode,
1628
1651
  speed: params.speed,
@@ -1656,7 +1679,7 @@ class BroadcastService extends UnityBaseService {
1656
1679
  const response = JSON.parse(event.data);
1657
1680
  // 错误处理
1658
1681
  if (response.code !== 0) {
1659
- this.handleError(new SDKError(NetworkErrorCode.SERVER_ERROR, response.message || '未知服务器错误'));
1682
+ this.handleBroadcastError(response.code);
1660
1683
  return;
1661
1684
  }
1662
1685
  // 流式播报
@@ -1695,7 +1718,10 @@ class BroadcastService extends UnityBaseService {
1695
1718
  },
1696
1719
  onerror: (error) => {
1697
1720
  this.logger.error('Broadcast stream error', error);
1698
- this.handleError(new SDKError(OperationErrorCode.OPERATION_FAILED, '播报流错误', error));
1721
+ const sdkError = new SDKError(OperationErrorCode.OPERATION_FAILED, '服务出错了', error);
1722
+ this.handleError(sdkError);
1723
+ // 必须抛出错误,否则会循环重试请求
1724
+ throw new Error(`服务出错了${sdkError.message}`);
1699
1725
  }
1700
1726
  });
1701
1727
  }
@@ -1819,16 +1845,6 @@ class BroadcastService extends UnityBaseService {
1819
1845
  get callbackFunctionName() {
1820
1846
  return 'uniBroadcastCallback';
1821
1847
  }
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
1848
  /**
1833
1849
  * 获取播报API路径
1834
1850
  * @param type - 播报类型
@@ -1838,10 +1854,19 @@ class BroadcastService extends UnityBaseService {
1838
1854
  * @private
1839
1855
  */
1840
1856
  getBroadcastApiPath(type) {
1857
+ const env = ConfigManager.getInstance().getEnv();
1841
1858
  switch (type) {
1842
1859
  case BroadcastType.TEXT:
1860
+ // 临时处理,开发和测试环境使用新接口
1861
+ if (env === 'dev' || env === 'test') {
1862
+ return '/aiep-openapi/avatar-interaction/v1/broadcast/text';
1863
+ }
1843
1864
  return '/dh-talker/user/agent/broadcast/text';
1844
1865
  case BroadcastType.AUDIO:
1866
+ // 临时处理,开发和测试环境使用新接口
1867
+ if (env === 'dev' || env === 'test') {
1868
+ return '/aiep-openapi/avatar-interaction/v1/broadcast/audio';
1869
+ }
1845
1870
  return '/dh-talker/user/agent/broadcast/customAudio';
1846
1871
  default:
1847
1872
  throw new SDKError(ConfigErrorCode.INVALID_CONFIG, `未知的播报类型: ${type}`);
@@ -1883,6 +1908,31 @@ class BroadcastService extends UnityBaseService {
1883
1908
  // 触发错误回调
1884
1909
  (_b = (_a = this.callbacks).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
1885
1910
  }
1911
+ /**
1912
+ * 处理播报错误
1913
+ * @param errorCode - 错误码
1914
+ * @description 处理播报过程中的错误
1915
+ * @private
1916
+ */
1917
+ handleBroadcastError(errorCode) {
1918
+ // 用户权益额度不存在错误码 14001
1919
+ // 用户权益额度不足错误码 14002
1920
+ // 用户权益额度冻结失败 14003
1921
+ switch (errorCode) {
1922
+ case 14001:
1923
+ this.handleError(new SDKError(OperationErrorCode.BROADCAST_EQUITY_NOT_EXIST, '用户权益额度不存在'));
1924
+ break;
1925
+ case 14002:
1926
+ this.handleError(new SDKError(OperationErrorCode.BROADCAST_EQUITY_NOT_ENOUGH, '用户权益额度不足'));
1927
+ break;
1928
+ case 14003:
1929
+ this.handleError(new SDKError(OperationErrorCode.BROADCAST_EQUITY_FREEZE_FAILED, '用户权益额度冻结失败'));
1930
+ break;
1931
+ default:
1932
+ this.handleError(new SDKError(OperationErrorCode.OPERATION_FAILED, '播报服务错误'));
1933
+ break;
1934
+ }
1935
+ }
1886
1936
  }
1887
1937
 
1888
1938
  /**
@@ -2009,7 +2059,12 @@ class ZEEAvatarLoader {
2009
2059
  * @protected
2010
2060
  */
2011
2061
  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 });
2062
+ const params = {
2063
+ token: ConfigManager.getInstance().getToken(),
2064
+ apiBaseUrl: ConfigManager.getInstance().getApiBaseUrl(false),
2065
+ idleMotionList: ConfigManager.getInstance().getConfig().idleMotionList,
2066
+ assetsUrl: ConfigManager.getInstance().getConfig().assetsUrl
2067
+ };
2013
2068
  console.warn('[ Send Unity message ]: AvatarSDK.InitializeConfig', params);
2014
2069
  this.unityInstance.SendMessage('AvatarSDK', 'InitializeConfig', JSON.stringify(params));
2015
2070
  }
@@ -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
 
@@ -1095,6 +1113,7 @@
1095
1113
  getApiBaseUrl(withModule = true) {
1096
1114
  var _a, _b, _c, _d;
1097
1115
  if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.env) === 'custom' && ((_b = this.config) === null || _b === void 0 ? void 0 : _b.apiUrl)) {
1116
+ // 如果环境为自定义,则直接返回配置的API,无需添加模块路径
1098
1117
  return this.config.apiUrl;
1099
1118
  }
1100
1119
  return ((_d = getEnvConfig(((_c = this.config) === null || _c === void 0 ? void 0 : _c.env) || 'prod', withModule)) === null || _d === void 0 ? void 0 : _d.apiBaseUrl) || '';
@@ -1568,6 +1587,10 @@
1568
1587
  break;
1569
1588
  }
1570
1589
  }
1590
+ else {
1591
+ const error = SDKError.createFromUnityError(code, `Unity operation '${operation}' failed: ${message}`);
1592
+ this.handleError(error);
1593
+ }
1571
1594
  }
1572
1595
  /**
1573
1596
  * 开始播报
@@ -1628,7 +1651,7 @@
1628
1651
  motionPlayMode: params.motionPlayMode
1629
1652
  });
1630
1653
  try {
1631
- const apiUrl = `${this.getApiBaseUrl()}${this.getBroadcastApiPath(params.type)}`;
1654
+ const apiUrl = `${ConfigManager.getInstance().getApiBaseUrl(true)}${this.getBroadcastApiPath(params.type)}`;
1632
1655
  const requestBody = {
1633
1656
  humanCode: params.humanCode,
1634
1657
  speed: params.speed,
@@ -1662,7 +1685,7 @@
1662
1685
  const response = JSON.parse(event.data);
1663
1686
  // 错误处理
1664
1687
  if (response.code !== 0) {
1665
- this.handleError(new SDKError(exports.NetworkErrorCode.SERVER_ERROR, response.message || '未知服务器错误'));
1688
+ this.handleBroadcastError(response.code);
1666
1689
  return;
1667
1690
  }
1668
1691
  // 流式播报
@@ -1701,7 +1724,10 @@
1701
1724
  },
1702
1725
  onerror: (error) => {
1703
1726
  this.logger.error('Broadcast stream error', error);
1704
- this.handleError(new SDKError(exports.OperationErrorCode.OPERATION_FAILED, '播报流错误', error));
1727
+ const sdkError = new SDKError(exports.OperationErrorCode.OPERATION_FAILED, '服务出错了', error);
1728
+ this.handleError(sdkError);
1729
+ // 必须抛出错误,否则会循环重试请求
1730
+ throw new Error(`服务出错了${sdkError.message}`);
1705
1731
  }
1706
1732
  });
1707
1733
  }
@@ -1825,16 +1851,6 @@
1825
1851
  get callbackFunctionName() {
1826
1852
  return 'uniBroadcastCallback';
1827
1853
  }
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
1854
  /**
1839
1855
  * 获取播报API路径
1840
1856
  * @param type - 播报类型
@@ -1844,10 +1860,19 @@
1844
1860
  * @private
1845
1861
  */
1846
1862
  getBroadcastApiPath(type) {
1863
+ const env = ConfigManager.getInstance().getEnv();
1847
1864
  switch (type) {
1848
1865
  case exports.BroadcastType.TEXT:
1866
+ // 临时处理,开发和测试环境使用新接口
1867
+ if (env === 'dev' || env === 'test') {
1868
+ return '/aiep-openapi/avatar-interaction/v1/broadcast/text';
1869
+ }
1849
1870
  return '/dh-talker/user/agent/broadcast/text';
1850
1871
  case exports.BroadcastType.AUDIO:
1872
+ // 临时处理,开发和测试环境使用新接口
1873
+ if (env === 'dev' || env === 'test') {
1874
+ return '/aiep-openapi/avatar-interaction/v1/broadcast/audio';
1875
+ }
1851
1876
  return '/dh-talker/user/agent/broadcast/customAudio';
1852
1877
  default:
1853
1878
  throw new SDKError(exports.ConfigErrorCode.INVALID_CONFIG, `未知的播报类型: ${type}`);
@@ -1889,6 +1914,31 @@
1889
1914
  // 触发错误回调
1890
1915
  (_b = (_a = this.callbacks).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
1891
1916
  }
1917
+ /**
1918
+ * 处理播报错误
1919
+ * @param errorCode - 错误码
1920
+ * @description 处理播报过程中的错误
1921
+ * @private
1922
+ */
1923
+ handleBroadcastError(errorCode) {
1924
+ // 用户权益额度不存在错误码 14001
1925
+ // 用户权益额度不足错误码 14002
1926
+ // 用户权益额度冻结失败 14003
1927
+ switch (errorCode) {
1928
+ case 14001:
1929
+ this.handleError(new SDKError(exports.OperationErrorCode.BROADCAST_EQUITY_NOT_EXIST, '用户权益额度不存在'));
1930
+ break;
1931
+ case 14002:
1932
+ this.handleError(new SDKError(exports.OperationErrorCode.BROADCAST_EQUITY_NOT_ENOUGH, '用户权益额度不足'));
1933
+ break;
1934
+ case 14003:
1935
+ this.handleError(new SDKError(exports.OperationErrorCode.BROADCAST_EQUITY_FREEZE_FAILED, '用户权益额度冻结失败'));
1936
+ break;
1937
+ default:
1938
+ this.handleError(new SDKError(exports.OperationErrorCode.OPERATION_FAILED, '播报服务错误'));
1939
+ break;
1940
+ }
1941
+ }
1892
1942
  }
1893
1943
 
1894
1944
  /**
@@ -2015,7 +2065,12 @@
2015
2065
  * @protected
2016
2066
  */
2017
2067
  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 });
2068
+ const params = {
2069
+ token: ConfigManager.getInstance().getToken(),
2070
+ apiBaseUrl: ConfigManager.getInstance().getApiBaseUrl(false),
2071
+ idleMotionList: ConfigManager.getInstance().getConfig().idleMotionList,
2072
+ assetsUrl: ConfigManager.getInstance().getConfig().assetsUrl
2073
+ };
2019
2074
  console.warn('[ Send Unity message ]: AvatarSDK.InitializeConfig', params);
2020
2075
  this.unityInstance.SendMessage('AvatarSDK', 'InitializeConfig', JSON.stringify(params));
2021
2076
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zeewain/3d-avatar-sdk",
3
3
  "type": "module",
4
- "version": "1.2.1",
4
+ "version": "1.2.2",
5
5
  "description": "SDK for ZEE Avatar WebGL integration",
6
6
  "author": "ZEEWain",
7
7
  "license": "MIT",
@@ -76,12 +76,13 @@
76
76
  "cross-env": "^7.0.3",
77
77
  "del-cli": "^5.1.0",
78
78
  "eslint": "^8.22.0",
79
+ "fs-extra": "^11.3.0",
80
+ "glob": "^11.0.3",
81
+ "minimatch": "^10.0.3",
79
82
  "release-it": "^17.6.0",
80
83
  "rollup": "^4.12.0",
81
84
  "rollup-plugin-copy": "^3.5.0",
82
85
  "rollup-plugin-dts": "^6.1.0",
83
- "rollup-plugin-livereload": "^2.0.5",
84
- "rollup-plugin-serve": "^3.0.0",
85
86
  "tslib": "^2.6.2",
86
87
  "typescript": "^5.8.3"
87
88
  },