@zeewain/3d-avatar-sdk 1.2.5 → 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 清空当前配置
@@ -1897,6 +1890,7 @@
1897
1890
  */
1898
1891
  startTaskRequest(task) {
1899
1892
  return __awaiter(this, void 0, void 0, function* () {
1893
+ var _a;
1900
1894
  task.status = BroadcastTaskStatus.REQUESTING;
1901
1895
  this.logger.debug('Starting task request', { taskId: task.id });
1902
1896
  try {
@@ -1905,7 +1899,8 @@
1905
1899
  humanCode: task.params.humanCode,
1906
1900
  speed: task.params.speed,
1907
1901
  volume: task.params.volume >= 0 ? task.params.volume * 100 : undefined,
1908
- isSubtitle: task.params.isSubtitle
1902
+ isSubtitle: task.params.isSubtitle,
1903
+ audioDrivenVersion: ConfigManager.getInstance().getConfig().audioDrivenVersion
1909
1904
  };
1910
1905
  // 根据播报类型设置特定参数
1911
1906
  if (task.params.type === exports.BroadcastType.TEXT) {
@@ -1921,7 +1916,7 @@
1921
1916
  method: 'POST',
1922
1917
  headers: {
1923
1918
  'Content-Type': 'application/json',
1924
- 'x_auth_token': ConfigManager.getInstance().getToken()
1919
+ 'x_auth_token': ((_a = ConfigManager.getInstance().getConfig()) === null || _a === void 0 ? void 0 : _a.token) || ''
1925
1920
  },
1926
1921
  body: JSON.stringify(requestBody),
1927
1922
  signal: task.controller.signal,
@@ -2083,7 +2078,6 @@
2083
2078
  * @private
2084
2079
  */
2085
2080
  getBroadcastApiPath(type) {
2086
- ConfigManager.getInstance().getEnv();
2087
2081
  switch (type) {
2088
2082
  case exports.BroadcastType.TEXT:
2089
2083
  return '/aiep-openapi/avatar-interaction/v1/broadcast/text';
@@ -2177,13 +2171,11 @@
2177
2171
  * @param config - Unity配置对象
2178
2172
  * @description 初始化数字人加载器,创建Unity加载器实例
2179
2173
  */
2180
- constructor(config) {
2174
+ constructor() {
2181
2175
  /** Avatar API实例 */
2182
2176
  this.apiService = null;
2183
2177
  /** Unity实例 */
2184
2178
  this.unityInstance = null;
2185
- // 同时设置到配置管理器中
2186
- ConfigManager.getInstance().setConfig(config);
2187
2179
  this.loader = new UnityLoader();
2188
2180
  }
2189
2181
  /**
@@ -2286,17 +2278,61 @@
2286
2278
  * @protected
2287
2279
  */
2288
2280
  initGlobalConfig() {
2289
- const params = {
2290
- token: ConfigManager.getInstance().getToken(),
2281
+ const config = ConfigManager.getInstance().getConfig();
2282
+ const globalParams = {
2283
+ token: config === null || config === void 0 ? void 0 : config.token,
2291
2284
  apiBaseUrl: ConfigManager.getInstance().getApiBaseUrl(false),
2292
- idleMotionList: ConfigManager.getInstance().getConfig().idleMotionList,
2293
- 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
2294
2288
  };
2295
- console.warn('[ Send Unity message ]: AvatarSDK.InitializeConfig', params);
2296
- 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);
2297
2297
  }
2298
2298
  }
2299
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
+
2300
2336
  /**
2301
2337
  * @fileoverview 统一的3D数字人SDK入口类
2302
2338
  * @description 提供统一的SDK接口,内部通过组合模式调用各个服务模块
@@ -2329,10 +2365,12 @@
2329
2365
  this.unityInstance = null;
2330
2366
  /** SDK初始化状态 */
2331
2367
  this.isInitialized = false;
2332
- this.config = config;
2333
2368
  this.instanceId = generateUniqueId();
2334
2369
  // 设置全局配置
2335
2370
  ConfigManager.getInstance().setConfig(config);
2371
+ // 设置日志
2372
+ this.logger = new SimpleLogger(ConfigManager.getInstance().getConfig().enableDebugLog);
2373
+ this.logger.info('SDK版本', SDK_VERSION);
2336
2374
  }
2337
2375
  /**
2338
2376
  * 初始化数字人
@@ -2343,12 +2381,14 @@
2343
2381
  */
2344
2382
  initializeAvatar(avatarCode_1) {
2345
2383
  return __awaiter(this, arguments, void 0, function* (avatarCode, cameraType = exports.AvatarCameraType.WHOLE) {
2384
+ var _a;
2346
2385
  if (this.isInitialized) {
2347
2386
  throw new SDKError(exports.OperationErrorCode.OPERATION_FAILED, 'SDK已经初始化,请勿重复初始化');
2348
2387
  }
2349
2388
  try {
2389
+ const config = ConfigManager.getInstance().getConfig();
2350
2390
  // 1. 创建Unity加载器
2351
- this.loader = new ZEEAvatarLoader(this.config);
2391
+ this.loader = new ZEEAvatarLoader();
2352
2392
  // 2. 初始化Unity实例
2353
2393
  yield this.loader.init();
2354
2394
  // 3. 获取Unity实例
@@ -2357,18 +2397,31 @@
2357
2397
  this.avatarService = new AvatarService({
2358
2398
  unityInstance: this.unityInstance,
2359
2399
  instanceId: this.instanceId,
2360
- enableDebugLog: this.config.enableDebugLog
2400
+ enableDebugLog: config.enableDebugLog
2361
2401
  });
2362
2402
  // 5. 创建带有唯一标识符的播报服务
2363
2403
  this.broadcastService = new BroadcastService({
2364
2404
  unityInstance: this.unityInstance,
2365
2405
  instanceId: this.instanceId,
2366
- callbacks: this.config.broadcastCallbacks,
2367
- enableDebugLog: this.config.enableDebugLog
2406
+ callbacks: config.broadcastCallbacks,
2407
+ enableDebugLog: config.enableDebugLog
2368
2408
  });
2369
2409
  // 6. 初始化数字人
2370
2410
  const result = yield this.avatarService.initializeAvatar(avatarCode, cameraType);
2371
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
+ }
2372
2425
  this.isInitialized = true;
2373
2426
  }
2374
2427
  return result;
@@ -2384,8 +2437,7 @@
2384
2437
  * @description 更新全局Token配置
2385
2438
  */
2386
2439
  updateToken(token) {
2387
- this.config.token = token;
2388
- ConfigManager.getInstance().setConfig(this.config);
2440
+ ConfigManager.getInstance().updateConfig({ token });
2389
2441
  // 如果loader已经初始化,也更新loader的token
2390
2442
  if (this.loader) {
2391
2443
  this.loader.updateToken(token);
@@ -2569,7 +2621,8 @@
2569
2621
  * @returns IAvatarSDKConfig 当前配置
2570
2622
  */
2571
2623
  getConfig() {
2572
- return Object.assign({}, this.config);
2624
+ const config = ConfigManager.getInstance().getConfig();
2625
+ return config ? Object.assign({}, config) : null;
2573
2626
  }
2574
2627
  // ===========================================
2575
2628
  // 私有方法
@@ -2589,6 +2642,7 @@
2589
2642
  exports.BroadcastService = BroadcastService;
2590
2643
  exports.ERROR_CODE_MAP = ERROR_CODE_MAP;
2591
2644
  exports.SDKError = SDKError;
2645
+ exports.SDK_VERSION = SDK_VERSION;
2592
2646
  exports.ZEEAvatarLoader = ZEEAvatarLoader;
2593
2647
  exports.ZEEAvatarSDK = ZEEAvatarSDK;
2594
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.5",
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
  }