perf: WebSocket只在状态变化时广播,减少无效消息
This commit is contained in:
@@ -136,11 +136,10 @@ function startCarouselTimer() {
|
|||||||
const startTime = parseInt(getConfig('current_group_start_time') || '0');
|
const startTime = parseInt(getConfig('current_group_start_time') || '0');
|
||||||
const currentGroup = groups[idx];
|
const currentGroup = groups[idx];
|
||||||
|
|
||||||
if (currentGroup.display_seconds === 0) {
|
// 无限时分组,不需要切换
|
||||||
broadcastState();
|
if (currentGroup.display_seconds === 0) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 首次启动,记录开始时间并广播
|
||||||
if (startTime === 0) {
|
if (startTime === 0) {
|
||||||
setConfig('current_group_start_time', Math.floor(Date.now() / 1000));
|
setConfig('current_group_start_time', Math.floor(Date.now() / 1000));
|
||||||
broadcastState();
|
broadcastState();
|
||||||
@@ -150,12 +149,13 @@ function startCarouselTimer() {
|
|||||||
const now = Math.floor(Date.now() / 1000);
|
const now = Math.floor(Date.now() / 1000);
|
||||||
const elapsed = now - startTime;
|
const elapsed = now - startTime;
|
||||||
|
|
||||||
|
// 时间到了,切换分组并广播
|
||||||
if (elapsed >= currentGroup.display_seconds) {
|
if (elapsed >= currentGroup.display_seconds) {
|
||||||
const nextIdx = findNextGroupIndex(groups, idx);
|
const nextIdx = findNextGroupIndex(groups, idx);
|
||||||
setConfig('current_group_index', nextIdx);
|
setConfig('current_group_index', nextIdx);
|
||||||
setConfig('current_group_start_time', Math.floor(Date.now() / 1000));
|
setConfig('current_group_start_time', Math.floor(Date.now() / 1000));
|
||||||
}
|
|
||||||
broadcastState();
|
broadcastState();
|
||||||
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user