@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.
package/dist/index.esm.js CHANGED
@@ -107,6 +107,8 @@ var ResourceErrorCode;
107
107
  ResourceErrorCode[ResourceErrorCode["NOT_FOUND"] = 3003] = "NOT_FOUND";
108
108
  /** 资源格式不支持 */
109
109
  ResourceErrorCode[ResourceErrorCode["UNSUPPORTED_FORMAT"] = 3004] = "UNSUPPORTED_FORMAT";
110
+ /** 资源版本不兼容 */
111
+ ResourceErrorCode[ResourceErrorCode["VERSION_INCOMPATIBLE"] = 3005] = "VERSION_INCOMPATIBLE";
110
112
  })(ResourceErrorCode || (ResourceErrorCode = {}));
111
113
  /**
112
114
  * 系统错误码 (4xxx)
@@ -213,6 +215,10 @@ const ERROR_CODE_MAP = {
213
215
  category: ErrorCategory.RESOURCE,
214
216
  message: '资源格式不支持'
215
217
  },
218
+ [ResourceErrorCode.VERSION_INCOMPATIBLE]: {
219
+ category: ErrorCategory.RESOURCE,
220
+ message: '资源版本不兼容'
221
+ },
216
222
  // 系统错误
217
223
  [SystemErrorCode.OUT_OF_MEMORY]: {
218
224
  category: ErrorCategory.SYSTEM,
@@ -401,6 +407,44 @@ class SDKError extends Error {
401
407
  }
402
408
  }
403
409
 
410
+ /**
411
+ * Unity服务日志级别枚举
412
+ * @enum {string}
413
+ * @description 定义日志记录的级别
414
+ */
415
+ var LogLevel;
416
+ (function (LogLevel) {
417
+ LogLevel["DEBUG"] = "debug";
418
+ LogLevel["INFO"] = "info";
419
+ LogLevel["WARN"] = "warn";
420
+ LogLevel["ERROR"] = "error";
421
+ })(LogLevel || (LogLevel = {}));
422
+ /**
423
+ * 简单日志记录器实现
424
+ * @class SimpleLogger
425
+ * @implements {ISimpleLogger}
426
+ * @description 提供基础的日志记录功能
427
+ */
428
+ class SimpleLogger {
429
+ constructor(enableDebug = false) {
430
+ this.enableDebug = enableDebug;
431
+ }
432
+ debug(message, data) {
433
+ if (this.enableDebug) {
434
+ console.debug(`[SDK DEBUG] ${message}`, data);
435
+ }
436
+ }
437
+ info(message, data) {
438
+ console.info(`[SDK INFO] ${message}`, data);
439
+ }
440
+ warn(message, data) {
441
+ console.warn(`[SDK WARN] ${message}`, data);
442
+ }
443
+ error(message, error, data) {
444
+ console.error(`[SDK ERROR] ${message}`, error, error instanceof SDKError ? error.code : null, data);
445
+ }
446
+ }
447
+
404
448
  /**
405
449
  * @fileoverview Unity服务基础类型定义
406
450
  * @description 定义Unity服务的通用接口和类型,为所有Unity服务提供统一的基础类型
@@ -421,18 +465,6 @@ var UnityOperationStatus;
421
465
  /** 操作取消 */
422
466
  UnityOperationStatus[UnityOperationStatus["CANCELLED"] = 3] = "CANCELLED";
423
467
  })(UnityOperationStatus || (UnityOperationStatus = {}));
424
- /**
425
- * Unity服务日志级别枚举
426
- * @enum {string}
427
- * @description 定义日志记录的级别
428
- */
429
- var LogLevel;
430
- (function (LogLevel) {
431
- LogLevel["DEBUG"] = "debug";
432
- LogLevel["INFO"] = "info";
433
- LogLevel["WARN"] = "warn";
434
- LogLevel["ERROR"] = "error";
435
- })(LogLevel || (LogLevel = {}));
436
468
 
437
469
  /**
438
470
  * @fileoverview Unity服务抽象基类
@@ -717,31 +749,6 @@ class UnityBaseService {
717
749
  });
718
750
  }
719
751
  }
720
- /**
721
- * 简单日志记录器实现
722
- * @class SimpleLogger
723
- * @implements {IUnityLogger}
724
- * @description 提供基础的日志记录功能
725
- */
726
- class SimpleLogger {
727
- constructor(enableDebug = false) {
728
- this.enableDebug = enableDebug;
729
- }
730
- debug(message, data) {
731
- if (this.enableDebug) {
732
- console.debug(`[Unity Debug] ${message}`, data);
733
- }
734
- }
735
- info(message, data) {
736
- console.info(`[Unity Info] ${message}`, data);
737
- }
738
- warn(message, data) {
739
- console.warn(`[Unity Warning] ${message}`, data);
740
- }
741
- error(message, error, data) {
742
- console.error(`[Unity Error] ${message}`, error, error instanceof SDKError ? error.code : null, data);
743
- }
744
- }
745
752
 
746
753
  /**
747
754
  * @fileoverview Avatar API接口定义
@@ -836,6 +843,9 @@ class AvatarService extends UnityBaseService {
836
843
  }
837
844
  });
838
845
  }
846
+ handleCallback(operation, code, message, data) {
847
+ super.handleCallback(operation, code, message, data);
848
+ }
839
849
  /**
840
850
  * 播放数字人动作
841
851
  * @param clipCode - 动作编码
@@ -1073,6 +1083,16 @@ class ConfigManager {
1073
1083
  setConfig(config) {
1074
1084
  this.config = Object.assign(Object.assign({}, config), { env: config.env || 'prod', containerId: config.containerId || 'unity-container' });
1075
1085
  }
1086
+ /**
1087
+ * 更新SDK配置
1088
+ * @param config - SDK配置对象
1089
+ * @description 更新全局SDK配置
1090
+ */
1091
+ updateConfig(config) {
1092
+ if (this.config) {
1093
+ this.config = Object.assign(Object.assign({}, this.config), config);
1094
+ }
1095
+ }
1076
1096
  /**
1077
1097
  * 获取SDK配置
1078
1098
  * @returns IAvatarSDKConfig | null SDK配置对象或null
@@ -1081,24 +1101,6 @@ class ConfigManager {
1081
1101
  getConfig() {
1082
1102
  return this.config;
1083
1103
  }
1084
- /**
1085
- * 获取认证token
1086
- * @returns string 认证token
1087
- * @description 获取当前配置的认证token
1088
- */
1089
- getToken() {
1090
- var _a;
1091
- return ((_a = this.config) === null || _a === void 0 ? void 0 : _a.token) || '';
1092
- }
1093
- /**
1094
- * 获取环境类型
1095
- * @returns string 环境类型
1096
- * @description 获取当前配置的环境类型
1097
- */
1098
- getEnv() {
1099
- var _a;
1100
- return ((_a = this.config) === null || _a === void 0 ? void 0 : _a.env) || 'prod';
1101
- }
1102
1104
  /**
1103
1105
  * 获取API基础URL
1104
1106
  * @param withApiModule 是否包含模块路径
@@ -1113,15 +1115,6 @@ class ConfigManager {
1113
1115
  }
1114
1116
  return ((_d = getEnvConfig(((_c = this.config) === null || _c === void 0 ? void 0 : _c.env) || 'prod', withApiModule)) === null || _d === void 0 ? void 0 : _d.apiBaseUrl) || '';
1115
1117
  }
1116
- /**
1117
- * 获取自定义API URL
1118
- * @returns string | undefined 自定义API URL
1119
- * @description 获取自定义API URL配置
1120
- */
1121
- getCustomApiUrl() {
1122
- var _a;
1123
- return (_a = this.config) === null || _a === void 0 ? void 0 : _a.apiUrl;
1124
- }
1125
1118
  /**
1126
1119
  * 重置配置
1127
1120
  * @description 清空当前配置
@@ -1556,14 +1549,14 @@ class BroadcastService extends UnityBaseService {
1556
1549
  this.taskSequence = 0;
1557
1550
  /** 当前发送任务的序号 */
1558
1551
  this.currentSendingSequence = 0;
1559
- /** 是否正在生成音频 */
1560
- this.isGeneratingAudio = false;
1552
+ /** 是否正在播报音频 */
1553
+ this.isBroadcastingAudio = false;
1561
1554
  /** 是否已经收到音频 */
1562
1555
  this.hasReceivedAudio = false;
1563
1556
  /** 队列处理定时器 */
1564
1557
  this.queueProcessTimer = null;
1565
- /** 主请求控制器(兼容性保留) */
1566
- this.activeController = null;
1558
+ /** 播报完成次数 */
1559
+ this.broadcastCompletedCount = 0;
1567
1560
  this.callbacks = config.callbacks || {};
1568
1561
  this.logger.info('Broadcast service initialized', { config });
1569
1562
  }
@@ -1577,7 +1570,7 @@ class BroadcastService extends UnityBaseService {
1577
1570
  * @override
1578
1571
  */
1579
1572
  handleCallback(operation, code, message, data) {
1580
- var _a, _b, _c, _d, _e, _f, _g, _h;
1573
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1581
1574
  // 提取 isBroadcastCompleted 参数
1582
1575
  const { isBroadcastCompleted } = JSON.parse(data || '{}');
1583
1576
  // 先调用基类处理逻辑
@@ -1587,19 +1580,31 @@ class BroadcastService extends UnityBaseService {
1587
1580
  switch (operation) {
1588
1581
  case BroadcastOperationType.START_BROADCAST:
1589
1582
  if (isBroadcastCompleted) {
1590
- (_b = (_a = this.callbacks).onFinish) === null || _b === void 0 ? void 0 : _b.call(_a);
1583
+ this.broadcastCompletedCount++;
1584
+ const status = this.getStatus();
1585
+ if (((_a = status.queueInfo) === null || _a === void 0 ? void 0 : _a.completedTasks) === this.broadcastCompletedCount) {
1586
+ // 重置状态、计数
1587
+ this.isBroadcastingAudio = false;
1588
+ this.hasReceivedAudio = false;
1589
+ this.currentSendingSequence = 0;
1590
+ // 清理已完成的任务
1591
+ this.cleanupCompletedTasks();
1592
+ this.logger.warn('Broadcast all completed');
1593
+ }
1594
+ // this.logger.warn('AAAAAA', { status: this.getStatus(), broadcastCompletedCount: this.broadcastCompletedCount });
1595
+ (_c = (_b = this.callbacks).onFinish) === null || _c === void 0 ? void 0 : _c.call(_b);
1591
1596
  }
1592
1597
  break;
1593
1598
  case BroadcastOperationType.PAUSE_BROADCAST:
1594
- (_d = (_c = this.callbacks).onPause) === null || _d === void 0 ? void 0 : _d.call(_c);
1599
+ (_e = (_d = this.callbacks).onPause) === null || _e === void 0 ? void 0 : _e.call(_d);
1595
1600
  this.logger.debug('Broadcast paused callback triggered');
1596
1601
  break;
1597
1602
  case BroadcastOperationType.RESUME_BROADCAST:
1598
- (_f = (_e = this.callbacks).onResume) === null || _f === void 0 ? void 0 : _f.call(_e);
1603
+ (_g = (_f = this.callbacks).onResume) === null || _g === void 0 ? void 0 : _g.call(_f);
1599
1604
  this.logger.debug('Broadcast resumed callback triggered');
1600
1605
  break;
1601
1606
  case BroadcastOperationType.STOP_BROADCAST:
1602
- (_h = (_g = this.callbacks).onStop) === null || _h === void 0 ? void 0 : _h.call(_g);
1607
+ (_j = (_h = this.callbacks).onStop) === null || _j === void 0 ? void 0 : _j.call(_h);
1603
1608
  this.logger.debug('Broadcast stopped callback triggered');
1604
1609
  break;
1605
1610
  }
@@ -1665,7 +1670,7 @@ class BroadcastService extends UnityBaseService {
1665
1670
  });
1666
1671
  // 触发开始回调
1667
1672
  (_b = (_a = this.callbacks).onStart) === null || _b === void 0 ? void 0 : _b.call(_a);
1668
- this.isGeneratingAudio = true;
1673
+ this.isBroadcastingAudio = true;
1669
1674
  }
1670
1675
  // 创建新的播报任务
1671
1676
  const task = this.createBroadcastTask(params);
@@ -1740,8 +1745,9 @@ class BroadcastService extends UnityBaseService {
1740
1745
  // 取消所有队列中的任务
1741
1746
  this.cancelAllTasks();
1742
1747
  // 重置状态
1743
- this.isGeneratingAudio = false;
1748
+ this.isBroadcastingAudio = false;
1744
1749
  this.hasReceivedAudio = false;
1750
+ this.broadcastCompletedCount = 0;
1745
1751
  try {
1746
1752
  yield this.sendAsyncMessage('StopBroadcast', BroadcastOperationType.STOP_BROADCAST, {});
1747
1753
  this.logger.info('Broadcast stopped successfully');
@@ -1767,19 +1773,23 @@ class BroadcastService extends UnityBaseService {
1767
1773
  * @description 获取当前播报服务的状态信息,包括队列状态
1768
1774
  */
1769
1775
  getStatus() {
1776
+ const completedTasks = this.taskQueue.filter((t) => t.status === BroadcastTaskStatus.COMPLETED).length;
1777
+ const requestingTasks = this.taskQueue.filter((t) => t.status === BroadcastTaskStatus.REQUESTING).length;
1778
+ const failedTasks = this.taskQueue.filter((t) => t.status === BroadcastTaskStatus.FAILED).length;
1779
+ const totalPendingResponses = this.taskQueue.reduce((sum, t) => sum + t.pendingResponses.length, 0);
1780
+ const currentSendingSequence = this.currentSendingSequence;
1781
+ const isGeneratingAudio = completedTasks + failedTasks !== this.taskQueue.length;
1770
1782
  return {
1771
- isActive: this.taskQueue.length > 0 || this.isGeneratingAudio,
1772
- isGeneratingAudio: this.isGeneratingAudio,
1783
+ isActive: this.isBroadcastingAudio || isGeneratingAudio, // 是否正在播报音频或正在生成音频
1784
+ isGeneratingAudio,
1773
1785
  hasReceivedAudio: this.hasReceivedAudio,
1774
- pendingCallbacks: this.getPendingCallbackCount(),
1775
- hasController: this.activeController !== null,
1776
1786
  queueInfo: {
1777
1787
  totalTasks: this.taskQueue.length,
1778
- requestingTasks: this.taskQueue.filter((t) => t.status === BroadcastTaskStatus.REQUESTING).length,
1779
- completedTasks: this.taskQueue.filter((t) => t.status === BroadcastTaskStatus.COMPLETED).length,
1780
- failedTasks: this.taskQueue.filter((t) => t.status === BroadcastTaskStatus.FAILED).length,
1781
- totalPendingResponses: this.taskQueue.reduce((sum, t) => sum + t.pendingResponses.length, 0),
1782
- currentSendingSequence: this.currentSendingSequence
1788
+ requestingTasks,
1789
+ completedTasks,
1790
+ failedTasks,
1791
+ totalPendingResponses,
1792
+ currentSendingSequence
1783
1793
  }
1784
1794
  };
1785
1795
  }
@@ -1789,10 +1799,7 @@ class BroadcastService extends UnityBaseService {
1789
1799
  */
1790
1800
  destroy() {
1791
1801
  // 清理队列处理定时器
1792
- if (this.queueProcessTimer) {
1793
- clearInterval(this.queueProcessTimer);
1794
- this.queueProcessTimer = null;
1795
- }
1802
+ this.clearQueueProcessTimer();
1796
1803
  // 取消所有任务
1797
1804
  this.cancelAllTasks();
1798
1805
  // 调用基类销毁方法
@@ -1861,12 +1868,12 @@ class BroadcastService extends UnityBaseService {
1861
1868
  if (nextTask) {
1862
1869
  this.sendNextResponse(nextTask);
1863
1870
  }
1864
- // 清理已完成的任务
1865
- this.cleanupCompletedTasks();
1866
- // 如果队列为空,停止定时器
1867
- if (this.taskQueue.length === 0 && this.queueProcessTimer) {
1868
- clearInterval(this.queueProcessTimer);
1869
- this.queueProcessTimer = null;
1871
+ // 如果队列中没有剩余任务,则停止定时器
1872
+ const remainingTasks = this.taskQueue.filter(task => task.status !== BroadcastTaskStatus.COMPLETED
1873
+ && task.status !== BroadcastTaskStatus.FAILED
1874
+ && task.status !== BroadcastTaskStatus.CANCELLED);
1875
+ if (remainingTasks.length === 0) {
1876
+ this.clearQueueProcessTimer();
1870
1877
  }
1871
1878
  }
1872
1879
  /**
@@ -1877,6 +1884,7 @@ class BroadcastService extends UnityBaseService {
1877
1884
  */
1878
1885
  startTaskRequest(task) {
1879
1886
  return __awaiter(this, void 0, void 0, function* () {
1887
+ var _a;
1880
1888
  task.status = BroadcastTaskStatus.REQUESTING;
1881
1889
  this.logger.debug('Starting task request', { taskId: task.id });
1882
1890
  try {
@@ -1885,7 +1893,8 @@ class BroadcastService extends UnityBaseService {
1885
1893
  humanCode: task.params.humanCode,
1886
1894
  speed: task.params.speed,
1887
1895
  volume: task.params.volume >= 0 ? task.params.volume * 100 : undefined,
1888
- isSubtitle: task.params.isSubtitle
1896
+ isSubtitle: task.params.isSubtitle,
1897
+ audioDrivenVersion: ConfigManager.getInstance().getConfig().audioDrivenVersion
1889
1898
  };
1890
1899
  // 根据播报类型设置特定参数
1891
1900
  if (task.params.type === BroadcastType.TEXT) {
@@ -1901,7 +1910,7 @@ class BroadcastService extends UnityBaseService {
1901
1910
  method: 'POST',
1902
1911
  headers: {
1903
1912
  'Content-Type': 'application/json',
1904
- 'x_auth_token': ConfigManager.getInstance().getToken()
1913
+ 'x_auth_token': ((_a = ConfigManager.getInstance().getConfig()) === null || _a === void 0 ? void 0 : _a.token) || ''
1905
1914
  },
1906
1915
  body: JSON.stringify(requestBody),
1907
1916
  signal: task.controller.signal,
@@ -1940,6 +1949,7 @@ class BroadcastService extends UnityBaseService {
1940
1949
  }
1941
1950
  // 处理音频数据
1942
1951
  if (response.data) {
1952
+ this.hasReceivedAudio = true;
1943
1953
  // 自定义音频播报时,如果服务器未返回音频URL,使用传入的audioUrl
1944
1954
  if (task.params.type === BroadcastType.AUDIO && task.params.audioUrl && !response.data.voiceUrl) {
1945
1955
  response.data.voiceUrl = task.params.audioUrl;
@@ -2062,7 +2072,6 @@ class BroadcastService extends UnityBaseService {
2062
2072
  * @private
2063
2073
  */
2064
2074
  getBroadcastApiPath(type) {
2065
- ConfigManager.getInstance().getEnv();
2066
2075
  switch (type) {
2067
2076
  case BroadcastType.TEXT:
2068
2077
  return '/aiep-openapi/avatar-interaction/v1/broadcast/text';
@@ -2100,11 +2109,6 @@ class BroadcastService extends UnityBaseService {
2100
2109
  handleError(error) {
2101
2110
  var _a, _b;
2102
2111
  this.logger.error('Broadcast error occurred', error);
2103
- // 清理控制器
2104
- if (this.activeController) {
2105
- this.activeController.abort();
2106
- this.activeController = null;
2107
- }
2108
2112
  // 触发错误回调
2109
2113
  (_b = (_a = this.callbacks).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
2110
2114
  }
@@ -2133,6 +2137,17 @@ class BroadcastService extends UnityBaseService {
2133
2137
  break;
2134
2138
  }
2135
2139
  }
2140
+ /**
2141
+ * 清理队列处理定时器
2142
+ * @description 清理队列处理定时器
2143
+ * @private
2144
+ */
2145
+ clearQueueProcessTimer() {
2146
+ if (this.queueProcessTimer) {
2147
+ clearInterval(this.queueProcessTimer);
2148
+ this.queueProcessTimer = null;
2149
+ }
2150
+ }
2136
2151
  }
2137
2152
 
2138
2153
  /**
@@ -2150,13 +2165,11 @@ class ZEEAvatarLoader {
2150
2165
  * @param config - Unity配置对象
2151
2166
  * @description 初始化数字人加载器,创建Unity加载器实例
2152
2167
  */
2153
- constructor(config) {
2168
+ constructor() {
2154
2169
  /** Avatar API实例 */
2155
2170
  this.apiService = null;
2156
2171
  /** Unity实例 */
2157
2172
  this.unityInstance = null;
2158
- // 同时设置到配置管理器中
2159
- ConfigManager.getInstance().setConfig(config);
2160
2173
  this.loader = new UnityLoader();
2161
2174
  }
2162
2175
  /**
@@ -2259,17 +2272,61 @@ class ZEEAvatarLoader {
2259
2272
  * @protected
2260
2273
  */
2261
2274
  initGlobalConfig() {
2262
- const params = {
2263
- token: ConfigManager.getInstance().getToken(),
2275
+ const config = ConfigManager.getInstance().getConfig();
2276
+ const globalParams = {
2277
+ token: config === null || config === void 0 ? void 0 : config.token,
2264
2278
  apiBaseUrl: ConfigManager.getInstance().getApiBaseUrl(false),
2265
- idleMotionList: ConfigManager.getInstance().getConfig().idleMotionList,
2266
- assetsUrl: ConfigManager.getInstance().getConfig().assetsUrl
2279
+ idleMotionList: config === null || config === void 0 ? void 0 : config.idleMotionList
2280
+ // 純AB包方案在SDK 2.1.0 中已弃用
2281
+ // assetsUrl: config?.assetsUrl
2282
+ };
2283
+ const assetModuleParams = {
2284
+ isZip: true,
2285
+ assetBundlePath: config === null || config === void 0 ? void 0 : config.assetsUrl
2267
2286
  };
2268
- console.warn('[ Send Unity message ]: AvatarSDK.InitializeConfig', params);
2269
- this.unityInstance.SendMessage('AvatarSDK', 'InitializeConfig', JSON.stringify(params));
2287
+ this.unityInstance.SendMessage('AvatarSDK', 'InitializeConfig', JSON.stringify(globalParams));
2288
+ this.unityInstance.SendMessage('AvatarSDK', 'InitAssetBundleModule', JSON.stringify(assetModuleParams));
2289
+ console.warn('[ Send Unity message ]: AvatarSDK.InitializeConfig', globalParams);
2290
+ console.warn('[ Send Unity message ]: AvatarSDK.InitAssetBundleModule', assetModuleParams);
2270
2291
  }
2271
2292
  }
2272
2293
 
2294
+ // 深拷贝
2295
+ /**
2296
+ * 比较两个版本号的前两位(major.minor)是否一致
2297
+ * @param version1 版本号1,格式:x.x.x
2298
+ * @param version2 版本号2,格式:x.x.x
2299
+ * @returns boolean 如果前两位一致返回 true,否则返回 false
2300
+ * @description 用于检查 SDK 版本与资源版本是否兼容
2301
+ * @example
2302
+ * compareVersionCompatibility('2.1.0', '2.1.5') // true
2303
+ * compareVersionCompatibility('2.1.0', '2.2.0') // false
2304
+ * compareVersionCompatibility('2.1.0', '3.0.0') // false
2305
+ */
2306
+ function compareVersionCompatibility(version1, version2) {
2307
+ // 提取版本号的前两位(major.minor)
2308
+ const getMajorMinor = (version) => {
2309
+ const parts = version.split('.');
2310
+ if (parts.length < 2) {
2311
+ return version;
2312
+ }
2313
+ return `${parts[0]}.${parts[1]}`;
2314
+ };
2315
+ const v1MajorMinor = getMajorMinor(version1);
2316
+ const v2MajorMinor = getMajorMinor(version2);
2317
+ return v1MajorMinor === v2MajorMinor;
2318
+ }
2319
+
2320
+ /**
2321
+ * @fileoverview SDK 版本号常量
2322
+ * @description 此文件由构建脚本自动生成,请勿手动修改
2323
+ */
2324
+ /**
2325
+ * SDK 版本号
2326
+ * @const {string} SDK_VERSION
2327
+ */
2328
+ const SDK_VERSION = '2.1.1';
2329
+
2273
2330
  /**
2274
2331
  * @fileoverview 统一的3D数字人SDK入口类
2275
2332
  * @description 提供统一的SDK接口,内部通过组合模式调用各个服务模块
@@ -2302,10 +2359,12 @@ class ZEEAvatarSDK {
2302
2359
  this.unityInstance = null;
2303
2360
  /** SDK初始化状态 */
2304
2361
  this.isInitialized = false;
2305
- this.config = config;
2306
2362
  this.instanceId = generateUniqueId();
2307
2363
  // 设置全局配置
2308
2364
  ConfigManager.getInstance().setConfig(config);
2365
+ // 设置日志
2366
+ this.logger = new SimpleLogger(ConfigManager.getInstance().getConfig().enableDebugLog);
2367
+ this.logger.info('SDK版本', SDK_VERSION);
2309
2368
  }
2310
2369
  /**
2311
2370
  * 初始化数字人
@@ -2316,12 +2375,14 @@ class ZEEAvatarSDK {
2316
2375
  */
2317
2376
  initializeAvatar(avatarCode_1) {
2318
2377
  return __awaiter(this, arguments, void 0, function* (avatarCode, cameraType = AvatarCameraType.WHOLE) {
2378
+ var _a;
2319
2379
  if (this.isInitialized) {
2320
2380
  throw new SDKError(OperationErrorCode.OPERATION_FAILED, 'SDK已经初始化,请勿重复初始化');
2321
2381
  }
2322
2382
  try {
2383
+ const config = ConfigManager.getInstance().getConfig();
2323
2384
  // 1. 创建Unity加载器
2324
- this.loader = new ZEEAvatarLoader(this.config);
2385
+ this.loader = new ZEEAvatarLoader();
2325
2386
  // 2. 初始化Unity实例
2326
2387
  yield this.loader.init();
2327
2388
  // 3. 获取Unity实例
@@ -2330,18 +2391,31 @@ class ZEEAvatarSDK {
2330
2391
  this.avatarService = new AvatarService({
2331
2392
  unityInstance: this.unityInstance,
2332
2393
  instanceId: this.instanceId,
2333
- enableDebugLog: this.config.enableDebugLog
2394
+ enableDebugLog: config.enableDebugLog
2334
2395
  });
2335
2396
  // 5. 创建带有唯一标识符的播报服务
2336
2397
  this.broadcastService = new BroadcastService({
2337
2398
  unityInstance: this.unityInstance,
2338
2399
  instanceId: this.instanceId,
2339
- callbacks: this.config.broadcastCallbacks,
2340
- enableDebugLog: this.config.enableDebugLog
2400
+ callbacks: config.broadcastCallbacks,
2401
+ enableDebugLog: config.enableDebugLog
2341
2402
  });
2342
2403
  // 6. 初始化数字人
2343
2404
  const result = yield this.avatarService.initializeAvatar(avatarCode, cameraType);
2344
2405
  if (result.success) {
2406
+ const audioDrivenVersion = (_a = result.data) === null || _a === void 0 ? void 0 : _a.audioDrivenVersion;
2407
+ config.audioDrivenVersion = audioDrivenVersion;
2408
+ this.logger.info('AudioDrivenVersion', audioDrivenVersion);
2409
+ // 7. 检查资源版本兼容性
2410
+ if (audioDrivenVersion) {
2411
+ const isCompatible = compareVersionCompatibility(SDK_VERSION, audioDrivenVersion);
2412
+ if (!isCompatible) {
2413
+ // 销毁SDK实例
2414
+ this.destroy();
2415
+ throw new SDKError(ResourceErrorCode.VERSION_INCOMPATIBLE, `资源版本不兼容: SDK版本为 ${SDK_VERSION},WebGL资源版本为 ${audioDrivenVersion},前两位版本号必须一致`);
2416
+ }
2417
+ this.logger.info('版本兼容性检查通过', `SDK: ${SDK_VERSION}, 资源: ${audioDrivenVersion}`);
2418
+ }
2345
2419
  this.isInitialized = true;
2346
2420
  }
2347
2421
  return result;
@@ -2357,8 +2431,7 @@ class ZEEAvatarSDK {
2357
2431
  * @description 更新全局Token配置
2358
2432
  */
2359
2433
  updateToken(token) {
2360
- this.config.token = token;
2361
- ConfigManager.getInstance().setConfig(this.config);
2434
+ ConfigManager.getInstance().updateConfig({ token });
2362
2435
  // 如果loader已经初始化,也更新loader的token
2363
2436
  if (this.loader) {
2364
2437
  this.loader.updateToken(token);
@@ -2542,7 +2615,8 @@ class ZEEAvatarSDK {
2542
2615
  * @returns IAvatarSDKConfig 当前配置
2543
2616
  */
2544
2617
  getConfig() {
2545
- return Object.assign({}, this.config);
2618
+ const config = ConfigManager.getInstance().getConfig();
2619
+ return config ? Object.assign({}, config) : null;
2546
2620
  }
2547
2621
  // ===========================================
2548
2622
  // 私有方法
@@ -2558,4 +2632,4 @@ class ZEEAvatarSDK {
2558
2632
  }
2559
2633
  }
2560
2634
 
2561
- export { AvatarCameraType, AvatarOperationType, AvatarService, BroadcastOperationType, BroadcastService, BroadcastType, ConfigErrorCode, ERROR_CODE_MAP, ErrorCategory, LogLevel, NetworkErrorCode, OperationErrorCode, ResourceErrorCode, SDKError, SystemErrorCode, UnityOperationStatus, ZEEAvatarLoader, ZEEAvatarSDK, getErrorInfo };
2635
+ export { AvatarCameraType, AvatarOperationType, AvatarService, BroadcastOperationType, BroadcastService, BroadcastType, ConfigErrorCode, ERROR_CODE_MAP, ErrorCategory, NetworkErrorCode, OperationErrorCode, ResourceErrorCode, SDKError, SDK_VERSION, SystemErrorCode, UnityOperationStatus, ZEEAvatarLoader, ZEEAvatarSDK, getErrorInfo };