@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.
- package/README.md +4 -8
- package/dist/examples/test-vue2/package.json +1 -1
- package/dist/examples/test-vue3/package.json +1 -1
- package/dist/examples/test-vue3/pnpm-lock.yaml +7 -7
- package/dist/examples/test-vue3/src/App.vue +34 -12
- package/dist/examples/test-vue3/src/components/BroadcastAPI.vue +78 -26
- package/dist/examples/test-vue3/src/components/GlobalConfig.vue +1 -0
- package/dist/examples/test-vue3/src/components/LogPanel.vue +5 -5
- package/dist/examples/test-vue3/src/components/MotionControlAPI.vue +44 -7
- package/dist/examples/test-vue3/src/utils/index.ts +35 -0
- package/dist/index.d.ts +26 -10
- package/dist/index.es5.js +65 -43
- package/dist/index.es5.umd.js +65 -43
- package/dist/index.esm.js +56 -35
- package/dist/index.umd.cjs +56 -35
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -305,8 +305,14 @@ interface IBroadcastAPI {
|
|
|
305
305
|
isActive: boolean;
|
|
306
306
|
isGeneratingAudio: boolean;
|
|
307
307
|
hasReceivedAudio: boolean;
|
|
308
|
-
|
|
309
|
-
|
|
308
|
+
queueInfo?: {
|
|
309
|
+
totalTasks: number;
|
|
310
|
+
requestingTasks: number;
|
|
311
|
+
completedTasks: number;
|
|
312
|
+
failedTasks: number;
|
|
313
|
+
totalPendingResponses: number;
|
|
314
|
+
currentSendingSequence: number;
|
|
315
|
+
};
|
|
310
316
|
};
|
|
311
317
|
/**
|
|
312
318
|
* 销毁播报服务
|
|
@@ -546,8 +552,14 @@ declare class ZEEAvatarSDK {
|
|
|
546
552
|
isActive: boolean;
|
|
547
553
|
isGeneratingAudio: boolean;
|
|
548
554
|
hasReceivedAudio: boolean;
|
|
549
|
-
|
|
550
|
-
|
|
555
|
+
queueInfo?: {
|
|
556
|
+
totalTasks: number;
|
|
557
|
+
requestingTasks: number;
|
|
558
|
+
completedTasks: number;
|
|
559
|
+
failedTasks: number;
|
|
560
|
+
totalPendingResponses: number;
|
|
561
|
+
currentSendingSequence: number;
|
|
562
|
+
};
|
|
551
563
|
};
|
|
552
564
|
/**
|
|
553
565
|
* 销毁SDK实例
|
|
@@ -845,14 +857,14 @@ declare class BroadcastService extends UnityBaseService<BroadcastOperationType>
|
|
|
845
857
|
private taskSequence;
|
|
846
858
|
/** 当前发送任务的序号 */
|
|
847
859
|
private currentSendingSequence;
|
|
848
|
-
/**
|
|
849
|
-
private
|
|
860
|
+
/** 是否正在播报音频 */
|
|
861
|
+
private isBroadcastingAudio;
|
|
850
862
|
/** 是否已经收到音频 */
|
|
851
863
|
private hasReceivedAudio;
|
|
852
864
|
/** 队列处理定时器 */
|
|
853
865
|
private queueProcessTimer;
|
|
854
|
-
/**
|
|
855
|
-
private
|
|
866
|
+
/** 播报完成次数 */
|
|
867
|
+
private broadcastCompletedCount;
|
|
856
868
|
/**
|
|
857
869
|
* 构造函数
|
|
858
870
|
* @param config - 播报服务配置
|
|
@@ -959,8 +971,6 @@ declare class BroadcastService extends UnityBaseService<BroadcastOperationType>
|
|
|
959
971
|
isActive: boolean;
|
|
960
972
|
isGeneratingAudio: boolean;
|
|
961
973
|
hasReceivedAudio: boolean;
|
|
962
|
-
pendingCallbacks: number;
|
|
963
|
-
hasController: boolean;
|
|
964
974
|
queueInfo?: {
|
|
965
975
|
totalTasks: number;
|
|
966
976
|
requestingTasks: number;
|
|
@@ -1084,6 +1094,12 @@ declare class BroadcastService extends UnityBaseService<BroadcastOperationType>
|
|
|
1084
1094
|
* @private
|
|
1085
1095
|
*/
|
|
1086
1096
|
private handleBroadcastError;
|
|
1097
|
+
/**
|
|
1098
|
+
* 清理队列处理定时器
|
|
1099
|
+
* @description 清理队列处理定时器
|
|
1100
|
+
* @private
|
|
1101
|
+
*/
|
|
1102
|
+
private clearQueueProcessTimer;
|
|
1087
1103
|
}
|
|
1088
1104
|
|
|
1089
1105
|
/**
|
package/dist/index.es5.js
CHANGED
|
@@ -13816,14 +13816,14 @@ var ZEEAvatarSDKLib = (function (exports) {
|
|
|
13816
13816
|
_this.taskSequence = 0;
|
|
13817
13817
|
/** 当前发送任务的序号 */
|
|
13818
13818
|
_this.currentSendingSequence = 0;
|
|
13819
|
-
/**
|
|
13820
|
-
_this.
|
|
13819
|
+
/** 是否正在播报音频 */
|
|
13820
|
+
_this.isBroadcastingAudio = false;
|
|
13821
13821
|
/** 是否已经收到音频 */
|
|
13822
13822
|
_this.hasReceivedAudio = false;
|
|
13823
13823
|
/** 队列处理定时器 */
|
|
13824
13824
|
_this.queueProcessTimer = null;
|
|
13825
|
-
/**
|
|
13826
|
-
_this.
|
|
13825
|
+
/** 播报完成次数 */
|
|
13826
|
+
_this.broadcastCompletedCount = 0;
|
|
13827
13827
|
_this.callbacks = config.callbacks || {};
|
|
13828
13828
|
_this.logger.info('Broadcast service initialized', {
|
|
13829
13829
|
config: config
|
|
@@ -13840,7 +13840,7 @@ var ZEEAvatarSDKLib = (function (exports) {
|
|
|
13840
13840
|
* @override
|
|
13841
13841
|
*/
|
|
13842
13842
|
BroadcastService.prototype.handleCallback = function (operation, code, message, data) {
|
|
13843
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
13843
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
13844
13844
|
// 提取 isBroadcastCompleted 参数
|
|
13845
13845
|
var isBroadcastCompleted = JSON.parse(data || '{}').isBroadcastCompleted;
|
|
13846
13846
|
// 先调用基类处理逻辑
|
|
@@ -13850,19 +13850,31 @@ var ZEEAvatarSDKLib = (function (exports) {
|
|
|
13850
13850
|
switch (operation) {
|
|
13851
13851
|
case exports.BroadcastOperationType.START_BROADCAST:
|
|
13852
13852
|
if (isBroadcastCompleted) {
|
|
13853
|
-
|
|
13853
|
+
this.broadcastCompletedCount++;
|
|
13854
|
+
var status_1 = this.getStatus();
|
|
13855
|
+
if (((_a = status_1.queueInfo) === null || _a === void 0 ? void 0 : _a.completedTasks) === this.broadcastCompletedCount) {
|
|
13856
|
+
// 重置状态、计数
|
|
13857
|
+
this.isBroadcastingAudio = false;
|
|
13858
|
+
this.hasReceivedAudio = false;
|
|
13859
|
+
this.currentSendingSequence = 0;
|
|
13860
|
+
// 清理已完成的任务
|
|
13861
|
+
this.cleanupCompletedTasks();
|
|
13862
|
+
this.logger.warn('Broadcast all completed');
|
|
13863
|
+
}
|
|
13864
|
+
// this.logger.warn('AAAAAA', { status: this.getStatus(), broadcastCompletedCount: this.broadcastCompletedCount });
|
|
13865
|
+
(_c = (_b = this.callbacks).onFinish) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
13854
13866
|
}
|
|
13855
13867
|
break;
|
|
13856
13868
|
case exports.BroadcastOperationType.PAUSE_BROADCAST:
|
|
13857
|
-
(
|
|
13869
|
+
(_e = (_d = this.callbacks).onPause) === null || _e === void 0 ? void 0 : _e.call(_d);
|
|
13858
13870
|
this.logger.debug('Broadcast paused callback triggered');
|
|
13859
13871
|
break;
|
|
13860
13872
|
case exports.BroadcastOperationType.RESUME_BROADCAST:
|
|
13861
|
-
(
|
|
13873
|
+
(_g = (_f = this.callbacks).onResume) === null || _g === void 0 ? void 0 : _g.call(_f);
|
|
13862
13874
|
this.logger.debug('Broadcast resumed callback triggered');
|
|
13863
13875
|
break;
|
|
13864
13876
|
case exports.BroadcastOperationType.STOP_BROADCAST:
|
|
13865
|
-
(
|
|
13877
|
+
(_j = (_h = this.callbacks).onStop) === null || _j === void 0 ? void 0 : _j.call(_h);
|
|
13866
13878
|
this.logger.debug('Broadcast stopped callback triggered');
|
|
13867
13879
|
break;
|
|
13868
13880
|
}
|
|
@@ -13933,7 +13945,7 @@ var ZEEAvatarSDKLib = (function (exports) {
|
|
|
13933
13945
|
});
|
|
13934
13946
|
// 触发开始回调
|
|
13935
13947
|
(_b = (_a = this.callbacks).onStart) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
13936
|
-
this.
|
|
13948
|
+
this.isBroadcastingAudio = true;
|
|
13937
13949
|
_c.label = 2;
|
|
13938
13950
|
case 2:
|
|
13939
13951
|
task = this.createBroadcastTask(params);
|
|
@@ -14041,8 +14053,9 @@ var ZEEAvatarSDKLib = (function (exports) {
|
|
|
14041
14053
|
// 取消所有队列中的任务
|
|
14042
14054
|
this.cancelAllTasks();
|
|
14043
14055
|
// 重置状态
|
|
14044
|
-
this.
|
|
14056
|
+
this.isBroadcastingAudio = false;
|
|
14045
14057
|
this.hasReceivedAudio = false;
|
|
14058
|
+
this.broadcastCompletedCount = 0;
|
|
14046
14059
|
_a.label = 1;
|
|
14047
14060
|
case 1:
|
|
14048
14061
|
_a.trys.push([1, 3,, 4]);
|
|
@@ -14076,27 +14089,32 @@ var ZEEAvatarSDKLib = (function (exports) {
|
|
|
14076
14089
|
* @description 获取当前播报服务的状态信息,包括队列状态
|
|
14077
14090
|
*/
|
|
14078
14091
|
BroadcastService.prototype.getStatus = function () {
|
|
14092
|
+
var completedTasks = this.taskQueue.filter(function (t) {
|
|
14093
|
+
return t.status === BroadcastTaskStatus.COMPLETED;
|
|
14094
|
+
}).length;
|
|
14095
|
+
var requestingTasks = this.taskQueue.filter(function (t) {
|
|
14096
|
+
return t.status === BroadcastTaskStatus.REQUESTING;
|
|
14097
|
+
}).length;
|
|
14098
|
+
var failedTasks = this.taskQueue.filter(function (t) {
|
|
14099
|
+
return t.status === BroadcastTaskStatus.FAILED;
|
|
14100
|
+
}).length;
|
|
14101
|
+
var totalPendingResponses = this.taskQueue.reduce(function (sum, t) {
|
|
14102
|
+
return sum + t.pendingResponses.length;
|
|
14103
|
+
}, 0);
|
|
14104
|
+
var currentSendingSequence = this.currentSendingSequence;
|
|
14105
|
+
var isGeneratingAudio = completedTasks + failedTasks !== this.taskQueue.length;
|
|
14079
14106
|
return {
|
|
14080
|
-
isActive: this.
|
|
14081
|
-
|
|
14107
|
+
isActive: this.isBroadcastingAudio || isGeneratingAudio,
|
|
14108
|
+
// 是否正在播报音频或正在生成音频
|
|
14109
|
+
isGeneratingAudio: isGeneratingAudio,
|
|
14082
14110
|
hasReceivedAudio: this.hasReceivedAudio,
|
|
14083
|
-
pendingCallbacks: this.getPendingCallbackCount(),
|
|
14084
|
-
hasController: this.activeController !== null,
|
|
14085
14111
|
queueInfo: {
|
|
14086
14112
|
totalTasks: this.taskQueue.length,
|
|
14087
|
-
requestingTasks:
|
|
14088
|
-
|
|
14089
|
-
|
|
14090
|
-
|
|
14091
|
-
|
|
14092
|
-
}).length,
|
|
14093
|
-
failedTasks: this.taskQueue.filter(function (t) {
|
|
14094
|
-
return t.status === BroadcastTaskStatus.FAILED;
|
|
14095
|
-
}).length,
|
|
14096
|
-
totalPendingResponses: this.taskQueue.reduce(function (sum, t) {
|
|
14097
|
-
return sum + t.pendingResponses.length;
|
|
14098
|
-
}, 0),
|
|
14099
|
-
currentSendingSequence: this.currentSendingSequence
|
|
14113
|
+
requestingTasks: requestingTasks,
|
|
14114
|
+
completedTasks: completedTasks,
|
|
14115
|
+
failedTasks: failedTasks,
|
|
14116
|
+
totalPendingResponses: totalPendingResponses,
|
|
14117
|
+
currentSendingSequence: currentSendingSequence
|
|
14100
14118
|
}
|
|
14101
14119
|
};
|
|
14102
14120
|
};
|
|
@@ -14106,10 +14124,7 @@ var ZEEAvatarSDKLib = (function (exports) {
|
|
|
14106
14124
|
*/
|
|
14107
14125
|
BroadcastService.prototype.destroy = function () {
|
|
14108
14126
|
// 清理队列处理定时器
|
|
14109
|
-
|
|
14110
|
-
clearInterval(this.queueProcessTimer);
|
|
14111
|
-
this.queueProcessTimer = null;
|
|
14112
|
-
}
|
|
14127
|
+
this.clearQueueProcessTimer();
|
|
14113
14128
|
// 取消所有任务
|
|
14114
14129
|
this.cancelAllTasks();
|
|
14115
14130
|
// 调用基类销毁方法
|
|
@@ -14187,12 +14202,12 @@ var ZEEAvatarSDKLib = (function (exports) {
|
|
|
14187
14202
|
if (nextTask) {
|
|
14188
14203
|
this.sendNextResponse(nextTask);
|
|
14189
14204
|
}
|
|
14190
|
-
//
|
|
14191
|
-
this.
|
|
14192
|
-
|
|
14193
|
-
|
|
14194
|
-
|
|
14195
|
-
this.
|
|
14205
|
+
// 如果队列中没有剩余任务,则停止定时器
|
|
14206
|
+
var remainingTasks = this.taskQueue.filter(function (task) {
|
|
14207
|
+
return task.status !== BroadcastTaskStatus.COMPLETED && task.status !== BroadcastTaskStatus.FAILED && task.status !== BroadcastTaskStatus.CANCELLED;
|
|
14208
|
+
});
|
|
14209
|
+
if (remainingTasks.length === 0) {
|
|
14210
|
+
this.clearQueueProcessTimer();
|
|
14196
14211
|
}
|
|
14197
14212
|
};
|
|
14198
14213
|
/**
|
|
@@ -14271,6 +14286,7 @@ var ZEEAvatarSDKLib = (function (exports) {
|
|
|
14271
14286
|
}
|
|
14272
14287
|
// 处理音频数据
|
|
14273
14288
|
if (response.data) {
|
|
14289
|
+
this.hasReceivedAudio = true;
|
|
14274
14290
|
// 自定义音频播报时,如果服务器未返回音频URL,使用传入的audioUrl
|
|
14275
14291
|
if (task.params.type === exports.BroadcastType.AUDIO && task.params.audioUrl && !response.data.voiceUrl) {
|
|
14276
14292
|
response.data.voiceUrl = task.params.audioUrl;
|
|
@@ -14460,11 +14476,6 @@ var ZEEAvatarSDKLib = (function (exports) {
|
|
|
14460
14476
|
BroadcastService.prototype.handleError = function (error) {
|
|
14461
14477
|
var _a, _b;
|
|
14462
14478
|
this.logger.error('Broadcast error occurred', error);
|
|
14463
|
-
// 清理控制器
|
|
14464
|
-
if (this.activeController) {
|
|
14465
|
-
this.activeController.abort();
|
|
14466
|
-
this.activeController = null;
|
|
14467
|
-
}
|
|
14468
14479
|
// 触发错误回调
|
|
14469
14480
|
(_b = (_a = this.callbacks).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
|
|
14470
14481
|
};
|
|
@@ -14493,6 +14504,17 @@ var ZEEAvatarSDKLib = (function (exports) {
|
|
|
14493
14504
|
break;
|
|
14494
14505
|
}
|
|
14495
14506
|
};
|
|
14507
|
+
/**
|
|
14508
|
+
* 清理队列处理定时器
|
|
14509
|
+
* @description 清理队列处理定时器
|
|
14510
|
+
* @private
|
|
14511
|
+
*/
|
|
14512
|
+
BroadcastService.prototype.clearQueueProcessTimer = function () {
|
|
14513
|
+
if (this.queueProcessTimer) {
|
|
14514
|
+
clearInterval(this.queueProcessTimer);
|
|
14515
|
+
this.queueProcessTimer = null;
|
|
14516
|
+
}
|
|
14517
|
+
};
|
|
14496
14518
|
return BroadcastService;
|
|
14497
14519
|
}(UnityBaseService);
|
|
14498
14520
|
|
package/dist/index.es5.umd.js
CHANGED
|
@@ -13819,14 +13819,14 @@
|
|
|
13819
13819
|
_this.taskSequence = 0;
|
|
13820
13820
|
/** 当前发送任务的序号 */
|
|
13821
13821
|
_this.currentSendingSequence = 0;
|
|
13822
|
-
/**
|
|
13823
|
-
_this.
|
|
13822
|
+
/** 是否正在播报音频 */
|
|
13823
|
+
_this.isBroadcastingAudio = false;
|
|
13824
13824
|
/** 是否已经收到音频 */
|
|
13825
13825
|
_this.hasReceivedAudio = false;
|
|
13826
13826
|
/** 队列处理定时器 */
|
|
13827
13827
|
_this.queueProcessTimer = null;
|
|
13828
|
-
/**
|
|
13829
|
-
_this.
|
|
13828
|
+
/** 播报完成次数 */
|
|
13829
|
+
_this.broadcastCompletedCount = 0;
|
|
13830
13830
|
_this.callbacks = config.callbacks || {};
|
|
13831
13831
|
_this.logger.info('Broadcast service initialized', {
|
|
13832
13832
|
config: config
|
|
@@ -13843,7 +13843,7 @@
|
|
|
13843
13843
|
* @override
|
|
13844
13844
|
*/
|
|
13845
13845
|
BroadcastService.prototype.handleCallback = function (operation, code, message, data) {
|
|
13846
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
13846
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
13847
13847
|
// 提取 isBroadcastCompleted 参数
|
|
13848
13848
|
var isBroadcastCompleted = JSON.parse(data || '{}').isBroadcastCompleted;
|
|
13849
13849
|
// 先调用基类处理逻辑
|
|
@@ -13853,19 +13853,31 @@
|
|
|
13853
13853
|
switch (operation) {
|
|
13854
13854
|
case exports.BroadcastOperationType.START_BROADCAST:
|
|
13855
13855
|
if (isBroadcastCompleted) {
|
|
13856
|
-
|
|
13856
|
+
this.broadcastCompletedCount++;
|
|
13857
|
+
var status_1 = this.getStatus();
|
|
13858
|
+
if (((_a = status_1.queueInfo) === null || _a === void 0 ? void 0 : _a.completedTasks) === this.broadcastCompletedCount) {
|
|
13859
|
+
// 重置状态、计数
|
|
13860
|
+
this.isBroadcastingAudio = false;
|
|
13861
|
+
this.hasReceivedAudio = false;
|
|
13862
|
+
this.currentSendingSequence = 0;
|
|
13863
|
+
// 清理已完成的任务
|
|
13864
|
+
this.cleanupCompletedTasks();
|
|
13865
|
+
this.logger.warn('Broadcast all completed');
|
|
13866
|
+
}
|
|
13867
|
+
// this.logger.warn('AAAAAA', { status: this.getStatus(), broadcastCompletedCount: this.broadcastCompletedCount });
|
|
13868
|
+
(_c = (_b = this.callbacks).onFinish) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
13857
13869
|
}
|
|
13858
13870
|
break;
|
|
13859
13871
|
case exports.BroadcastOperationType.PAUSE_BROADCAST:
|
|
13860
|
-
(
|
|
13872
|
+
(_e = (_d = this.callbacks).onPause) === null || _e === void 0 ? void 0 : _e.call(_d);
|
|
13861
13873
|
this.logger.debug('Broadcast paused callback triggered');
|
|
13862
13874
|
break;
|
|
13863
13875
|
case exports.BroadcastOperationType.RESUME_BROADCAST:
|
|
13864
|
-
(
|
|
13876
|
+
(_g = (_f = this.callbacks).onResume) === null || _g === void 0 ? void 0 : _g.call(_f);
|
|
13865
13877
|
this.logger.debug('Broadcast resumed callback triggered');
|
|
13866
13878
|
break;
|
|
13867
13879
|
case exports.BroadcastOperationType.STOP_BROADCAST:
|
|
13868
|
-
(
|
|
13880
|
+
(_j = (_h = this.callbacks).onStop) === null || _j === void 0 ? void 0 : _j.call(_h);
|
|
13869
13881
|
this.logger.debug('Broadcast stopped callback triggered');
|
|
13870
13882
|
break;
|
|
13871
13883
|
}
|
|
@@ -13936,7 +13948,7 @@
|
|
|
13936
13948
|
});
|
|
13937
13949
|
// 触发开始回调
|
|
13938
13950
|
(_b = (_a = this.callbacks).onStart) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
13939
|
-
this.
|
|
13951
|
+
this.isBroadcastingAudio = true;
|
|
13940
13952
|
_c.label = 2;
|
|
13941
13953
|
case 2:
|
|
13942
13954
|
task = this.createBroadcastTask(params);
|
|
@@ -14044,8 +14056,9 @@
|
|
|
14044
14056
|
// 取消所有队列中的任务
|
|
14045
14057
|
this.cancelAllTasks();
|
|
14046
14058
|
// 重置状态
|
|
14047
|
-
this.
|
|
14059
|
+
this.isBroadcastingAudio = false;
|
|
14048
14060
|
this.hasReceivedAudio = false;
|
|
14061
|
+
this.broadcastCompletedCount = 0;
|
|
14049
14062
|
_a.label = 1;
|
|
14050
14063
|
case 1:
|
|
14051
14064
|
_a.trys.push([1, 3,, 4]);
|
|
@@ -14079,27 +14092,32 @@
|
|
|
14079
14092
|
* @description 获取当前播报服务的状态信息,包括队列状态
|
|
14080
14093
|
*/
|
|
14081
14094
|
BroadcastService.prototype.getStatus = function () {
|
|
14095
|
+
var completedTasks = this.taskQueue.filter(function (t) {
|
|
14096
|
+
return t.status === BroadcastTaskStatus.COMPLETED;
|
|
14097
|
+
}).length;
|
|
14098
|
+
var requestingTasks = this.taskQueue.filter(function (t) {
|
|
14099
|
+
return t.status === BroadcastTaskStatus.REQUESTING;
|
|
14100
|
+
}).length;
|
|
14101
|
+
var failedTasks = this.taskQueue.filter(function (t) {
|
|
14102
|
+
return t.status === BroadcastTaskStatus.FAILED;
|
|
14103
|
+
}).length;
|
|
14104
|
+
var totalPendingResponses = this.taskQueue.reduce(function (sum, t) {
|
|
14105
|
+
return sum + t.pendingResponses.length;
|
|
14106
|
+
}, 0);
|
|
14107
|
+
var currentSendingSequence = this.currentSendingSequence;
|
|
14108
|
+
var isGeneratingAudio = completedTasks + failedTasks !== this.taskQueue.length;
|
|
14082
14109
|
return {
|
|
14083
|
-
isActive: this.
|
|
14084
|
-
|
|
14110
|
+
isActive: this.isBroadcastingAudio || isGeneratingAudio,
|
|
14111
|
+
// 是否正在播报音频或正在生成音频
|
|
14112
|
+
isGeneratingAudio: isGeneratingAudio,
|
|
14085
14113
|
hasReceivedAudio: this.hasReceivedAudio,
|
|
14086
|
-
pendingCallbacks: this.getPendingCallbackCount(),
|
|
14087
|
-
hasController: this.activeController !== null,
|
|
14088
14114
|
queueInfo: {
|
|
14089
14115
|
totalTasks: this.taskQueue.length,
|
|
14090
|
-
requestingTasks:
|
|
14091
|
-
|
|
14092
|
-
|
|
14093
|
-
|
|
14094
|
-
|
|
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
|
|
14116
|
+
requestingTasks: requestingTasks,
|
|
14117
|
+
completedTasks: completedTasks,
|
|
14118
|
+
failedTasks: failedTasks,
|
|
14119
|
+
totalPendingResponses: totalPendingResponses,
|
|
14120
|
+
currentSendingSequence: currentSendingSequence
|
|
14103
14121
|
}
|
|
14104
14122
|
};
|
|
14105
14123
|
};
|
|
@@ -14109,10 +14127,7 @@
|
|
|
14109
14127
|
*/
|
|
14110
14128
|
BroadcastService.prototype.destroy = function () {
|
|
14111
14129
|
// 清理队列处理定时器
|
|
14112
|
-
|
|
14113
|
-
clearInterval(this.queueProcessTimer);
|
|
14114
|
-
this.queueProcessTimer = null;
|
|
14115
|
-
}
|
|
14130
|
+
this.clearQueueProcessTimer();
|
|
14116
14131
|
// 取消所有任务
|
|
14117
14132
|
this.cancelAllTasks();
|
|
14118
14133
|
// 调用基类销毁方法
|
|
@@ -14190,12 +14205,12 @@
|
|
|
14190
14205
|
if (nextTask) {
|
|
14191
14206
|
this.sendNextResponse(nextTask);
|
|
14192
14207
|
}
|
|
14193
|
-
//
|
|
14194
|
-
this.
|
|
14195
|
-
|
|
14196
|
-
|
|
14197
|
-
|
|
14198
|
-
this.
|
|
14208
|
+
// 如果队列中没有剩余任务,则停止定时器
|
|
14209
|
+
var remainingTasks = this.taskQueue.filter(function (task) {
|
|
14210
|
+
return task.status !== BroadcastTaskStatus.COMPLETED && task.status !== BroadcastTaskStatus.FAILED && task.status !== BroadcastTaskStatus.CANCELLED;
|
|
14211
|
+
});
|
|
14212
|
+
if (remainingTasks.length === 0) {
|
|
14213
|
+
this.clearQueueProcessTimer();
|
|
14199
14214
|
}
|
|
14200
14215
|
};
|
|
14201
14216
|
/**
|
|
@@ -14274,6 +14289,7 @@
|
|
|
14274
14289
|
}
|
|
14275
14290
|
// 处理音频数据
|
|
14276
14291
|
if (response.data) {
|
|
14292
|
+
this.hasReceivedAudio = true;
|
|
14277
14293
|
// 自定义音频播报时,如果服务器未返回音频URL,使用传入的audioUrl
|
|
14278
14294
|
if (task.params.type === exports.BroadcastType.AUDIO && task.params.audioUrl && !response.data.voiceUrl) {
|
|
14279
14295
|
response.data.voiceUrl = task.params.audioUrl;
|
|
@@ -14463,11 +14479,6 @@
|
|
|
14463
14479
|
BroadcastService.prototype.handleError = function (error) {
|
|
14464
14480
|
var _a, _b;
|
|
14465
14481
|
this.logger.error('Broadcast error occurred', error);
|
|
14466
|
-
// 清理控制器
|
|
14467
|
-
if (this.activeController) {
|
|
14468
|
-
this.activeController.abort();
|
|
14469
|
-
this.activeController = null;
|
|
14470
|
-
}
|
|
14471
14482
|
// 触发错误回调
|
|
14472
14483
|
(_b = (_a = this.callbacks).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
|
|
14473
14484
|
};
|
|
@@ -14496,6 +14507,17 @@
|
|
|
14496
14507
|
break;
|
|
14497
14508
|
}
|
|
14498
14509
|
};
|
|
14510
|
+
/**
|
|
14511
|
+
* 清理队列处理定时器
|
|
14512
|
+
* @description 清理队列处理定时器
|
|
14513
|
+
* @private
|
|
14514
|
+
*/
|
|
14515
|
+
BroadcastService.prototype.clearQueueProcessTimer = function () {
|
|
14516
|
+
if (this.queueProcessTimer) {
|
|
14517
|
+
clearInterval(this.queueProcessTimer);
|
|
14518
|
+
this.queueProcessTimer = null;
|
|
14519
|
+
}
|
|
14520
|
+
};
|
|
14499
14521
|
return BroadcastService;
|
|
14500
14522
|
}(UnityBaseService);
|
|
14501
14523
|
|
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.
|
|
1559
|
+
/** 是否正在播报音频 */
|
|
1560
|
+
this.isBroadcastingAudio = false;
|
|
1561
1561
|
/** 是否已经收到音频 */
|
|
1562
1562
|
this.hasReceivedAudio = false;
|
|
1563
1563
|
/** 队列处理定时器 */
|
|
1564
1564
|
this.queueProcessTimer = null;
|
|
1565
|
-
/**
|
|
1566
|
-
this.
|
|
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
|
-
|
|
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
|
-
(
|
|
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
|
-
(
|
|
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
|
-
(
|
|
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.
|
|
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.
|
|
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.
|
|
1772
|
-
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
|
|
1779
|
-
completedTasks
|
|
1780
|
-
failedTasks
|
|
1781
|
-
totalPendingResponses
|
|
1782
|
-
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
|
-
|
|
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.
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
this.
|
|
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;
|
|
@@ -2100,11 +2115,6 @@ class BroadcastService extends UnityBaseService {
|
|
|
2100
2115
|
handleError(error) {
|
|
2101
2116
|
var _a, _b;
|
|
2102
2117
|
this.logger.error('Broadcast error occurred', error);
|
|
2103
|
-
// 清理控制器
|
|
2104
|
-
if (this.activeController) {
|
|
2105
|
-
this.activeController.abort();
|
|
2106
|
-
this.activeController = null;
|
|
2107
|
-
}
|
|
2108
2118
|
// 触发错误回调
|
|
2109
2119
|
(_b = (_a = this.callbacks).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
|
|
2110
2120
|
}
|
|
@@ -2133,6 +2143,17 @@ class BroadcastService extends UnityBaseService {
|
|
|
2133
2143
|
break;
|
|
2134
2144
|
}
|
|
2135
2145
|
}
|
|
2146
|
+
/**
|
|
2147
|
+
* 清理队列处理定时器
|
|
2148
|
+
* @description 清理队列处理定时器
|
|
2149
|
+
* @private
|
|
2150
|
+
*/
|
|
2151
|
+
clearQueueProcessTimer() {
|
|
2152
|
+
if (this.queueProcessTimer) {
|
|
2153
|
+
clearInterval(this.queueProcessTimer);
|
|
2154
|
+
this.queueProcessTimer = null;
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2136
2157
|
}
|
|
2137
2158
|
|
|
2138
2159
|
/**
|