feat: Add train pre-arrival broadcast via CRN create_target
This commit is contained in:
@@ -1687,6 +1687,9 @@ function handleMessage(ws, data) {
|
||||
case 'train_arrival':
|
||||
handleTrainArrival(ws, data);
|
||||
break;
|
||||
case 'train_approaching':
|
||||
handleTrainApproaching(ws, data);
|
||||
break;
|
||||
case 'train_departure':
|
||||
handleTrainDeparture(ws, data);
|
||||
break;
|
||||
@@ -1854,6 +1857,53 @@ function findStationByFlexibleName(targetName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function handleTrainApproaching(ws, data) {
|
||||
const trainId = data.trainId;
|
||||
const stationName = getCorrectStationName(data.stationName);
|
||||
const stationCode = data.stationCode;
|
||||
const platform = data.stationPlatform || data.platform || '1';
|
||||
|
||||
const destCode = data.destCode || getStationCodeFromName(data.destination) || 'UNK';
|
||||
|
||||
log('INFO', `Train ${trainId} approaching ${stationName}. Broadcasting pre-arrival...`);
|
||||
|
||||
ws.send(JSON.stringify({
|
||||
type: 'train_approaching_ack',
|
||||
success: true,
|
||||
message: 'Train approaching processed successfully',
|
||||
trainId
|
||||
}));
|
||||
|
||||
// Pre-arrival Audio Logic
|
||||
// 提示音:ksts
|
||||
// 日文:ja-fc1 + ja-站台编号 + ja-fc2 + ja-终点编号 + ja-fc3
|
||||
// 中文:ch-fc1 + ch-fc2 + ch-fc3 + ch-终点编号 + ch-fc4
|
||||
const seq = [
|
||||
'ksts',
|
||||
'ja-fc1', `ja-${platform}`, 'ja-fc2', `ja-${destCode}`, 'ja-fc3',
|
||||
'ch-fc1', 'ch-fc2', 'ch-fc3', `ch-${destCode}`, 'ch-fc4'
|
||||
];
|
||||
|
||||
enqueueHlsPush(stationName, seq);
|
||||
|
||||
const audioId = `approaching-${stationCode}-${Date.now()}`;
|
||||
const built = buildSequenceWavFile(seq);
|
||||
if (built) {
|
||||
enqueueStationAudioTask(stationName, ws, {
|
||||
audioFormat: built.audioFormat,
|
||||
sourcePath: built.sourcePath,
|
||||
streamUrl: built.streamUrl,
|
||||
durationSec: built.durationSec,
|
||||
priority: 1,
|
||||
interruptMode: 'ifLower',
|
||||
source: 'train_approaching',
|
||||
audioId,
|
||||
consoleStreamStart: { type: 'stream_start', station: stationName, seq, streamName: getStationStreamName(stationName), hlsUrl: getStationHlsUrl(getStationStreamName(stationName)) },
|
||||
consoleStreamEnd: { type: 'stream_end', station: stationName }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function handleTrainArrival(ws, data) {
|
||||
const trainId = data.trainId;
|
||||
const stationName = getCorrectStationName(data.stationName);
|
||||
|
||||
Reference in New Issue
Block a user