@zeewain/3d-avatar-sdk 1.2.4 → 2.1.1

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.
@@ -113,6 +113,8 @@
113
113
  ResourceErrorCode[ResourceErrorCode["NOT_FOUND"] = 3003] = "NOT_FOUND";
114
114
  /** 资源格式不支持 */
115
115
  ResourceErrorCode[ResourceErrorCode["UNSUPPORTED_FORMAT"] = 3004] = "UNSUPPORTED_FORMAT";
116
+ /** 资源版本不兼容 */
117
+ ResourceErrorCode[ResourceErrorCode["VERSION_INCOMPATIBLE"] = 3005] = "VERSION_INCOMPATIBLE";
116
118
  })(exports.ResourceErrorCode || (exports.ResourceErrorCode = {}));
117
119
  /**
118
120
  * 系统错误码 (4xxx)
@@ -219,6 +221,10 @@
219
221
  category: exports.ErrorCategory.RESOURCE,
220
222
  message: '资源格式不支持'
221
223
  },
224
+ [exports.ResourceErrorCode.VERSION_INCOMPATIBLE]: {
225
+ category: exports.ErrorCategory.RESOURCE,
226
+ message: '资源版本不兼容'
227
+ },
222
228
  // 系统错误
223
229
  [exports.SystemErrorCode.OUT_OF_MEMORY]: {
224
230
  category: exports.ErrorCategory.SYSTEM,
@@ -407,6 +413,44 @@
407
413
  }
408
414
  }
409
415
 
416
+ /**
417
+ * Unity服务日志级别枚举
418
+ * @enum {string}
419
+ * @description 定义日志记录的级别
420
+ */
421
+ var LogLevel;
422
+ (function (LogLevel) {
423
+ LogLevel["DEBUG"] = "debug";
424
+ LogLevel["INFO"] = "info";
425
+ LogLevel["WARN"] = "warn";
426
+ LogLevel["ERROR"] = "error";
427
+ })(LogLevel || (LogLevel = {}));
428
+ /**
429
+ * 简单日志记录器实现
430
+ * @class SimpleLogger
431
+ * @implements {ISimpleLogger}
432
+ * @description 提供基础的日志记录功能
433
+ */
434
+ class SimpleLogger {
435
+ constructor(enableDebug = false) {
436
+ this.enableDebug = enableDebug;
437
+ }
438
+ debug(message, data) {
439
+ if (this.enableDebug) {
440
+ console.debug(`[SDK DEBUG] ${message}`, data);
441
+ }
442
+ }
443
+ info(message, data) {
444
+ console.info(`[SDK INFO] ${message}`, data);
445
+ }
446
+ warn(message, data) {
447
+ console.warn(`[SDK WARN] ${message}`, data);
448
+ }
449
+ error(message, error, data) {
450
+ console.error(`[SDK ERROR] ${message}`, error, error instanceof SDKError ? error.code : null, data);
451
+ }
452
+ }
453
+
410
454
  /**
411
455
  * @fileoverview Unity服务基础类型定义
412
456
  * @description 定义Unity服务的通用接口和类型,为所有Unity服务提供统一的基础类型
@@ -427,18 +471,6 @@
427
471
  /** 操作取消 */
428
472
  UnityOperationStatus[UnityOperationStatus["CANCELLED"] = 3] = "CANCELLED";
429
473
  })(exports.UnityOperationStatus || (exports.UnityOperationStatus = {}));
430
- /**
431
- * Unity服务日志级别枚举
432
- * @enum {string}
433
- * @description 定义日志记录的级别
434
- */
435
- exports.LogLevel = void 0;
436
- (function (LogLevel) {
437
- LogLevel["DEBUG"] = "debug";
438
- LogLevel["INFO"] = "info";
439
- LogLevel["WARN"] = "warn";
440
- LogLevel["ERROR"] = "error";
441
- })(exports.LogLevel || (exports.LogLevel = {}));
442
474
 
443
475
  /**
444
476
  * @fileoverview Unity服务抽象基类
@@ -723,31 +755,6 @@
723
755
  });
724
756
  }
725
757
  }
726
- /**
727
- * 简单日志记录器实现
728
- * @class SimpleLogger
729
- * @implements {IUnityLogger}
730
- * @description 提供基础的日志记录功能
731
- */
732
- class SimpleLogger {
733
- constructor(enableDebug = false) {
734
- this.enableDebug = enableDebug;
735
- }
736
- debug(message, data) {
737
- if (this.enableDebug) {
738
- console.debug(`[Unity Debug] ${message}`, data);
739
- }
740
- }
741
- info(message, data) {
742
- console.info(`[Unity Info] ${message}`, data);
743
- }
744
- warn(message, data) {
745
- console.warn(`[Unity Warning] ${message}`, data);
746
- }
747
- error(message, error, data) {
748
- console.error(`[Unity Error] ${message}`, error, error instanceof SDKError ? error.code : null, data);
749
- }
750
- }
751
758
 
752
759
  /**
753
760
  * @fileoverview Avatar API接口定义
@@ -842,6 +849,9 @@
842
849
  }
843
850
  });
844
851
  }
852
+ handleCallback(operation, code, message, data) {
853
+ super.handleCallback(operation, code, message, data);
854
+ }
845
855
  /**
846
856
  * 播放数字人动作
847
857
  * @param clipCode - 动作编码
@@ -1079,6 +1089,16 @@
1079
1089
  setConfig(config) {
1080
1090
  this.config = Object.assign(Object.assign({}, config), { env: config.env || 'prod', containerId: config.containerId || 'unity-container' });
1081
1091
  }
1092
+ /**
1093
+ * 更新SDK配置
1094
+ * @param config - SDK配置对象
1095
+ * @description 更新全局SDK配置
1096
+ */
1097
+ updateConfig(config) {
1098
+ if (this.config) {
1099
+ this.config = Object.assign(Object.assign({}, this.config), config);
1100
+ }
1101
+ }
1082
1102
  /**
1083
1103
  * 获取SDK配置
1084
1104
  * @returns IAvatarSDKConfig | null SDK配置对象或null
@@ -1087,24 +1107,6 @@
1087
1107
  getConfig() {
1088
1108
  return this.config;
1089
1109
  }
1090
- /**
1091
- * 获取认证token
1092
- * @returns string 认证token
1093
- * @description 获取当前配置的认证token
1094
- */
1095
- getToken() {
1096
- var _a;
1097
- return ((_a = this.config) === null || _a === void 0 ? void 0 : _a.token) || '';
1098
- }
1099
- /**
1100
- * 获取环境类型
1101
- * @returns string 环境类型
1102
- * @description 获取当前配置的环境类型
1103
- */
1104
- getEnv() {
1105
- var _a;
1106
- return ((_a = this.config) === null || _a === void 0 ? void 0 : _a.env) || 'prod';
1107
- }
1108
1110
  /**
1109
1111
  * 获取API基础URL
1110
1112
  * @param withApiModule 是否包含模块路径
@@ -1119,15 +1121,6 @@
1119
1121
  }
1120
1122
  return ((_d = getEnvConfig(((_c = this.config) === null || _c === void 0 ? void 0 : _c.env) || 'prod', withApiModule)) === null || _d === void 0 ? void 0 : _d.apiBaseUrl) || '';
1121
1123
  }
1122
- /**
1123
- * 获取自定义API URL
1124
- * @returns string | undefined 自定义API URL
1125
- * @description 获取自定义API URL配置
1126
- */
1127
- getCustomApiUrl() {
1128
- var _a;
1129
- return (_a = this.config) === null || _a === void 0 ? void 0 : _a.apiUrl;
1130
- }
1131
1124
  /**
1132
1125
  * 重置配置
1133
1126
  * @description 清空当前配置
@@ -1562,14 +1555,14 @@
1562
1555
  this.taskSequence = 0;
1563
1556
  /** 当前发送任务的序号 */
1564
1557
  this.currentSendingSequence = 0;
1565
- /** 是否正在生成音频 */
1566
- this.isGeneratingAudio = false;
1558
+ /** 是否正在播报音频 */
1559
+ this.isBroadcastingAudio = false;
1567
1560
  /** 是否已经收到音频 */
1568
1561
  this.hasReceivedAudio = false;
1569
1562
  /** 队列处理定时器 */
1570
1563
  this.queueProcessTimer = null;
1571
- /** 主请求控制器(兼容性保留) */
1572
- this.activeController = null;
1564
+ /** 播报完成次数 */
1565
+ this.broadcastCompletedCount = 0;
1573
1566
  this.callbacks = config.callbacks || {};
1574
1567
  this.logger.info('Broadcast service initialized', { config });
1575
1568
  }
@@ -1583,7 +1576,7 @@
1583
1576
  * @override
1584
1577
  */
1585
1578
  handleCallback(operation, code, message, data) {
1586
- var _a, _b, _c, _d, _e, _f, _g, _h;
1579
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1587
1580
  // 提取 isBroadcastCompleted 参数
1588
1581
  const { isBroadcastCompleted } = JSON.parse(data || '{}');
1589
1582
  // 先调用基类处理逻辑
@@ -1593,19 +1586,31 @@
1593
1586
  switch (operation) {
1594
1587
  case exports.BroadcastOperationType.START_BROADCAST:
1595
1588
  if (isBroadcastCompleted) {
1596
- (_b = (_a = this.callbacks).onFinish) === null || _b === void 0 ? void 0 : _b.call(_a);
1589
+ this.broadcastCompletedCount++;
1590
+ const status = this.getStatus();
1591
+ if (((_a = status.queueInfo) === null || _a === void 0 ? void 0 : _a.completedTasks) === this.broadcastCompletedCount) {
1592
+ // 重置状态、计数
1593
+ this.isBroadcastingAudio = false;
1594
+ this.hasReceivedAudio = false;
1595
+ this.currentSendingSequence = 0;
1596
+ // 清理已完成的任务
1597
+ this.cleanupCompletedTasks();
1598
+ this.logger.warn('Broadcast all completed');
1599
+ }
1600
+ // this.logger.warn('AAAAAA', { status: this.getStatus(), broadcastCompletedCount: this.broadcastCompletedCount });
1601
+ (_c = (_b = this.callbacks).onFinish) === null || _c === void 0 ? void 0 : _c.call(_b);
1597
1602
  }
1598
1603
  break;
1599
1604
  case exports.BroadcastOperationType.PAUSE_BROADCAST:
1600
- (_d = (_c = this.callbacks).onPause) === null || _d === void 0 ? void 0 : _d.call(_c);
1605
+ (_e = (_d = this.callbacks).onPause) === null || _e === void 0 ? void 0 : _e.call(_d);
1601
1606
  this.logger.debug('Broadcast paused callback triggered');
1602
1607
  break;
1603
1608
  case exports.BroadcastOperationType.RESUME_BROADCAST:
1604
- (_f = (_e = this.callbacks).onResume) === null || _f === void 0 ? void 0 : _f.call(_e);
1609
+ (_g = (_f = this.callbacks).onResume) === null || _g === void 0 ? void 0 : _g.call(_f);
1605
1610
  this.logger.debug('Broadcast resumed callback triggered');
1606
1611
  break;
1607
1612
  case exports.BroadcastOperationType.STOP_BROADCAST:
1608
- (_h = (_g = this.callbacks).onStop) === null || _h === void 0 ? void 0 : _h.call(_g);
1613
+ (_j = (_h = this.callbacks).onStop) === null || _j === void 0 ? void 0 : _j.call(_h);
1609
1614
  this.logger.debug('Broadcast stopped callback triggered');
1610
1615
  break;
1611
1616
  }
@@ -1671,7 +1676,7 @@
1671
1676
  });
1672
1677
  // 触发开始回调
1673
1678
  (_b = (_a = this.callbacks).onStart) === null || _b === void 0 ? void 0 : _b.call(_a);
1674
- this.isGeneratingAudio = true;
1679
+ this.isBroadcastingAudio = true;
1675
1680
  }
1676
1681
  // 创建新的播报任务
1677
1682
  const task = this.createBroadcastTask(params);
@@ -1746,8 +1751,9 @@
1746
1751
  // 取消所有队列中的任务
1747
1752
  this.cancelAllTasks();
1748
1753
  // 重置状态
1749
- this.isGeneratingAudio = false;
1754
+ this.isBroadcastingAudio = false;
1750
1755
  this.hasReceivedAudio = false;
1756
+ this.broadcastCompletedCount = 0;
1751
1757
  try {
1752
1758
  yield this.sendAsyncMessage('StopBroadcast', exports.BroadcastOperationType.STOP_BROADCAST, {});
1753
1759
  this.logger.info('Broadcast stopped successfully');
@@ -1773,19 +1779,23 @@
1773
1779
  * @description 获取当前播报服务的状态信息,包括队列状态
1774
1780
  */
1775
1781
  getStatus() {
1782
+ const completedTasks = this.taskQueue.filter((t) => t.status === BroadcastTaskStatus.COMPLETED).length;
1783
+ const requestingTasks = this.taskQueue.filter((t) => t.status === BroadcastTaskStatus.REQUESTING).length;
1784
+ const failedTasks = this.taskQueue.filter((t) => t.status === BroadcastTaskStatus.FAILED).length;
1785
+ const totalPendingResponses = this.taskQueue.reduce((sum, t) => sum + t.pendingResponses.length, 0);
1786
+ const currentSendingSequence = this.currentSendingSequence;
1787
+ const isGeneratingAudio = completedTasks + failedTasks !== this.taskQueue.length;
1776
1788
  return {
1777
- isActive: this.taskQueue.length > 0 || this.isGeneratingAudio,
1778
- isGeneratingAudio: this.isGeneratingAudio,
1789
+ isActive: this.isBroadcastingAudio || isGeneratingAudio, // 是否正在播报音频或正在生成音频
1790
+ isGeneratingAudio,
1779
1791
  hasReceivedAudio: this.hasReceivedAudio,
1780
- pendingCallbacks: this.getPendingCallbackCount(),
1781
- hasController: this.activeController !== null,
1782
1792
  queueInfo: {
1783
1793
  totalTasks: this.taskQueue.length,
1784
- requestingTasks: this.taskQueue.filter((t) => t.status === BroadcastTaskStatus.REQUESTING).length,
1785
- completedTasks: this.taskQueue.filter((t) => t.status === BroadcastTaskStatus.COMPLETED).length,
1786
- failedTasks: this.taskQueue.filter((t) => t.status === BroadcastTaskStatus.FAILED).length,
1787
- totalPendingResponses: this.taskQueue.reduce((sum, t) => sum + t.pendingResponses.length, 0),
1788
- currentSendingSequence: this.currentSendingSequence
1794
+ requestingTasks,
1795
+ completedTasks,
1796
+ failedTasks,
1797
+ totalPendingResponses,
1798
+ currentSendingSequence
1789
1799
  }
1790
1800
  };
1791
1801
  }
@@ -1795,10 +1805,7 @@
1795
1805
  */
1796
1806
  destroy() {
1797
1807
  // 清理队列处理定时器
1798
- if (this.queueProcessTimer) {
1799
- clearInterval(this.queueProcessTimer);
1800
- this.queueProcessTimer = null;
1801
- }
1808
+ this.clearQueueProcessTimer();
1802
1809
  // 取消所有任务
1803
1810
  this.cancelAllTasks();
1804
1811
  // 调用基类销毁方法
@@ -1867,12 +1874,12 @@
1867
1874
  if (nextTask) {
1868
1875
  this.sendNextResponse(nextTask);
1869
1876
  }
1870
- // 清理已完成的任务
1871
- this.cleanupCompletedTasks();
1872
- // 如果队列为空,停止定时器
1873
- if (this.taskQueue.length === 0 && this.queueProcessTimer) {
1874
- clearInterval(this.queueProcessTimer);
1875
- this.queueProcessTimer = null;
1877
+ // 如果队列中没有剩余任务,则停止定时器
1878
+ const remainingTasks = this.taskQueue.filter(task => task.status !== BroadcastTaskStatus.COMPLETED
1879
+ && task.status !== BroadcastTaskStatus.FAILED
1880
+ && task.status !== BroadcastTaskStatus.CANCELLED);
1881
+ if (remainingTasks.length === 0) {
1882
+ this.clearQueueProcessTimer();
1876
1883
  }
1877
1884
  }
1878
1885
  /**
@@ -1883,6 +1890,7 @@
1883
1890
  */
1884
1891
  startTaskRequest(task) {
1885
1892
  return __awaiter(this, void 0, void 0, function* () {
1893
+ var _a;
1886
1894
  task.status = BroadcastTaskStatus.REQUESTING;
1887
1895
  this.logger.debug('Starting task request', { taskId: task.id });
1888
1896
  try {
@@ -1891,7 +1899,8 @@
1891
1899
  humanCode: task.params.humanCode,
1892
1900
  speed: task.params.speed,
1893
1901
  volume: task.params.volume >= 0 ? task.params.volume * 100 : undefined,
1894
- isSubtitle: task.params.isSubtitle
1902
+ isSubtitle: task.params.isSubtitle,
1903
+ audioDrivenVersion: ConfigManager.getInstance().getConfig().audioDrivenVersion
1895
1904
  };
1896
1905
  // 根据播报类型设置特定参数
1897
1906
  if (task.params.type === exports.BroadcastType.TEXT) {
@@ -1907,7 +1916,7 @@
1907
1916
  method: 'POST',
1908
1917
  headers: {
1909
1918
  'Content-Type': 'application/json',
1910
- 'x_auth_token': ConfigManager.getInstance().getToken()
1919
+ 'x_auth_token': ((_a = ConfigManager.getInstance().getConfig()) === null || _a === void 0 ? void 0 : _a.token) || ''
1911
1920
  },
1912
1921
  body: JSON.stringify(requestBody),
1913
1922
  signal: task.controller.signal,
@@ -1946,6 +1955,7 @@
1946
1955
  }
1947
1956
  // 处理音频数据
1948
1957
  if (response.data) {
1958
+ this.hasReceivedAudio = true;
1949
1959
  // 自定义音频播报时,如果服务器未返回音频URL,使用传入的audioUrl
1950
1960
  if (task.params.type === exports.BroadcastType.AUDIO && task.params.audioUrl && !response.data.voiceUrl) {
1951
1961
  response.data.voiceUrl = task.params.audioUrl;
@@ -2068,7 +2078,6 @@
2068
2078
  * @private
2069
2079
  */
2070
2080
  getBroadcastApiPath(type) {
2071
- ConfigManager.getInstance().getEnv();
2072
2081
  switch (type) {
2073
2082
  case exports.BroadcastType.TEXT:
2074
2083
  return '/aiep-openapi/avatar-interaction/v1/broadcast/text';
@@ -2106,11 +2115,6 @@
2106
2115
  handleError(error) {
2107
2116
  var _a, _b;
2108
2117
  this.logger.error('Broadcast error occurred', error);
2109
- // 清理控制器
2110
- if (this.activeController) {
2111
- this.activeController.abort();
2112
- this.activeController = null;
2113
- }
2114
2118
  // 触发错误回调
2115
2119
  (_b = (_a = this.callbacks).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
2116
2120
  }
@@ -2139,6 +2143,17 @@
2139
2143
  break;
2140
2144
  }
2141
2145
  }
2146
+ /**
2147
+ * 清理队列处理定时器
2148
+ * @description 清理队列处理定时器
2149
+ * @private
2150
+ */
2151
+ clearQueueProcessTimer() {
2152
+ if (this.queueProcessTimer) {
2153
+ clearInterval(this.queueProcessTimer);
2154
+ this.queueProcessTimer = null;
2155
+ }
2156
+ }
2142
2157
  }
2143
2158
 
2144
2159
  /**
@@ -2156,13 +2171,11 @@
2156
2171
  * @param config - Unity配置对象
2157
2172
  * @description 初始化数字人加载器,创建Unity加载器实例
2158
2173
  */
2159
- constructor(config) {
2174
+ constructor() {
2160
2175
  /** Avatar API实例 */
2161
2176
  this.apiService = null;
2162
2177
  /** Unity实例 */
2163
2178
  this.unityInstance = null;
2164
- // 同时设置到配置管理器中
2165
- ConfigManager.getInstance().setConfig(config);
2166
2179
  this.loader = new UnityLoader();
2167
2180
  }
2168
2181
  /**
@@ -2265,17 +2278,61 @@
2265
2278
  * @protected
2266
2279
  */
2267
2280
  initGlobalConfig() {
2268
- const params = {
2269
- token: ConfigManager.getInstance().getToken(),
2281
+ const config = ConfigManager.getInstance().getConfig();
2282
+ const globalParams = {
2283
+ token: config === null || config === void 0 ? void 0 : config.token,
2270
2284
  apiBaseUrl: ConfigManager.getInstance().getApiBaseUrl(false),
2271
- idleMotionList: ConfigManager.getInstance().getConfig().idleMotionList,
2272
- assetsUrl: ConfigManager.getInstance().getConfig().assetsUrl
2285
+ idleMotionList: config === null || config === void 0 ? void 0 : config.idleMotionList
2286
+ // 純AB包方案在SDK 2.1.0 中已弃用
2287
+ // assetsUrl: config?.assetsUrl
2273
2288
  };
2274
- console.warn('[ Send Unity message ]: AvatarSDK.InitializeConfig', params);
2275
- this.unityInstance.SendMessage('AvatarSDK', 'InitializeConfig', JSON.stringify(params));
2289
+ const assetModuleParams = {
2290
+ isZip: true,
2291
+ assetBundlePath: config === null || config === void 0 ? void 0 : config.assetsUrl
2292
+ };
2293
+ this.unityInstance.SendMessage('AvatarSDK', 'InitializeConfig', JSON.stringify(globalParams));
2294
+ this.unityInstance.SendMessage('AvatarSDK', 'InitAssetBundleModule', JSON.stringify(assetModuleParams));
2295
+ console.warn('[ Send Unity message ]: AvatarSDK.InitializeConfig', globalParams);
2296
+ console.warn('[ Send Unity message ]: AvatarSDK.InitAssetBundleModule', assetModuleParams);
2276
2297
  }
2277
2298
  }
2278
2299
 
2300
+ // 深拷贝
2301
+ /**
2302
+ * 比较两个版本号的前两位(major.minor)是否一致
2303
+ * @param version1 版本号1,格式:x.x.x
2304
+ * @param version2 版本号2,格式:x.x.x
2305
+ * @returns boolean 如果前两位一致返回 true,否则返回 false
2306
+ * @description 用于检查 SDK 版本与资源版本是否兼容
2307
+ * @example
2308
+ * compareVersionCompatibility('2.1.0', '2.1.5') // true
2309
+ * compareVersionCompatibility('2.1.0', '2.2.0') // false
2310
+ * compareVersionCompatibility('2.1.0', '3.0.0') // false
2311
+ */
2312
+ function compareVersionCompatibility(version1, version2) {
2313
+ // 提取版本号的前两位(major.minor)
2314
+ const getMajorMinor = (version) => {
2315
+ const parts = version.split('.');
2316
+ if (parts.length < 2) {
2317
+ return version;
2318
+ }
2319
+ return `${parts[0]}.${parts[1]}`;
2320
+ };
2321
+ const v1MajorMinor = getMajorMinor(version1);
2322
+ const v2MajorMinor = getMajorMinor(version2);
2323
+ return v1MajorMinor === v2MajorMinor;
2324
+ }
2325
+
2326
+ /**
2327
+ * @fileoverview SDK 版本号常量
2328
+ * @description 此文件由构建脚本自动生成,请勿手动修改
2329
+ */
2330
+ /**
2331
+ * SDK 版本号
2332
+ * @const {string} SDK_VERSION
2333
+ */
2334
+ const SDK_VERSION = '2.1.1';
2335
+
2279
2336
  /**
2280
2337
  * @fileoverview 统一的3D数字人SDK入口类
2281
2338
  * @description 提供统一的SDK接口,内部通过组合模式调用各个服务模块
@@ -2308,10 +2365,12 @@
2308
2365
  this.unityInstance = null;
2309
2366
  /** SDK初始化状态 */
2310
2367
  this.isInitialized = false;
2311
- this.config = config;
2312
2368
  this.instanceId = generateUniqueId();
2313
2369
  // 设置全局配置
2314
2370
  ConfigManager.getInstance().setConfig(config);
2371
+ // 设置日志
2372
+ this.logger = new SimpleLogger(ConfigManager.getInstance().getConfig().enableDebugLog);
2373
+ this.logger.info('SDK版本', SDK_VERSION);
2315
2374
  }
2316
2375
  /**
2317
2376
  * 初始化数字人
@@ -2322,12 +2381,14 @@
2322
2381
  */
2323
2382
  initializeAvatar(avatarCode_1) {
2324
2383
  return __awaiter(this, arguments, void 0, function* (avatarCode, cameraType = exports.AvatarCameraType.WHOLE) {
2384
+ var _a;
2325
2385
  if (this.isInitialized) {
2326
2386
  throw new SDKError(exports.OperationErrorCode.OPERATION_FAILED, 'SDK已经初始化,请勿重复初始化');
2327
2387
  }
2328
2388
  try {
2389
+ const config = ConfigManager.getInstance().getConfig();
2329
2390
  // 1. 创建Unity加载器
2330
- this.loader = new ZEEAvatarLoader(this.config);
2391
+ this.loader = new ZEEAvatarLoader();
2331
2392
  // 2. 初始化Unity实例
2332
2393
  yield this.loader.init();
2333
2394
  // 3. 获取Unity实例
@@ -2336,18 +2397,31 @@
2336
2397
  this.avatarService = new AvatarService({
2337
2398
  unityInstance: this.unityInstance,
2338
2399
  instanceId: this.instanceId,
2339
- enableDebugLog: this.config.enableDebugLog
2400
+ enableDebugLog: config.enableDebugLog
2340
2401
  });
2341
2402
  // 5. 创建带有唯一标识符的播报服务
2342
2403
  this.broadcastService = new BroadcastService({
2343
2404
  unityInstance: this.unityInstance,
2344
2405
  instanceId: this.instanceId,
2345
- callbacks: this.config.broadcastCallbacks,
2346
- enableDebugLog: this.config.enableDebugLog
2406
+ callbacks: config.broadcastCallbacks,
2407
+ enableDebugLog: config.enableDebugLog
2347
2408
  });
2348
2409
  // 6. 初始化数字人
2349
2410
  const result = yield this.avatarService.initializeAvatar(avatarCode, cameraType);
2350
2411
  if (result.success) {
2412
+ const audioDrivenVersion = (_a = result.data) === null || _a === void 0 ? void 0 : _a.audioDrivenVersion;
2413
+ config.audioDrivenVersion = audioDrivenVersion;
2414
+ this.logger.info('AudioDrivenVersion', audioDrivenVersion);
2415
+ // 7. 检查资源版本兼容性
2416
+ if (audioDrivenVersion) {
2417
+ const isCompatible = compareVersionCompatibility(SDK_VERSION, audioDrivenVersion);
2418
+ if (!isCompatible) {
2419
+ // 销毁SDK实例
2420
+ this.destroy();
2421
+ throw new SDKError(exports.ResourceErrorCode.VERSION_INCOMPATIBLE, `资源版本不兼容: SDK版本为 ${SDK_VERSION},WebGL资源版本为 ${audioDrivenVersion},前两位版本号必须一致`);
2422
+ }
2423
+ this.logger.info('版本兼容性检查通过', `SDK: ${SDK_VERSION}, 资源: ${audioDrivenVersion}`);
2424
+ }
2351
2425
  this.isInitialized = true;
2352
2426
  }
2353
2427
  return result;
@@ -2363,8 +2437,7 @@
2363
2437
  * @description 更新全局Token配置
2364
2438
  */
2365
2439
  updateToken(token) {
2366
- this.config.token = token;
2367
- ConfigManager.getInstance().setConfig(this.config);
2440
+ ConfigManager.getInstance().updateConfig({ token });
2368
2441
  // 如果loader已经初始化,也更新loader的token
2369
2442
  if (this.loader) {
2370
2443
  this.loader.updateToken(token);
@@ -2548,7 +2621,8 @@
2548
2621
  * @returns IAvatarSDKConfig 当前配置
2549
2622
  */
2550
2623
  getConfig() {
2551
- return Object.assign({}, this.config);
2624
+ const config = ConfigManager.getInstance().getConfig();
2625
+ return config ? Object.assign({}, config) : null;
2552
2626
  }
2553
2627
  // ===========================================
2554
2628
  // 私有方法
@@ -2568,6 +2642,7 @@
2568
2642
  exports.BroadcastService = BroadcastService;
2569
2643
  exports.ERROR_CODE_MAP = ERROR_CODE_MAP;
2570
2644
  exports.SDKError = SDKError;
2645
+ exports.SDK_VERSION = SDK_VERSION;
2571
2646
  exports.ZEEAvatarLoader = ZEEAvatarLoader;
2572
2647
  exports.ZEEAvatarSDK = ZEEAvatarSDK;
2573
2648
  exports.getErrorInfo = getErrorInfo;
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.4",
4
+ "version": "2.1.1",
5
5
  "description": "SDK for ZEE Avatar WebGL integration",
6
6
  "author": "ZEEWain",
7
7
  "license": "MIT",
@@ -44,10 +44,11 @@
44
44
  "dev": "cross-env NODE_ENV=development rollup -c -w",
45
45
  "dev:watch": "cross-env NODE_ENV=development rollup -c -w --watch.include='src/**'",
46
46
  "clean": "del-cli dist",
47
+ "generate:version": "node scripts/generate-version.js",
47
48
  "build": "npm run clean && cross-env NODE_ENV=production rollup -c",
48
49
  "test": "cross-env NODE_ENV=test rollup -c",
49
50
  "lint": "eslint \"./src/**/*.{ts,js}\" --fix",
50
- "prebuild": "npm run lint",
51
+ "prebuild": "npm run generate:version && npm run lint",
51
52
  "prepublishOnly": "npm run build",
52
53
  "start": "npm run test",
53
54
  "release": "release-it",
@@ -55,6 +56,9 @@
55
56
  "release:minor": "release-it minor",
56
57
  "release:major": "release-it major",
57
58
  "release:dry": "release-it --dry-run",
59
+ "release:internal": "release-it --config .release-it.internal.json",
60
+ "release:alpha": "npm run release:internal -- --preRelease=alpha",
61
+ "release:beta": "npm run release:internal -- --preRelease=beta",
58
62
  "version": "npm run build"
59
63
  },
60
64
  "dependencies": {
@@ -85,9 +89,5 @@
85
89
  "rollup-plugin-dts": "^6.1.0",
86
90
  "tslib": "^2.6.2",
87
91
  "typescript": "^5.8.3"
88
- },
89
- "publishConfig": {
90
- "registry": "https://registry.npmjs.org/",
91
- "access": "public"
92
92
  }
93
93
  }