@zeewain/3d-avatar-sdk 1.2.4-1 → 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.
package/dist/index.esm.js CHANGED
@@ -1556,14 +1556,14 @@ class BroadcastService extends UnityBaseService {
1556
1556
  this.taskSequence = 0;
1557
1557
  /** 当前发送任务的序号 */
1558
1558
  this.currentSendingSequence = 0;
1559
- /** 是否正在生成音频 */
1560
- this.isGeneratingAudio = false;
1559
+ /** 是否正在播报音频 */
1560
+ this.isBroadcastingAudio = false;
1561
1561
  /** 是否已经收到音频 */
1562
1562
  this.hasReceivedAudio = false;
1563
1563
  /** 队列处理定时器 */
1564
1564
  this.queueProcessTimer = null;
1565
- /** 主请求控制器(兼容性保留) */
1566
- this.activeController = null;
1565
+ /** 播报完成次数 */
1566
+ this.broadcastCompletedCount = 0;
1567
1567
  this.callbacks = config.callbacks || {};
1568
1568
  this.logger.info('Broadcast service initialized', { config });
1569
1569
  }
@@ -1577,7 +1577,7 @@ class BroadcastService extends UnityBaseService {
1577
1577
  * @override
1578
1578
  */
1579
1579
  handleCallback(operation, code, message, data) {
1580
- var _a, _b, _c, _d, _e, _f, _g, _h;
1580
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1581
1581
  // 提取 isBroadcastCompleted 参数
1582
1582
  const { isBroadcastCompleted } = JSON.parse(data || '{}');
1583
1583
  // 先调用基类处理逻辑
@@ -1587,19 +1587,31 @@ class BroadcastService extends UnityBaseService {
1587
1587
  switch (operation) {
1588
1588
  case BroadcastOperationType.START_BROADCAST:
1589
1589
  if (isBroadcastCompleted) {
1590
- (_b = (_a = this.callbacks).onFinish) === null || _b === void 0 ? void 0 : _b.call(_a);
1590
+ this.broadcastCompletedCount++;
1591
+ const status = this.getStatus();
1592
+ if (((_a = status.queueInfo) === null || _a === void 0 ? void 0 : _a.completedTasks) === this.broadcastCompletedCount) {
1593
+ // 重置状态、计数
1594
+ this.isBroadcastingAudio = false;
1595
+ this.hasReceivedAudio = false;
1596
+ this.currentSendingSequence = 0;
1597
+ // 清理已完成的任务
1598
+ this.cleanupCompletedTasks();
1599
+ this.logger.warn('Broadcast all completed');
1600
+ }
1601
+ // this.logger.warn('AAAAAA', { status: this.getStatus(), broadcastCompletedCount: this.broadcastCompletedCount });
1602
+ (_c = (_b = this.callbacks).onFinish) === null || _c === void 0 ? void 0 : _c.call(_b);
1591
1603
  }
1592
1604
  break;
1593
1605
  case BroadcastOperationType.PAUSE_BROADCAST:
1594
- (_d = (_c = this.callbacks).onPause) === null || _d === void 0 ? void 0 : _d.call(_c);
1606
+ (_e = (_d = this.callbacks).onPause) === null || _e === void 0 ? void 0 : _e.call(_d);
1595
1607
  this.logger.debug('Broadcast paused callback triggered');
1596
1608
  break;
1597
1609
  case BroadcastOperationType.RESUME_BROADCAST:
1598
- (_f = (_e = this.callbacks).onResume) === null || _f === void 0 ? void 0 : _f.call(_e);
1610
+ (_g = (_f = this.callbacks).onResume) === null || _g === void 0 ? void 0 : _g.call(_f);
1599
1611
  this.logger.debug('Broadcast resumed callback triggered');
1600
1612
  break;
1601
1613
  case BroadcastOperationType.STOP_BROADCAST:
1602
- (_h = (_g = this.callbacks).onStop) === null || _h === void 0 ? void 0 : _h.call(_g);
1614
+ (_j = (_h = this.callbacks).onStop) === null || _j === void 0 ? void 0 : _j.call(_h);
1603
1615
  this.logger.debug('Broadcast stopped callback triggered');
1604
1616
  break;
1605
1617
  }
@@ -1665,7 +1677,7 @@ class BroadcastService extends UnityBaseService {
1665
1677
  });
1666
1678
  // 触发开始回调
1667
1679
  (_b = (_a = this.callbacks).onStart) === null || _b === void 0 ? void 0 : _b.call(_a);
1668
- this.isGeneratingAudio = true;
1680
+ this.isBroadcastingAudio = true;
1669
1681
  }
1670
1682
  // 创建新的播报任务
1671
1683
  const task = this.createBroadcastTask(params);
@@ -1740,8 +1752,9 @@ class BroadcastService extends UnityBaseService {
1740
1752
  // 取消所有队列中的任务
1741
1753
  this.cancelAllTasks();
1742
1754
  // 重置状态
1743
- this.isGeneratingAudio = false;
1755
+ this.isBroadcastingAudio = false;
1744
1756
  this.hasReceivedAudio = false;
1757
+ this.broadcastCompletedCount = 0;
1745
1758
  try {
1746
1759
  yield this.sendAsyncMessage('StopBroadcast', BroadcastOperationType.STOP_BROADCAST, {});
1747
1760
  this.logger.info('Broadcast stopped successfully');
@@ -1767,19 +1780,23 @@ class BroadcastService extends UnityBaseService {
1767
1780
  * @description 获取当前播报服务的状态信息,包括队列状态
1768
1781
  */
1769
1782
  getStatus() {
1783
+ const completedTasks = this.taskQueue.filter((t) => t.status === BroadcastTaskStatus.COMPLETED).length;
1784
+ const requestingTasks = this.taskQueue.filter((t) => t.status === BroadcastTaskStatus.REQUESTING).length;
1785
+ const failedTasks = this.taskQueue.filter((t) => t.status === BroadcastTaskStatus.FAILED).length;
1786
+ const totalPendingResponses = this.taskQueue.reduce((sum, t) => sum + t.pendingResponses.length, 0);
1787
+ const currentSendingSequence = this.currentSendingSequence;
1788
+ const isGeneratingAudio = completedTasks + failedTasks !== this.taskQueue.length;
1770
1789
  return {
1771
- isActive: this.taskQueue.length > 0 || this.isGeneratingAudio,
1772
- isGeneratingAudio: this.isGeneratingAudio,
1790
+ isActive: this.isBroadcastingAudio || isGeneratingAudio, // 是否正在播报音频或正在生成音频
1791
+ isGeneratingAudio,
1773
1792
  hasReceivedAudio: this.hasReceivedAudio,
1774
- pendingCallbacks: this.getPendingCallbackCount(),
1775
- hasController: this.activeController !== null,
1776
1793
  queueInfo: {
1777
1794
  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
1795
+ requestingTasks,
1796
+ completedTasks,
1797
+ failedTasks,
1798
+ totalPendingResponses,
1799
+ currentSendingSequence
1783
1800
  }
1784
1801
  };
1785
1802
  }
@@ -1789,10 +1806,7 @@ class BroadcastService extends UnityBaseService {
1789
1806
  */
1790
1807
  destroy() {
1791
1808
  // 清理队列处理定时器
1792
- if (this.queueProcessTimer) {
1793
- clearInterval(this.queueProcessTimer);
1794
- this.queueProcessTimer = null;
1795
- }
1809
+ this.clearQueueProcessTimer();
1796
1810
  // 取消所有任务
1797
1811
  this.cancelAllTasks();
1798
1812
  // 调用基类销毁方法
@@ -1861,12 +1875,12 @@ class BroadcastService extends UnityBaseService {
1861
1875
  if (nextTask) {
1862
1876
  this.sendNextResponse(nextTask);
1863
1877
  }
1864
- // 清理已完成的任务
1865
- this.cleanupCompletedTasks();
1866
- // 如果队列为空,停止定时器
1867
- if (this.taskQueue.length === 0 && this.queueProcessTimer) {
1868
- clearInterval(this.queueProcessTimer);
1869
- this.queueProcessTimer = null;
1878
+ // 如果队列中没有剩余任务,则停止定时器
1879
+ const remainingTasks = this.taskQueue.filter(task => task.status !== BroadcastTaskStatus.COMPLETED
1880
+ && task.status !== BroadcastTaskStatus.FAILED
1881
+ && task.status !== BroadcastTaskStatus.CANCELLED);
1882
+ if (remainingTasks.length === 0) {
1883
+ this.clearQueueProcessTimer();
1870
1884
  }
1871
1885
  }
1872
1886
  /**
@@ -1940,6 +1954,7 @@ class BroadcastService extends UnityBaseService {
1940
1954
  }
1941
1955
  // 处理音频数据
1942
1956
  if (response.data) {
1957
+ this.hasReceivedAudio = true;
1943
1958
  // 自定义音频播报时,如果服务器未返回音频URL,使用传入的audioUrl
1944
1959
  if (task.params.type === BroadcastType.AUDIO && task.params.audioUrl && !response.data.voiceUrl) {
1945
1960
  response.data.voiceUrl = task.params.audioUrl;
@@ -2062,20 +2077,12 @@ class BroadcastService extends UnityBaseService {
2062
2077
  * @private
2063
2078
  */
2064
2079
  getBroadcastApiPath(type) {
2065
- const env = ConfigManager.getInstance().getEnv();
2080
+ ConfigManager.getInstance().getEnv();
2066
2081
  switch (type) {
2067
2082
  case BroadcastType.TEXT:
2068
- // 临时处理,开发和测试环境使用新接口
2069
- if (env === 'dev' || env === 'test') {
2070
- return '/aiep-openapi/avatar-interaction/v1/broadcast/text';
2071
- }
2072
- return '/dh-talker/user/agent/broadcast/text';
2083
+ return '/aiep-openapi/avatar-interaction/v1/broadcast/text';
2073
2084
  case BroadcastType.AUDIO:
2074
- // 临时处理,开发和测试环境使用新接口
2075
- if (env === 'dev' || env === 'test') {
2076
- return '/aiep-openapi/avatar-interaction/v1/broadcast/audio';
2077
- }
2078
- return '/dh-talker/user/agent/broadcast/customAudio';
2085
+ return '/aiep-openapi/avatar-interaction/v1/broadcast/audio';
2079
2086
  default:
2080
2087
  throw new SDKError(ConfigErrorCode.INVALID_CONFIG, `未知的播报类型: ${type}`);
2081
2088
  }
@@ -2108,11 +2115,6 @@ class BroadcastService extends UnityBaseService {
2108
2115
  handleError(error) {
2109
2116
  var _a, _b;
2110
2117
  this.logger.error('Broadcast error occurred', error);
2111
- // 清理控制器
2112
- if (this.activeController) {
2113
- this.activeController.abort();
2114
- this.activeController = null;
2115
- }
2116
2118
  // 触发错误回调
2117
2119
  (_b = (_a = this.callbacks).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
2118
2120
  }
@@ -2141,6 +2143,17 @@ class BroadcastService extends UnityBaseService {
2141
2143
  break;
2142
2144
  }
2143
2145
  }
2146
+ /**
2147
+ * 清理队列处理定时器
2148
+ * @description 清理队列处理定时器
2149
+ * @private
2150
+ */
2151
+ clearQueueProcessTimer() {
2152
+ if (this.queueProcessTimer) {
2153
+ clearInterval(this.queueProcessTimer);
2154
+ this.queueProcessTimer = null;
2155
+ }
2156
+ }
2144
2157
  }
2145
2158
 
2146
2159
  /**
@@ -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;
@@ -2068,20 +2083,12 @@
2068
2083
  * @private
2069
2084
  */
2070
2085
  getBroadcastApiPath(type) {
2071
- const env = ConfigManager.getInstance().getEnv();
2086
+ ConfigManager.getInstance().getEnv();
2072
2087
  switch (type) {
2073
2088
  case exports.BroadcastType.TEXT:
2074
- // 临时处理,开发和测试环境使用新接口
2075
- if (env === 'dev' || env === 'test') {
2076
- return '/aiep-openapi/avatar-interaction/v1/broadcast/text';
2077
- }
2078
- return '/dh-talker/user/agent/broadcast/text';
2089
+ return '/aiep-openapi/avatar-interaction/v1/broadcast/text';
2079
2090
  case exports.BroadcastType.AUDIO:
2080
- // 临时处理,开发和测试环境使用新接口
2081
- if (env === 'dev' || env === 'test') {
2082
- return '/aiep-openapi/avatar-interaction/v1/broadcast/audio';
2083
- }
2084
- return '/dh-talker/user/agent/broadcast/customAudio';
2091
+ return '/aiep-openapi/avatar-interaction/v1/broadcast/audio';
2085
2092
  default:
2086
2093
  throw new SDKError(exports.ConfigErrorCode.INVALID_CONFIG, `未知的播报类型: ${type}`);
2087
2094
  }
@@ -2114,11 +2121,6 @@
2114
2121
  handleError(error) {
2115
2122
  var _a, _b;
2116
2123
  this.logger.error('Broadcast error occurred', error);
2117
- // 清理控制器
2118
- if (this.activeController) {
2119
- this.activeController.abort();
2120
- this.activeController = null;
2121
- }
2122
2124
  // 触发错误回调
2123
2125
  (_b = (_a = this.callbacks).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
2124
2126
  }
@@ -2147,6 +2149,17 @@
2147
2149
  break;
2148
2150
  }
2149
2151
  }
2152
+ /**
2153
+ * 清理队列处理定时器
2154
+ * @description 清理队列处理定时器
2155
+ * @private
2156
+ */
2157
+ clearQueueProcessTimer() {
2158
+ if (this.queueProcessTimer) {
2159
+ clearInterval(this.queueProcessTimer);
2160
+ this.queueProcessTimer = null;
2161
+ }
2162
+ }
2150
2163
  }
2151
2164
 
2152
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-1",
4
+ "version": "1.2.5",
5
5
  "description": "SDK for ZEE Avatar WebGL integration",
6
6
  "author": "ZEEWain",
7
7
  "license": "MIT",