@zeewain/3d-avatar-sdk 2.1.2 → 2.1.4

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.es5.js CHANGED
@@ -12565,7 +12565,7 @@ var ZEEAvatarSDKLib = (function (exports) {
12565
12565
  var finalConfig = __assign(__assign({}, DEFAULT_CONFIG), config);
12566
12566
  this.unityInstance = finalConfig.unityInstance;
12567
12567
  this.targetObjectName = finalConfig.targetObjectName;
12568
- this.timeout = finalConfig.timeout;
12568
+ this.timeout = finalConfig.timeout || DEFAULT_CONFIG.timeout;
12569
12569
  this.maxRetries = finalConfig.maxRetries;
12570
12570
  this.instanceId = finalConfig.instanceId || 'default';
12571
12571
  this.logger = new SimpleLogger(finalConfig.enableDebugLog);
@@ -13253,7 +13253,7 @@ var ZEEAvatarSDKLib = (function (exports) {
13253
13253
  },
13254
13254
  /** 生产环境配置 */
13255
13255
  prod: {
13256
- apiBaseUrl: 'https://aiip.zeewain.com'
13256
+ apiBaseUrl: 'https://ai.zeewain3d.com'
13257
13257
  }
13258
13258
  };
13259
13259
  /**
@@ -13264,7 +13264,7 @@ var ZEEAvatarSDKLib = (function (exports) {
13264
13264
  * @example
13265
13265
  * ```typescript
13266
13266
  * const config = getEnvConfig('prod');
13267
- * console.log(config.apiBaseUrl); // https://aiip.zeewain.com/api/dh-talker
13267
+ * console.log(config.apiBaseUrl); // https://ai.zeewain3d.com/api/dh-talker
13268
13268
  * ```
13269
13269
  */
13270
13270
  function getEnvConfig(env, withApiModule) {
@@ -13763,6 +13763,8 @@ var ZEEAvatarSDKLib = (function (exports) {
13763
13763
  */
13764
13764
  var BroadcastTaskStatus;
13765
13765
  (function (BroadcastTaskStatus) {
13766
+ /** 等待中(尚未开始请求) */
13767
+ BroadcastTaskStatus["PENDING"] = "pending";
13766
13768
  /** 请求中 */
13767
13769
  BroadcastTaskStatus["REQUESTING"] = "requesting";
13768
13770
  /** 已完成 */
@@ -13832,7 +13834,7 @@ var ZEEAvatarSDKLib = (function (exports) {
13832
13834
  * @override
13833
13835
  */
13834
13836
  BroadcastService.prototype.handleCallback = function (operation, code, message, data) {
13835
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
13837
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
13836
13838
  // 提取 isBroadcastCompleted 参数
13837
13839
  var isBroadcastCompleted = JSON.parse(data || '{}').isBroadcastCompleted;
13838
13840
  // 先调用基类处理逻辑
@@ -13844,7 +13846,12 @@ var ZEEAvatarSDKLib = (function (exports) {
13844
13846
  if (isBroadcastCompleted) {
13845
13847
  this.broadcastCompletedCount++;
13846
13848
  var status_1 = this.getStatus();
13847
- if (((_a = status_1.queueInfo) === null || _a === void 0 ? void 0 : _a.completedTasks) === this.broadcastCompletedCount) {
13849
+ // 判断是否所有任务都已完成:
13850
+ // 1. 没有待请求的任务 (PENDING)
13851
+ // 2. 没有正在请求的任务 (REQUESTING)
13852
+ // 3. Unity播放完成次数等于已完成任务数
13853
+ var isAllTasksCompleted = ((_a = status_1.queueInfo) === null || _a === void 0 ? void 0 : _a.pendingTasks) === 0 && ((_b = status_1.queueInfo) === null || _b === void 0 ? void 0 : _b.requestingTasks) === 0 && ((_c = status_1.queueInfo) === null || _c === void 0 ? void 0 : _c.completedTasks) === this.broadcastCompletedCount;
13854
+ if (isAllTasksCompleted) {
13848
13855
  // 重置状态、计数
13849
13856
  this.isBroadcastingAudio = false;
13850
13857
  this.hasReceivedAudio = false;
@@ -13854,19 +13861,19 @@ var ZEEAvatarSDKLib = (function (exports) {
13854
13861
  this.logger.warn('Broadcast all completed');
13855
13862
  }
13856
13863
  // this.logger.warn('AAAAAA', { status: this.getStatus(), broadcastCompletedCount: this.broadcastCompletedCount });
13857
- (_c = (_b = this.callbacks).onFinish) === null || _c === void 0 ? void 0 : _c.call(_b);
13864
+ (_e = (_d = this.callbacks).onFinish) === null || _e === void 0 ? void 0 : _e.call(_d);
13858
13865
  }
13859
13866
  break;
13860
13867
  case exports.BroadcastOperationType.PAUSE_BROADCAST:
13861
- (_e = (_d = this.callbacks).onPause) === null || _e === void 0 ? void 0 : _e.call(_d);
13868
+ (_g = (_f = this.callbacks).onPause) === null || _g === void 0 ? void 0 : _g.call(_f);
13862
13869
  this.logger.debug('Broadcast paused callback triggered');
13863
13870
  break;
13864
13871
  case exports.BroadcastOperationType.RESUME_BROADCAST:
13865
- (_g = (_f = this.callbacks).onResume) === null || _g === void 0 ? void 0 : _g.call(_f);
13872
+ (_j = (_h = this.callbacks).onResume) === null || _j === void 0 ? void 0 : _j.call(_h);
13866
13873
  this.logger.debug('Broadcast resumed callback triggered');
13867
13874
  break;
13868
13875
  case exports.BroadcastOperationType.STOP_BROADCAST:
13869
- (_j = (_h = this.callbacks).onStop) === null || _j === void 0 ? void 0 : _j.call(_h);
13876
+ (_l = (_k = this.callbacks).onStop) === null || _l === void 0 ? void 0 : _l.call(_k);
13870
13877
  this.logger.debug('Broadcast stopped callback triggered');
13871
13878
  break;
13872
13879
  }
@@ -13928,7 +13935,7 @@ var ZEEAvatarSDKLib = (function (exports) {
13928
13935
  // 重置序号计数器
13929
13936
  this.taskSequence = 0;
13930
13937
  this.currentSendingSequence = 0;
13931
- // 通知Unity开始新任务(清空队列)
13938
+ // 通知Unity开始新任务(清空队列),这里不使用sendAsyncMessage,因为startBroadcast不需要等待完成,而是在任务播报完成后通过回调通知
13932
13939
  this.sendMessage('StartBroadcast', {
13933
13940
  callbackFun: this.uniqueCallbackName,
13934
13941
  operationType: exports.BroadcastOperationType.START_BROADCAST,
@@ -14081,6 +14088,9 @@ var ZEEAvatarSDKLib = (function (exports) {
14081
14088
  * @description 获取当前播报服务的状态信息,包括队列状态
14082
14089
  */
14083
14090
  BroadcastService.prototype.getStatus = function () {
14091
+ var pendingTasks = this.taskQueue.filter(function (t) {
14092
+ return t.status === BroadcastTaskStatus.PENDING;
14093
+ }).length;
14084
14094
  var completedTasks = this.taskQueue.filter(function (t) {
14085
14095
  return t.status === BroadcastTaskStatus.COMPLETED;
14086
14096
  }).length;
@@ -14094,7 +14104,7 @@ var ZEEAvatarSDKLib = (function (exports) {
14094
14104
  return sum + t.pendingResponses.length;
14095
14105
  }, 0);
14096
14106
  var currentSendingSequence = this.currentSendingSequence;
14097
- var isGeneratingAudio = completedTasks + failedTasks !== this.taskQueue.length;
14107
+ var isGeneratingAudio = pendingTasks + requestingTasks > 0;
14098
14108
  return {
14099
14109
  isActive: this.isBroadcastingAudio || isGeneratingAudio,
14100
14110
  // 是否正在播报音频或正在生成音频
@@ -14102,6 +14112,7 @@ var ZEEAvatarSDKLib = (function (exports) {
14102
14112
  hasReceivedAudio: this.hasReceivedAudio,
14103
14113
  queueInfo: {
14104
14114
  totalTasks: this.taskQueue.length,
14115
+ pendingTasks: pendingTasks,
14105
14116
  requestingTasks: requestingTasks,
14106
14117
  completedTasks: completedTasks,
14107
14118
  failedTasks: failedTasks,
@@ -14135,7 +14146,7 @@ var ZEEAvatarSDKLib = (function (exports) {
14135
14146
  id: "broadcast_".concat(Date.now(), "_").concat(Math.random().toString(36).substring(2, 9)),
14136
14147
  sequence: ++this.taskSequence,
14137
14148
  params: params,
14138
- status: BroadcastTaskStatus.REQUESTING,
14149
+ status: BroadcastTaskStatus.PENDING,
14139
14150
  controller: new AbortController(),
14140
14151
  pendingResponses: [],
14141
14152
  isGenerationComplete: false,
@@ -14150,53 +14161,67 @@ var ZEEAvatarSDKLib = (function (exports) {
14150
14161
  /**
14151
14162
  * 添加任务到队列
14152
14163
  * @param task - 播报任务
14153
- * @description 将任务添加到队列并立即开始请求
14164
+ * @description 将任务添加到队列,只有当没有正在请求的任务时才开始请求(串行请求模式)
14154
14165
  * @private
14155
14166
  */
14156
14167
  BroadcastService.prototype.addTaskToQueue = function (task) {
14157
14168
  this.taskQueue.push(task);
14158
14169
  this.logger.debug('Task added to queue', {
14159
14170
  taskId: task.id,
14171
+ params: task.params,
14160
14172
  queueLength: this.taskQueue.length
14161
14173
  });
14162
- // 立即开始该任务的请求
14163
- this.startTaskRequest(task);
14174
+ // 检查是否有正在请求的任务
14175
+ var hasRequestingTask = this.taskQueue.some(function (t) {
14176
+ return t.status === BroadcastTaskStatus.REQUESTING;
14177
+ });
14178
+ // 只有当没有正在请求的任务时,才开始当前任务的请求
14179
+ if (!hasRequestingTask) {
14180
+ this.startTaskRequest(task);
14181
+ } else {
14182
+ this.logger.debug('Task queued, waiting for previous task to complete', {
14183
+ taskId: task.id,
14184
+ pendingTasks: this.taskQueue.filter(function (t) {
14185
+ return t.status === BroadcastTaskStatus.PENDING;
14186
+ }).length
14187
+ });
14188
+ }
14164
14189
  // 开始处理队列
14165
- this.processQueue();
14190
+ this.processTaskQueue();
14166
14191
  };
14167
14192
  /**
14168
14193
  * 处理队列
14169
- * @description 处理队列中的任务,发起请求生成音频
14194
+ * @description 处理队列中的任务响应,按序号发送给unity播放
14170
14195
  * @private
14171
14196
  */
14172
- BroadcastService.prototype.processQueue = function () {
14197
+ BroadcastService.prototype.processTaskQueue = function () {
14173
14198
  var _this = this;
14174
14199
  // 启动队列处理定时器(如果尚未启动)
14175
14200
  if (!this.queueProcessTimer) {
14176
14201
  this.queueProcessTimer = setInterval(function () {
14177
- _this.processQueueStep();
14202
+ _this.processTaskQueueStep();
14178
14203
  }, 100); // 每100ms检查一次队列状态
14179
14204
  }
14180
14205
  // 立即处理一次
14181
- this.processQueueStep();
14206
+ this.processTaskQueueStep();
14182
14207
  };
14183
14208
  /**
14184
14209
  * 队列处理步骤
14185
- * @description 处理队列中的单个步骤,包括发起请求和发送音频
14210
+ * @description 处理队列中的单个步骤,按序号发送给unity播放
14186
14211
  * @private
14187
14212
  */
14188
- BroadcastService.prototype.processQueueStep = function () {
14213
+ BroadcastService.prototype.processTaskQueueStep = function () {
14189
14214
  var _this = this;
14190
- // 按序号找到下一个要处理的任务
14215
+ // 按序号找到下一个要处理的任务(只处理已开始请求的任务,排除 PENDING 状态)
14191
14216
  var nextTask = this.taskQueue.find(function (task) {
14192
- return task.sequence === _this.currentSendingSequence + 1 && task.pendingResponses.length > 0;
14217
+ return task.sequence === _this.currentSendingSequence + 1 && task.status !== BroadcastTaskStatus.PENDING && task.pendingResponses.length > 0;
14193
14218
  });
14194
14219
  if (nextTask) {
14195
14220
  this.sendNextResponse(nextTask);
14196
14221
  }
14197
- // 如果队列中没有剩余任务,则停止定时器
14222
+ // 如果队列中没有剩余任务(排除待处理、已完成、失败和取消的任务),则停止定时器
14198
14223
  var remainingTasks = this.taskQueue.filter(function (task) {
14199
- return task.status !== BroadcastTaskStatus.COMPLETED && task.status !== BroadcastTaskStatus.FAILED && task.status !== BroadcastTaskStatus.CANCELLED;
14224
+ return task.status !== BroadcastTaskStatus.PENDING && task.status !== BroadcastTaskStatus.COMPLETED && task.status !== BroadcastTaskStatus.FAILED && task.status !== BroadcastTaskStatus.CANCELLED;
14200
14225
  });
14201
14226
  if (remainingTasks.length === 0) {
14202
14227
  this.clearQueueProcessTimer();
@@ -14297,7 +14322,7 @@ var ZEEAvatarSDKLib = (function (exports) {
14297
14322
  var response = JSON.parse(data);
14298
14323
  // 错误处理
14299
14324
  if (response.code !== 0) {
14300
- this.handleBroadcastError(response.code);
14325
+ this.handleBroadcastError(response.code, response.message);
14301
14326
  return;
14302
14327
  }
14303
14328
  // 处理音频数据
@@ -14311,6 +14336,7 @@ var ZEEAvatarSDKLib = (function (exports) {
14311
14336
  task.pendingResponses.push(response);
14312
14337
  this.logger.debug('Response added to task', {
14313
14338
  taskId: task.id,
14339
+ response: response,
14314
14340
  pendingCount: task.pendingResponses.length
14315
14341
  });
14316
14342
  // 检查是否完成
@@ -14323,13 +14349,13 @@ var ZEEAvatarSDKLib = (function (exports) {
14323
14349
  }
14324
14350
  }
14325
14351
  } catch (error) {
14326
- this.handleTaskError(task, error);
14352
+ this.handleTaskError(task, new SDKError(exports.OperationErrorCode.OPERATION_FAILED, typeof error === 'string' ? error : error.message || '播报服务错误'));
14327
14353
  }
14328
14354
  };
14329
14355
  /**
14330
- * 发送下一个响应
14356
+ * 发送下一个响应给unity播放
14331
14357
  * @param task - 播报任务
14332
- * @description 发送任务中的第一个待发送响应到Unity,发送后立即删除
14358
+ * @description 发送任务的响应数组中的第一个待发送响应到Unity(按顺序发送),发送后立即删除
14333
14359
  * @private
14334
14360
  */
14335
14361
  BroadcastService.prototype.sendNextResponse = function (task) {
@@ -14344,7 +14370,7 @@ var ZEEAvatarSDKLib = (function (exports) {
14344
14370
  remainingResponses: task.pendingResponses.length,
14345
14371
  voiceUrl: (_a = response.data) === null || _a === void 0 ? void 0 : _a.voiceUrl
14346
14372
  });
14347
- // 发送响应到Unity
14373
+ // 发送响应到Unity,这里不使用sendAsyncMessage,因为appendBroadcast不需要等待完成,而是在任务播报完成后通过startBroadcast回调通知
14348
14374
  this.sendMessage('AppendBroadcast', {
14349
14375
  response: response,
14350
14376
  callbackFun: this.uniqueCallbackName,
@@ -14362,7 +14388,7 @@ var ZEEAvatarSDKLib = (function (exports) {
14362
14388
  /**
14363
14389
  * 处理任务关闭
14364
14390
  * @param task - 播报任务
14365
- * @description 处理任务的流式连接关闭
14391
+ * @description 处理任务的流式连接关闭,并启动下一个待处理任务的请求
14366
14392
  * @private
14367
14393
  */
14368
14394
  BroadcastService.prototype.handleTaskClose = function (task) {
@@ -14373,12 +14399,14 @@ var ZEEAvatarSDKLib = (function (exports) {
14373
14399
  if (!task.isGenerationComplete && task.status === BroadcastTaskStatus.REQUESTING) {
14374
14400
  task.isGenerationComplete = true;
14375
14401
  }
14402
+ // 当前任务请求完成后(流断开后),启动下一个待处理任务的请求
14403
+ this.startNextPendingTask();
14376
14404
  };
14377
14405
  /**
14378
14406
  * 处理任务错误
14379
14407
  * @param task - 播报任务
14380
14408
  * @param error - 错误对象
14381
- * @description 处理任务执行过程中的错误,防止重复触发错误回调
14409
+ * @description 处理任务执行过程中的错误,防止重复触发错误回调,并启动下一个待处理任务
14382
14410
  * @private
14383
14411
  */
14384
14412
  BroadcastService.prototype.handleTaskError = function (task, error) {
@@ -14501,10 +14529,11 @@ var ZEEAvatarSDKLib = (function (exports) {
14501
14529
  /**
14502
14530
  * 处理播报错误
14503
14531
  * @param errorCode - 错误码
14532
+ * @param errorMessage - 错误消息
14504
14533
  * @description 处理播报过程中的错误
14505
14534
  * @private
14506
14535
  */
14507
- BroadcastService.prototype.handleBroadcastError = function (errorCode) {
14536
+ BroadcastService.prototype.handleBroadcastError = function (errorCode, errorMessage) {
14508
14537
  // 用户权益额度不存在错误码 14001
14509
14538
  // 用户权益额度不足错误码 14002
14510
14539
  // 用户权益额度冻结失败 14003
@@ -14519,10 +14548,32 @@ var ZEEAvatarSDKLib = (function (exports) {
14519
14548
  this.handleError(new SDKError(exports.OperationErrorCode.BROADCAST_EQUITY_FREEZE_FAILED, '用户权益额度冻结失败'));
14520
14549
  break;
14521
14550
  default:
14522
- this.handleError(new SDKError(exports.OperationErrorCode.OPERATION_FAILED, '播报服务错误'));
14551
+ this.handleError(new SDKError(exports.OperationErrorCode.OPERATION_FAILED, "".concat(errorMessage, "(").concat(errorCode, ")") || "\u64AD\u62A5\u670D\u52A1\u9519\u8BEF(".concat(errorCode, ")")));
14523
14552
  break;
14524
14553
  }
14525
14554
  };
14555
+ /**
14556
+ * 启动下一个待处理任务的请求
14557
+ * @description 在当前任务请求完成或失败后,检查并启动下一个待处理任务
14558
+ * @private
14559
+ */
14560
+ BroadcastService.prototype.startNextPendingTask = function () {
14561
+ // 查找下一个待处理的任务(按序号排序,取第一个 PENDING 状态的任务)
14562
+ var nextPendingTask = this.taskQueue.filter(function (t) {
14563
+ return t.status === BroadcastTaskStatus.PENDING;
14564
+ }).sort(function (a, b) {
14565
+ return a.sequence - b.sequence;
14566
+ })[0];
14567
+ if (nextPendingTask) {
14568
+ this.logger.debug('Starting next pending task', {
14569
+ taskId: nextPendingTask.id,
14570
+ sequence: nextPendingTask.sequence
14571
+ });
14572
+ this.startTaskRequest(nextPendingTask);
14573
+ } else {
14574
+ this.logger.debug('No pending tasks to start');
14575
+ }
14576
+ };
14526
14577
  /**
14527
14578
  * 清理队列处理定时器
14528
14579
  * @description 清理队列处理定时器
@@ -14532,6 +14583,7 @@ var ZEEAvatarSDKLib = (function (exports) {
14532
14583
  if (this.queueProcessTimer) {
14533
14584
  clearInterval(this.queueProcessTimer);
14534
14585
  this.queueProcessTimer = null;
14586
+ this.logger.debug('Queue process timer cleared');
14535
14587
  }
14536
14588
  };
14537
14589
  /**
@@ -14739,6 +14791,7 @@ var ZEEAvatarSDKLib = (function (exports) {
14739
14791
  */
14740
14792
  ZEEAvatarLoader.prototype.initGlobalConfig = function () {
14741
14793
  var config = ConfigManager.getInstance().getConfig();
14794
+ var assetsFrom = config.assetsFrom;
14742
14795
  var globalParams = {
14743
14796
  token: config === null || config === void 0 ? void 0 : config.token,
14744
14797
  apiBaseUrl: ConfigManager.getInstance().getApiBaseUrl(false),
@@ -14746,14 +14799,17 @@ var ZEEAvatarSDKLib = (function (exports) {
14746
14799
  // 純AB包方案在SDK 2.1.0 中已弃用
14747
14800
  // assetsUrl: config?.assetsUrl
14748
14801
  };
14749
- var assetModuleParams = {
14750
- isZip: true,
14751
- assetBundlePath: config === null || config === void 0 ? void 0 : config.assetsUrl
14752
- };
14753
14802
  this.unityInstance.SendMessage('AvatarSDK', 'InitializeConfig', JSON.stringify(globalParams));
14754
- this.unityInstance.SendMessage('AvatarSDK', 'InitAssetBundleModule', JSON.stringify(assetModuleParams));
14755
14803
  console.warn('[ Send Unity message ]: AvatarSDK.InitializeConfig', globalParams);
14756
- console.warn('[ Send Unity message ]: AvatarSDK.InitAssetBundleModule', assetModuleParams);
14804
+ //
14805
+ if (assetsFrom !== 'cloud') {
14806
+ var assetModuleParams = {
14807
+ isZip: true,
14808
+ assetBundlePath: config === null || config === void 0 ? void 0 : config.assetsUrl
14809
+ };
14810
+ this.unityInstance.SendMessage('AvatarSDK', 'InitAssetBundleModule', JSON.stringify(assetModuleParams));
14811
+ console.warn('[ Send Unity message ]: AvatarSDK.InitAssetBundleModule', assetModuleParams);
14812
+ }
14757
14813
  };
14758
14814
  return ZEEAvatarLoader;
14759
14815
  }();