@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.
@@ -12194,6 +12194,8 @@
12194
12194
  ResourceErrorCode[ResourceErrorCode["NOT_FOUND"] = 3003] = "NOT_FOUND";
12195
12195
  /** 资源格式不支持 */
12196
12196
  ResourceErrorCode[ResourceErrorCode["UNSUPPORTED_FORMAT"] = 3004] = "UNSUPPORTED_FORMAT";
12197
+ /** 资源版本不兼容 */
12198
+ ResourceErrorCode[ResourceErrorCode["VERSION_INCOMPATIBLE"] = 3005] = "VERSION_INCOMPATIBLE";
12197
12199
  })(exports.ResourceErrorCode || (exports.ResourceErrorCode = {}));
12198
12200
  /**
12199
12201
  * 系统错误码 (4xxx)
@@ -12286,6 +12288,9 @@
12286
12288
  }, _a[exports.ResourceErrorCode.UNSUPPORTED_FORMAT] = {
12287
12289
  category: exports.ErrorCategory.RESOURCE,
12288
12290
  message: '资源格式不支持'
12291
+ }, _a[exports.ResourceErrorCode.VERSION_INCOMPATIBLE] = {
12292
+ category: exports.ErrorCategory.RESOURCE,
12293
+ message: '资源版本不兼容'
12289
12294
  },
12290
12295
  // 系统错误
12291
12296
  _a[exports.SystemErrorCode.OUT_OF_MEMORY] = {
@@ -12471,6 +12476,48 @@
12471
12476
  return SDKError;
12472
12477
  }(Error);
12473
12478
 
12479
+ /**
12480
+ * Unity服务日志级别枚举
12481
+ * @enum {string}
12482
+ * @description 定义日志记录的级别
12483
+ */
12484
+ var LogLevel;
12485
+ (function (LogLevel) {
12486
+ LogLevel["DEBUG"] = "debug";
12487
+ LogLevel["INFO"] = "info";
12488
+ LogLevel["WARN"] = "warn";
12489
+ LogLevel["ERROR"] = "error";
12490
+ })(LogLevel || (LogLevel = {}));
12491
+ /**
12492
+ * 简单日志记录器实现
12493
+ * @class SimpleLogger
12494
+ * @implements {ISimpleLogger}
12495
+ * @description 提供基础的日志记录功能
12496
+ */
12497
+ var SimpleLogger = /** @class */function () {
12498
+ function SimpleLogger(enableDebug) {
12499
+ if (enableDebug === void 0) {
12500
+ enableDebug = false;
12501
+ }
12502
+ this.enableDebug = enableDebug;
12503
+ }
12504
+ SimpleLogger.prototype.debug = function (message, data) {
12505
+ if (this.enableDebug) {
12506
+ console.debug("[SDK DEBUG] ".concat(message), data);
12507
+ }
12508
+ };
12509
+ SimpleLogger.prototype.info = function (message, data) {
12510
+ console.info("[SDK INFO] ".concat(message), data);
12511
+ };
12512
+ SimpleLogger.prototype.warn = function (message, data) {
12513
+ console.warn("[SDK WARN] ".concat(message), data);
12514
+ };
12515
+ SimpleLogger.prototype.error = function (message, error, data) {
12516
+ console.error("[SDK ERROR] ".concat(message), error, error instanceof SDKError ? error.code : null, data);
12517
+ };
12518
+ return SimpleLogger;
12519
+ }();
12520
+
12474
12521
  /**
12475
12522
  * @fileoverview Unity服务基础类型定义
12476
12523
  * @description 定义Unity服务的通用接口和类型,为所有Unity服务提供统一的基础类型
@@ -12491,18 +12538,6 @@
12491
12538
  /** 操作取消 */
12492
12539
  UnityOperationStatus[UnityOperationStatus["CANCELLED"] = 3] = "CANCELLED";
12493
12540
  })(exports.UnityOperationStatus || (exports.UnityOperationStatus = {}));
12494
- /**
12495
- * Unity服务日志级别枚举
12496
- * @enum {string}
12497
- * @description 定义日志记录的级别
12498
- */
12499
- exports.LogLevel = void 0;
12500
- (function (LogLevel) {
12501
- LogLevel["DEBUG"] = "debug";
12502
- LogLevel["INFO"] = "info";
12503
- LogLevel["WARN"] = "warn";
12504
- LogLevel["ERROR"] = "error";
12505
- })(exports.LogLevel || (exports.LogLevel = {}));
12506
12541
 
12507
12542
  /**
12508
12543
  * 默认Unity服务配置
@@ -12844,35 +12879,6 @@
12844
12879
  };
12845
12880
  return UnityBaseService;
12846
12881
  }();
12847
- /**
12848
- * 简单日志记录器实现
12849
- * @class SimpleLogger
12850
- * @implements {IUnityLogger}
12851
- * @description 提供基础的日志记录功能
12852
- */
12853
- var SimpleLogger = /** @class */function () {
12854
- function SimpleLogger(enableDebug) {
12855
- if (enableDebug === void 0) {
12856
- enableDebug = false;
12857
- }
12858
- this.enableDebug = enableDebug;
12859
- }
12860
- SimpleLogger.prototype.debug = function (message, data) {
12861
- if (this.enableDebug) {
12862
- console.debug("[Unity Debug] ".concat(message), data);
12863
- }
12864
- };
12865
- SimpleLogger.prototype.info = function (message, data) {
12866
- console.info("[Unity Info] ".concat(message), data);
12867
- };
12868
- SimpleLogger.prototype.warn = function (message, data) {
12869
- console.warn("[Unity Warning] ".concat(message), data);
12870
- };
12871
- SimpleLogger.prototype.error = function (message, error, data) {
12872
- console.error("[Unity Error] ".concat(message), error, error instanceof SDKError ? error.code : null, data);
12873
- };
12874
- return SimpleLogger;
12875
- }();
12876
12882
 
12877
12883
  /**
12878
12884
  * @fileoverview Avatar API接口定义
@@ -12987,6 +12993,9 @@
12987
12993
  });
12988
12994
  });
12989
12995
  };
12996
+ AvatarService.prototype.handleCallback = function (operation, code, message, data) {
12997
+ _super.prototype.handleCallback.call(this, operation, code, message, data);
12998
+ };
12990
12999
  /**
12991
13000
  * 播放数字人动作
12992
13001
  * @param clipCode - 动作编码
@@ -13316,6 +13325,16 @@
13316
13325
  containerId: config.containerId || 'unity-container'
13317
13326
  });
13318
13327
  };
13328
+ /**
13329
+ * 更新SDK配置
13330
+ * @param config - SDK配置对象
13331
+ * @description 更新全局SDK配置
13332
+ */
13333
+ ConfigManager.prototype.updateConfig = function (config) {
13334
+ if (this.config) {
13335
+ this.config = __assign(__assign({}, this.config), config);
13336
+ }
13337
+ };
13319
13338
  /**
13320
13339
  * 获取SDK配置
13321
13340
  * @returns IAvatarSDKConfig | null SDK配置对象或null
@@ -13324,24 +13343,6 @@
13324
13343
  ConfigManager.prototype.getConfig = function () {
13325
13344
  return this.config;
13326
13345
  };
13327
- /**
13328
- * 获取认证token
13329
- * @returns string 认证token
13330
- * @description 获取当前配置的认证token
13331
- */
13332
- ConfigManager.prototype.getToken = function () {
13333
- var _a;
13334
- return ((_a = this.config) === null || _a === void 0 ? void 0 : _a.token) || '';
13335
- };
13336
- /**
13337
- * 获取环境类型
13338
- * @returns string 环境类型
13339
- * @description 获取当前配置的环境类型
13340
- */
13341
- ConfigManager.prototype.getEnv = function () {
13342
- var _a;
13343
- return ((_a = this.config) === null || _a === void 0 ? void 0 : _a.env) || 'prod';
13344
- };
13345
13346
  /**
13346
13347
  * 获取API基础URL
13347
13348
  * @param withApiModule 是否包含模块路径
@@ -13359,15 +13360,6 @@
13359
13360
  }
13360
13361
  return ((_d = getEnvConfig(((_c = this.config) === null || _c === void 0 ? void 0 : _c.env) || 'prod', withApiModule)) === null || _d === void 0 ? void 0 : _d.apiBaseUrl) || '';
13361
13362
  };
13362
- /**
13363
- * 获取自定义API URL
13364
- * @returns string | undefined 自定义API URL
13365
- * @description 获取自定义API URL配置
13366
- */
13367
- ConfigManager.prototype.getCustomApiUrl = function () {
13368
- var _a;
13369
- return (_a = this.config) === null || _a === void 0 ? void 0 : _a.apiUrl;
13370
- };
13371
13363
  /**
13372
13364
  * 重置配置
13373
13365
  * @description 清空当前配置
@@ -13819,14 +13811,14 @@
13819
13811
  _this.taskSequence = 0;
13820
13812
  /** 当前发送任务的序号 */
13821
13813
  _this.currentSendingSequence = 0;
13822
- /** 是否正在生成音频 */
13823
- _this.isGeneratingAudio = false;
13814
+ /** 是否正在播报音频 */
13815
+ _this.isBroadcastingAudio = false;
13824
13816
  /** 是否已经收到音频 */
13825
13817
  _this.hasReceivedAudio = false;
13826
13818
  /** 队列处理定时器 */
13827
13819
  _this.queueProcessTimer = null;
13828
- /** 主请求控制器(兼容性保留) */
13829
- _this.activeController = null;
13820
+ /** 播报完成次数 */
13821
+ _this.broadcastCompletedCount = 0;
13830
13822
  _this.callbacks = config.callbacks || {};
13831
13823
  _this.logger.info('Broadcast service initialized', {
13832
13824
  config: config
@@ -13843,7 +13835,7 @@
13843
13835
  * @override
13844
13836
  */
13845
13837
  BroadcastService.prototype.handleCallback = function (operation, code, message, data) {
13846
- var _a, _b, _c, _d, _e, _f, _g, _h;
13838
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
13847
13839
  // 提取 isBroadcastCompleted 参数
13848
13840
  var isBroadcastCompleted = JSON.parse(data || '{}').isBroadcastCompleted;
13849
13841
  // 先调用基类处理逻辑
@@ -13853,19 +13845,31 @@
13853
13845
  switch (operation) {
13854
13846
  case exports.BroadcastOperationType.START_BROADCAST:
13855
13847
  if (isBroadcastCompleted) {
13856
- (_b = (_a = this.callbacks).onFinish) === null || _b === void 0 ? void 0 : _b.call(_a);
13848
+ this.broadcastCompletedCount++;
13849
+ var status_1 = this.getStatus();
13850
+ if (((_a = status_1.queueInfo) === null || _a === void 0 ? void 0 : _a.completedTasks) === this.broadcastCompletedCount) {
13851
+ // 重置状态、计数
13852
+ this.isBroadcastingAudio = false;
13853
+ this.hasReceivedAudio = false;
13854
+ this.currentSendingSequence = 0;
13855
+ // 清理已完成的任务
13856
+ this.cleanupCompletedTasks();
13857
+ this.logger.warn('Broadcast all completed');
13858
+ }
13859
+ // this.logger.warn('AAAAAA', { status: this.getStatus(), broadcastCompletedCount: this.broadcastCompletedCount });
13860
+ (_c = (_b = this.callbacks).onFinish) === null || _c === void 0 ? void 0 : _c.call(_b);
13857
13861
  }
13858
13862
  break;
13859
13863
  case exports.BroadcastOperationType.PAUSE_BROADCAST:
13860
- (_d = (_c = this.callbacks).onPause) === null || _d === void 0 ? void 0 : _d.call(_c);
13864
+ (_e = (_d = this.callbacks).onPause) === null || _e === void 0 ? void 0 : _e.call(_d);
13861
13865
  this.logger.debug('Broadcast paused callback triggered');
13862
13866
  break;
13863
13867
  case exports.BroadcastOperationType.RESUME_BROADCAST:
13864
- (_f = (_e = this.callbacks).onResume) === null || _f === void 0 ? void 0 : _f.call(_e);
13868
+ (_g = (_f = this.callbacks).onResume) === null || _g === void 0 ? void 0 : _g.call(_f);
13865
13869
  this.logger.debug('Broadcast resumed callback triggered');
13866
13870
  break;
13867
13871
  case exports.BroadcastOperationType.STOP_BROADCAST:
13868
- (_h = (_g = this.callbacks).onStop) === null || _h === void 0 ? void 0 : _h.call(_g);
13872
+ (_j = (_h = this.callbacks).onStop) === null || _j === void 0 ? void 0 : _j.call(_h);
13869
13873
  this.logger.debug('Broadcast stopped callback triggered');
13870
13874
  break;
13871
13875
  }
@@ -13936,7 +13940,7 @@
13936
13940
  });
13937
13941
  // 触发开始回调
13938
13942
  (_b = (_a = this.callbacks).onStart) === null || _b === void 0 ? void 0 : _b.call(_a);
13939
- this.isGeneratingAudio = true;
13943
+ this.isBroadcastingAudio = true;
13940
13944
  _c.label = 2;
13941
13945
  case 2:
13942
13946
  task = this.createBroadcastTask(params);
@@ -14044,8 +14048,9 @@
14044
14048
  // 取消所有队列中的任务
14045
14049
  this.cancelAllTasks();
14046
14050
  // 重置状态
14047
- this.isGeneratingAudio = false;
14051
+ this.isBroadcastingAudio = false;
14048
14052
  this.hasReceivedAudio = false;
14053
+ this.broadcastCompletedCount = 0;
14049
14054
  _a.label = 1;
14050
14055
  case 1:
14051
14056
  _a.trys.push([1, 3,, 4]);
@@ -14079,27 +14084,32 @@
14079
14084
  * @description 获取当前播报服务的状态信息,包括队列状态
14080
14085
  */
14081
14086
  BroadcastService.prototype.getStatus = function () {
14087
+ var completedTasks = this.taskQueue.filter(function (t) {
14088
+ return t.status === BroadcastTaskStatus.COMPLETED;
14089
+ }).length;
14090
+ var requestingTasks = this.taskQueue.filter(function (t) {
14091
+ return t.status === BroadcastTaskStatus.REQUESTING;
14092
+ }).length;
14093
+ var failedTasks = this.taskQueue.filter(function (t) {
14094
+ return t.status === BroadcastTaskStatus.FAILED;
14095
+ }).length;
14096
+ var totalPendingResponses = this.taskQueue.reduce(function (sum, t) {
14097
+ return sum + t.pendingResponses.length;
14098
+ }, 0);
14099
+ var currentSendingSequence = this.currentSendingSequence;
14100
+ var isGeneratingAudio = completedTasks + failedTasks !== this.taskQueue.length;
14082
14101
  return {
14083
- isActive: this.taskQueue.length > 0 || this.isGeneratingAudio,
14084
- isGeneratingAudio: this.isGeneratingAudio,
14102
+ isActive: this.isBroadcastingAudio || isGeneratingAudio,
14103
+ // 是否正在播报音频或正在生成音频
14104
+ isGeneratingAudio: isGeneratingAudio,
14085
14105
  hasReceivedAudio: this.hasReceivedAudio,
14086
- pendingCallbacks: this.getPendingCallbackCount(),
14087
- hasController: this.activeController !== null,
14088
14106
  queueInfo: {
14089
14107
  totalTasks: this.taskQueue.length,
14090
- requestingTasks: this.taskQueue.filter(function (t) {
14091
- return t.status === BroadcastTaskStatus.REQUESTING;
14092
- }).length,
14093
- completedTasks: this.taskQueue.filter(function (t) {
14094
- return t.status === BroadcastTaskStatus.COMPLETED;
14095
- }).length,
14096
- failedTasks: this.taskQueue.filter(function (t) {
14097
- return t.status === BroadcastTaskStatus.FAILED;
14098
- }).length,
14099
- totalPendingResponses: this.taskQueue.reduce(function (sum, t) {
14100
- return sum + t.pendingResponses.length;
14101
- }, 0),
14102
- currentSendingSequence: this.currentSendingSequence
14108
+ requestingTasks: requestingTasks,
14109
+ completedTasks: completedTasks,
14110
+ failedTasks: failedTasks,
14111
+ totalPendingResponses: totalPendingResponses,
14112
+ currentSendingSequence: currentSendingSequence
14103
14113
  }
14104
14114
  };
14105
14115
  };
@@ -14109,10 +14119,7 @@
14109
14119
  */
14110
14120
  BroadcastService.prototype.destroy = function () {
14111
14121
  // 清理队列处理定时器
14112
- if (this.queueProcessTimer) {
14113
- clearInterval(this.queueProcessTimer);
14114
- this.queueProcessTimer = null;
14115
- }
14122
+ this.clearQueueProcessTimer();
14116
14123
  // 取消所有任务
14117
14124
  this.cancelAllTasks();
14118
14125
  // 调用基类销毁方法
@@ -14190,12 +14197,12 @@
14190
14197
  if (nextTask) {
14191
14198
  this.sendNextResponse(nextTask);
14192
14199
  }
14193
- // 清理已完成的任务
14194
- this.cleanupCompletedTasks();
14195
- // 如果队列为空,停止定时器
14196
- if (this.taskQueue.length === 0 && this.queueProcessTimer) {
14197
- clearInterval(this.queueProcessTimer);
14198
- this.queueProcessTimer = null;
14200
+ // 如果队列中没有剩余任务,则停止定时器
14201
+ var remainingTasks = this.taskQueue.filter(function (task) {
14202
+ return task.status !== BroadcastTaskStatus.COMPLETED && task.status !== BroadcastTaskStatus.FAILED && task.status !== BroadcastTaskStatus.CANCELLED;
14203
+ });
14204
+ if (remainingTasks.length === 0) {
14205
+ this.clearQueueProcessTimer();
14199
14206
  }
14200
14207
  };
14201
14208
  /**
@@ -14208,7 +14215,8 @@
14208
14215
  return __awaiter(this, void 0, void 0, function () {
14209
14216
  var apiUrl, requestBody;
14210
14217
  var _this = this;
14211
- return __generator(this, function (_a) {
14218
+ var _a;
14219
+ return __generator(this, function (_b) {
14212
14220
  task.status = BroadcastTaskStatus.REQUESTING;
14213
14221
  this.logger.debug('Starting task request', {
14214
14222
  taskId: task.id
@@ -14219,7 +14227,8 @@
14219
14227
  humanCode: task.params.humanCode,
14220
14228
  speed: task.params.speed,
14221
14229
  volume: task.params.volume >= 0 ? task.params.volume * 100 : undefined,
14222
- isSubtitle: task.params.isSubtitle
14230
+ isSubtitle: task.params.isSubtitle,
14231
+ audioDrivenVersion: ConfigManager.getInstance().getConfig().audioDrivenVersion
14223
14232
  };
14224
14233
  // 根据播报类型设置特定参数
14225
14234
  if (task.params.type === exports.BroadcastType.TEXT) {
@@ -14234,7 +14243,7 @@
14234
14243
  method: 'POST',
14235
14244
  headers: {
14236
14245
  'Content-Type': 'application/json',
14237
- 'x_auth_token': ConfigManager.getInstance().getToken()
14246
+ 'x_auth_token': ((_a = ConfigManager.getInstance().getConfig()) === null || _a === void 0 ? void 0 : _a.token) || ''
14238
14247
  },
14239
14248
  body: JSON.stringify(requestBody),
14240
14249
  signal: task.controller.signal,
@@ -14274,6 +14283,7 @@
14274
14283
  }
14275
14284
  // 处理音频数据
14276
14285
  if (response.data) {
14286
+ this.hasReceivedAudio = true;
14277
14287
  // 自定义音频播报时,如果服务器未返回音频URL,使用传入的audioUrl
14278
14288
  if (task.params.type === exports.BroadcastType.AUDIO && task.params.audioUrl && !response.data.voiceUrl) {
14279
14289
  response.data.voiceUrl = task.params.audioUrl;
@@ -14426,7 +14436,6 @@
14426
14436
  * @private
14427
14437
  */
14428
14438
  BroadcastService.prototype.getBroadcastApiPath = function (type) {
14429
- ConfigManager.getInstance().getEnv();
14430
14439
  switch (type) {
14431
14440
  case exports.BroadcastType.TEXT:
14432
14441
  return '/aiep-openapi/avatar-interaction/v1/broadcast/text';
@@ -14463,11 +14472,6 @@
14463
14472
  BroadcastService.prototype.handleError = function (error) {
14464
14473
  var _a, _b;
14465
14474
  this.logger.error('Broadcast error occurred', error);
14466
- // 清理控制器
14467
- if (this.activeController) {
14468
- this.activeController.abort();
14469
- this.activeController = null;
14470
- }
14471
14475
  // 触发错误回调
14472
14476
  (_b = (_a = this.callbacks).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
14473
14477
  };
@@ -14496,6 +14500,17 @@
14496
14500
  break;
14497
14501
  }
14498
14502
  };
14503
+ /**
14504
+ * 清理队列处理定时器
14505
+ * @description 清理队列处理定时器
14506
+ * @private
14507
+ */
14508
+ BroadcastService.prototype.clearQueueProcessTimer = function () {
14509
+ if (this.queueProcessTimer) {
14510
+ clearInterval(this.queueProcessTimer);
14511
+ this.queueProcessTimer = null;
14512
+ }
14513
+ };
14499
14514
  return BroadcastService;
14500
14515
  }(UnityBaseService);
14501
14516
 
@@ -14514,13 +14529,11 @@
14514
14529
  * @param config - Unity配置对象
14515
14530
  * @description 初始化数字人加载器,创建Unity加载器实例
14516
14531
  */
14517
- function ZEEAvatarLoader(config) {
14532
+ function ZEEAvatarLoader() {
14518
14533
  /** Avatar API实例 */
14519
14534
  this.apiService = null;
14520
14535
  /** Unity实例 */
14521
14536
  this.unityInstance = null;
14522
- // 同时设置到配置管理器中
14523
- ConfigManager.getInstance().setConfig(config);
14524
14537
  this.loader = new UnityLoader();
14525
14538
  }
14526
14539
  /**
@@ -14634,14 +14647,22 @@
14634
14647
  * @protected
14635
14648
  */
14636
14649
  ZEEAvatarLoader.prototype.initGlobalConfig = function () {
14637
- var params = {
14638
- token: ConfigManager.getInstance().getToken(),
14650
+ var config = ConfigManager.getInstance().getConfig();
14651
+ var globalParams = {
14652
+ token: config === null || config === void 0 ? void 0 : config.token,
14639
14653
  apiBaseUrl: ConfigManager.getInstance().getApiBaseUrl(false),
14640
- idleMotionList: ConfigManager.getInstance().getConfig().idleMotionList,
14641
- assetsUrl: ConfigManager.getInstance().getConfig().assetsUrl
14654
+ idleMotionList: config === null || config === void 0 ? void 0 : config.idleMotionList
14655
+ // 純AB包方案在SDK 2.1.0 中已弃用
14656
+ // assetsUrl: config?.assetsUrl
14657
+ };
14658
+ var assetModuleParams = {
14659
+ isZip: true,
14660
+ assetBundlePath: config === null || config === void 0 ? void 0 : config.assetsUrl
14642
14661
  };
14643
- console.warn('[ Send Unity message ]: AvatarSDK.InitializeConfig', params);
14644
- this.unityInstance.SendMessage('AvatarSDK', 'InitializeConfig', JSON.stringify(params));
14662
+ this.unityInstance.SendMessage('AvatarSDK', 'InitializeConfig', JSON.stringify(globalParams));
14663
+ this.unityInstance.SendMessage('AvatarSDK', 'InitAssetBundleModule', JSON.stringify(assetModuleParams));
14664
+ console.warn('[ Send Unity message ]: AvatarSDK.InitializeConfig', globalParams);
14665
+ console.warn('[ Send Unity message ]: AvatarSDK.InitAssetBundleModule', assetModuleParams);
14645
14666
  };
14646
14667
  return ZEEAvatarLoader;
14647
14668
  }();