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

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.
@@ -1562,14 +1562,14 @@
1562
1562
  this.taskSequence = 0;
1563
1563
  /** 当前发送任务的序号 */
1564
1564
  this.currentSendingSequence = 0;
1565
- /** 是否正在生成音频 */
1566
- this.isGeneratingAudio = false;
1565
+ /** 是否正在播报音频 */
1566
+ this.isBroadcastingAudio = false;
1567
1567
  /** 是否已经收到音频 */
1568
1568
  this.hasReceivedAudio = false;
1569
1569
  /** 队列处理定时器 */
1570
1570
  this.queueProcessTimer = null;
1571
- /** 主请求控制器(兼容性保留) */
1572
- this.activeController = null;
1571
+ /** 播报完成次数 */
1572
+ this.broadcastCompletedCount = 0;
1573
1573
  this.callbacks = config.callbacks || {};
1574
1574
  this.logger.info('Broadcast service initialized', { config });
1575
1575
  }
@@ -1583,7 +1583,7 @@
1583
1583
  * @override
1584
1584
  */
1585
1585
  handleCallback(operation, code, message, data) {
1586
- var _a, _b, _c, _d, _e, _f, _g, _h;
1586
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1587
1587
  // 提取 isBroadcastCompleted 参数
1588
1588
  const { isBroadcastCompleted } = JSON.parse(data || '{}');
1589
1589
  // 先调用基类处理逻辑
@@ -1593,19 +1593,31 @@
1593
1593
  switch (operation) {
1594
1594
  case exports.BroadcastOperationType.START_BROADCAST:
1595
1595
  if (isBroadcastCompleted) {
1596
- (_b = (_a = this.callbacks).onFinish) === null || _b === void 0 ? void 0 : _b.call(_a);
1596
+ this.broadcastCompletedCount++;
1597
+ const status = this.getStatus();
1598
+ if (((_a = status.queueInfo) === null || _a === void 0 ? void 0 : _a.completedTasks) === this.broadcastCompletedCount) {
1599
+ // 重置状态、计数
1600
+ this.isBroadcastingAudio = false;
1601
+ this.hasReceivedAudio = false;
1602
+ this.currentSendingSequence = 0;
1603
+ // 清理已完成的任务
1604
+ this.cleanupCompletedTasks();
1605
+ this.logger.warn('Broadcast all completed');
1606
+ }
1607
+ // this.logger.warn('AAAAAA', { status: this.getStatus(), broadcastCompletedCount: this.broadcastCompletedCount });
1608
+ (_c = (_b = this.callbacks).onFinish) === null || _c === void 0 ? void 0 : _c.call(_b);
1597
1609
  }
1598
1610
  break;
1599
1611
  case exports.BroadcastOperationType.PAUSE_BROADCAST:
1600
- (_d = (_c = this.callbacks).onPause) === null || _d === void 0 ? void 0 : _d.call(_c);
1612
+ (_e = (_d = this.callbacks).onPause) === null || _e === void 0 ? void 0 : _e.call(_d);
1601
1613
  this.logger.debug('Broadcast paused callback triggered');
1602
1614
  break;
1603
1615
  case exports.BroadcastOperationType.RESUME_BROADCAST:
1604
- (_f = (_e = this.callbacks).onResume) === null || _f === void 0 ? void 0 : _f.call(_e);
1616
+ (_g = (_f = this.callbacks).onResume) === null || _g === void 0 ? void 0 : _g.call(_f);
1605
1617
  this.logger.debug('Broadcast resumed callback triggered');
1606
1618
  break;
1607
1619
  case exports.BroadcastOperationType.STOP_BROADCAST:
1608
- (_h = (_g = this.callbacks).onStop) === null || _h === void 0 ? void 0 : _h.call(_g);
1620
+ (_j = (_h = this.callbacks).onStop) === null || _j === void 0 ? void 0 : _j.call(_h);
1609
1621
  this.logger.debug('Broadcast stopped callback triggered');
1610
1622
  break;
1611
1623
  }
@@ -1671,7 +1683,7 @@
1671
1683
  });
1672
1684
  // 触发开始回调
1673
1685
  (_b = (_a = this.callbacks).onStart) === null || _b === void 0 ? void 0 : _b.call(_a);
1674
- this.isGeneratingAudio = true;
1686
+ this.isBroadcastingAudio = true;
1675
1687
  }
1676
1688
  // 创建新的播报任务
1677
1689
  const task = this.createBroadcastTask(params);
@@ -1746,8 +1758,9 @@
1746
1758
  // 取消所有队列中的任务
1747
1759
  this.cancelAllTasks();
1748
1760
  // 重置状态
1749
- this.isGeneratingAudio = false;
1761
+ this.isBroadcastingAudio = false;
1750
1762
  this.hasReceivedAudio = false;
1763
+ this.broadcastCompletedCount = 0;
1751
1764
  try {
1752
1765
  yield this.sendAsyncMessage('StopBroadcast', exports.BroadcastOperationType.STOP_BROADCAST, {});
1753
1766
  this.logger.info('Broadcast stopped successfully');
@@ -1773,19 +1786,23 @@
1773
1786
  * @description 获取当前播报服务的状态信息,包括队列状态
1774
1787
  */
1775
1788
  getStatus() {
1789
+ const completedTasks = this.taskQueue.filter((t) => t.status === BroadcastTaskStatus.COMPLETED).length;
1790
+ const requestingTasks = this.taskQueue.filter((t) => t.status === BroadcastTaskStatus.REQUESTING).length;
1791
+ const failedTasks = this.taskQueue.filter((t) => t.status === BroadcastTaskStatus.FAILED).length;
1792
+ const totalPendingResponses = this.taskQueue.reduce((sum, t) => sum + t.pendingResponses.length, 0);
1793
+ const currentSendingSequence = this.currentSendingSequence;
1794
+ const isGeneratingAudio = completedTasks + failedTasks !== this.taskQueue.length;
1776
1795
  return {
1777
- isActive: this.taskQueue.length > 0 || this.isGeneratingAudio,
1778
- isGeneratingAudio: this.isGeneratingAudio,
1796
+ isActive: this.isBroadcastingAudio || isGeneratingAudio, // 是否正在播报音频或正在生成音频
1797
+ isGeneratingAudio,
1779
1798
  hasReceivedAudio: this.hasReceivedAudio,
1780
- pendingCallbacks: this.getPendingCallbackCount(),
1781
- hasController: this.activeController !== null,
1782
1799
  queueInfo: {
1783
1800
  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
1801
+ requestingTasks,
1802
+ completedTasks,
1803
+ failedTasks,
1804
+ totalPendingResponses,
1805
+ currentSendingSequence
1789
1806
  }
1790
1807
  };
1791
1808
  }
@@ -1795,10 +1812,7 @@
1795
1812
  */
1796
1813
  destroy() {
1797
1814
  // 清理队列处理定时器
1798
- if (this.queueProcessTimer) {
1799
- clearInterval(this.queueProcessTimer);
1800
- this.queueProcessTimer = null;
1801
- }
1815
+ this.clearQueueProcessTimer();
1802
1816
  // 取消所有任务
1803
1817
  this.cancelAllTasks();
1804
1818
  // 调用基类销毁方法
@@ -1867,12 +1881,12 @@
1867
1881
  if (nextTask) {
1868
1882
  this.sendNextResponse(nextTask);
1869
1883
  }
1870
- // 清理已完成的任务
1871
- this.cleanupCompletedTasks();
1872
- // 如果队列为空,停止定时器
1873
- if (this.taskQueue.length === 0 && this.queueProcessTimer) {
1874
- clearInterval(this.queueProcessTimer);
1875
- this.queueProcessTimer = null;
1884
+ // 如果队列中没有剩余任务,则停止定时器
1885
+ const remainingTasks = this.taskQueue.filter(task => task.status !== BroadcastTaskStatus.COMPLETED
1886
+ && task.status !== BroadcastTaskStatus.FAILED
1887
+ && task.status !== BroadcastTaskStatus.CANCELLED);
1888
+ if (remainingTasks.length === 0) {
1889
+ this.clearQueueProcessTimer();
1876
1890
  }
1877
1891
  }
1878
1892
  /**
@@ -1946,6 +1960,7 @@
1946
1960
  }
1947
1961
  // 处理音频数据
1948
1962
  if (response.data) {
1963
+ this.hasReceivedAudio = true;
1949
1964
  // 自定义音频播报时,如果服务器未返回音频URL,使用传入的audioUrl
1950
1965
  if (task.params.type === exports.BroadcastType.AUDIO && task.params.audioUrl && !response.data.voiceUrl) {
1951
1966
  response.data.voiceUrl = task.params.audioUrl;
@@ -2106,11 +2121,6 @@
2106
2121
  handleError(error) {
2107
2122
  var _a, _b;
2108
2123
  this.logger.error('Broadcast error occurred', error);
2109
- // 清理控制器
2110
- if (this.activeController) {
2111
- this.activeController.abort();
2112
- this.activeController = null;
2113
- }
2114
2124
  // 触发错误回调
2115
2125
  (_b = (_a = this.callbacks).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
2116
2126
  }
@@ -2139,6 +2149,17 @@
2139
2149
  break;
2140
2150
  }
2141
2151
  }
2152
+ /**
2153
+ * 清理队列处理定时器
2154
+ * @description 清理队列处理定时器
2155
+ * @private
2156
+ */
2157
+ clearQueueProcessTimer() {
2158
+ if (this.queueProcessTimer) {
2159
+ clearInterval(this.queueProcessTimer);
2160
+ this.queueProcessTimer = null;
2161
+ }
2162
+ }
2142
2163
  }
2143
2164
 
2144
2165
  /**
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": "1.2.5",
5
5
  "description": "SDK for ZEE Avatar WebGL integration",
6
6
  "author": "ZEEWain",
7
7
  "license": "MIT",