fix: 终点站到达时下一站广播播放异常 + getNextStation 不回绕起点
1. Utils.getNextStation: 移除终点站回绕到起点的逻辑(非环线)
- 此前当前站是 END 时会从 schedule.entries 开头再找,把起点当下一站
- 修复后在终点站返回 nil,明确表示无后续站
2. 服务端 handleTrainArrival: 智能区分普通站/终点站广播序列
- 新增 hasNextStation / finalNextCode 判断:只有当下一站有效时
才在 seq 中插入 ch-nextsta + ch- 片段
- 终点站(finalNextCode 为 null):直接删除 nextsta 和下一站代码,
仅保留 站台-站台-线路-方向-终点站-警示 片段
- 避免 ch-UNK 等无效资源或回绕起点站名被播放
3. 日志增强:arrival 处理时额外打印 nextStation 和 nextCode,
便于快速确认服务端是否收到正确的下一站信息
版本号 v1.0.69 -> v1.0.70
This commit is contained in:
+17
-7
@@ -2139,7 +2139,10 @@ function handleTrainArrival(ws, data) {
|
||||
|
||||
const lineCode = data.lineCode || (stationCode ? stationCode.split('-')[0] : 'UNK');
|
||||
const destCode = data.destCode || getStationCodeFromName(data.destination) || 'UNK';
|
||||
const nextCode = data.nextCode || getStationCodeFromName(data.nextStation) || 'UNK';
|
||||
const nextStationRaw = data.nextStation ? String(data.nextStation).trim() : '';
|
||||
const nextCodeRaw = data.nextCode ? String(data.nextCode).trim() : (nextStationRaw ? getStationCodeFromName(nextStationRaw) : '');
|
||||
const hasNextStation = nextStationRaw && nextStationRaw !== '' && nextCodeRaw && nextCodeRaw !== 'UNK' && nextCodeRaw !== '';
|
||||
const finalNextCode = hasNextStation ? nextCodeRaw : null;
|
||||
|
||||
const existingIndex = activeTrains.findIndex(t => t.trainId === trainId);
|
||||
const trainData = {
|
||||
@@ -2155,7 +2158,7 @@ function handleTrainArrival(ws, data) {
|
||||
activeTrains.push(trainData);
|
||||
}
|
||||
|
||||
log('INFO', `Train ${trainId} arrived at ${stationName}. Broadcasting...`);
|
||||
log('INFO', `Train ${trainId} arrived at ${stationName}. Broadcasting... nextStation=${nextStationRaw || '(none/terminal)'} nextCode=${finalNextCode || '(none)'}`);
|
||||
saveData();
|
||||
broadcastUpdate();
|
||||
|
||||
@@ -2173,11 +2176,18 @@ function handleTrainArrival(ws, data) {
|
||||
}));
|
||||
|
||||
// Broadcast Audio Logic
|
||||
const seq = [
|
||||
'ksts',
|
||||
`ja-${finalPlatform}`, 'ja-zt', `ja-${lineCode}`, `ja-${destCode}`, 'ja-to', 'ja-nextsta', `ja-${nextCode}`, 'ja-warn',
|
||||
`ch-${finalPlatform}`, 'ch-zt', `ch-${lineCode}`, 'ch-to', `ch-${destCode}`, 'ch-nextsta', `ch-${nextCode}`, 'ch-warn'
|
||||
];
|
||||
const seq = ['ksts'];
|
||||
if (finalNextCode) {
|
||||
seq.push(
|
||||
`ja-${finalPlatform}`, 'ja-zt', `ja-${lineCode}`, `ja-${destCode}`, 'ja-to', 'ja-nextsta', `ja-${finalNextCode}`, 'ja-warn',
|
||||
`ch-${finalPlatform}`, 'ch-zt', `ch-${lineCode}`, 'ch-to', `ch-${destCode}`, 'ch-nextsta', `ch-${finalNextCode}`, 'ch-warn'
|
||||
);
|
||||
} else {
|
||||
seq.push(
|
||||
`ja-${finalPlatform}`, 'ja-zt', `ja-${lineCode}`, `ja-${destCode}`, 'ja-warn',
|
||||
`ch-${finalPlatform}`, 'ch-zt', `ch-${lineCode}`, 'ch-to', `ch-${destCode}`, 'ch-warn'
|
||||
);
|
||||
}
|
||||
|
||||
enqueueHlsPush(stationName, seq);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user