fix(station): remove arrival and departure preview audio flow

Delete the station-side arrival/departure announcement requests and drop the server handlers for train arrival, train departure, and play_sequence messages so preview audio no longer interrupts live music.
This commit is contained in:
2026-07-31 21:53:12 +08:00
parent fd154afd82
commit 218aaabb50
2 changed files with 1 additions and 307 deletions
-132
View File
@@ -1370,18 +1370,9 @@ function handleMessage(ws, data) {
case 'station_register':
handleStationRegister(ws, data);
break;
case 'train_arrival':
handleTrainArrival(data);
break;
case 'train_departure':
handleTrainDeparture(data);
break;
case 'request_station_time':
handleStationTimeRequest(ws, data);
break;
case 'play_sequence':
handlePlaySequence(ws, data);
break;
case 'request_list_txt':
// TODO: Send list.txt content
break;
@@ -1393,33 +1384,6 @@ function handleMessage(ws, data) {
}
}
function getDestinationFromSchedule(schedule) {
if (!schedule || !schedule.entries) return "Unknown";
const entries = schedule.entries;
let dest = "Unknown";
// Convert entries to array if it's an object with numeric keys
const entryList = Array.isArray(entries) ? entries : Object.values(entries);
// 1. Look for explicit destination instructions
for (const entry of entryList) {
if (entry.instruction?.id === 'create:destination') {
dest = entry.instruction.data?.text || entry.instruction.text || dest;
}
}
// 2. If still Unknown, find the very last station instruction
if (dest === "Unknown") {
for (let i = entryList.length - 1; i >= 0; i--) {
if (entryList[i].instruction?.id === 'create:station') {
dest = entryList[i].instruction.data?.text || entryList[i].instruction.text || dest;
break;
}
}
}
return dest;
}
function getCorrectStationName(name) {
const cleanName = String(name || '').trim();
const station = findStationByFlexibleName(cleanName);
@@ -1483,40 +1447,6 @@ function handleStationRegister(ws, data) {
broadcastUpdate();
}
function handleTrainArrival(data) {
let { trainId, stationName, arrivalTime, destination, source, schedule } = data;
stationName = getCorrectStationName(stationName);
const baseId = getBaseTrainId(trainId);
const cooldownKey = `${baseId}|${stationName}|arrival`;
const lastEventTime = trainEventCooldown.get(cooldownKey);
if (lastEventTime && Date.now() - lastEventTime < 45000) return;
trainEventCooldown.set(cooldownKey, Date.now());
log('INFO', `Train ${trainId} (Consist ${baseId}) arrived at ${stationName}`);
// Add or update active train using base ID to group cars
const existingIndex = activeTrains.findIndex(t => getBaseTrainId(t.trainId) === baseId);
// Create history entry
let trainData = {
trainId,
currentStation: stationName,
destination: destination || (existingIndex >= 0 ? activeTrains[existingIndex].destination : "Unknown"),
status: "At Station",
lastUpdate: Date.now(),
schedule: schedule || (existingIndex >= 0 ? activeTrains[existingIndex].schedule : null)
};
if (existingIndex >= 0) {
activeTrains[existingIndex] = { ...activeTrains[existingIndex], ...trainData };
} else {
activeTrains.push(trainData);
}
broadcastUpdate();
}
function getBaseName(name) {
if (!name) return "";
return String(name).toLowerCase()
@@ -1599,68 +1529,6 @@ function findStationByFlexibleName(targetName) {
return null;
}
function handleTrainDeparture(data) {
let { trainId, stationName, destination, schedule, source } = data;
stationName = getCorrectStationName(stationName);
const baseId = getBaseTrainId(trainId);
const cooldownKey = `${baseId}|${stationName}|departure`;
const lastEventTime = trainEventCooldown.get(cooldownKey);
if (lastEventTime && Date.now() - lastEventTime < 45000) return;
trainEventCooldown.set(cooldownKey, Date.now());
log('INFO', `Train ${trainId} (Consist ${baseId}) departed from ${stationName}`);
const existingIndex = activeTrains.findIndex(t => getBaseTrainId(t.trainId) === baseId);
if (existingIndex >= 0) {
const train = activeTrains[existingIndex];
train.status = "Departed";
train.currentStation = stationName;
train.lastUpdate = Date.now();
train.lastStation = stationName;
train.departureTime = Date.now();
train.destination = destination || train.destination;
train.schedule = schedule || train.schedule;
}
broadcastUpdate();
}
function handlePlaySequence(ws, data) {
const { stationName, seq, requestId } = data;
const cleanStation = stationName.trim();
const correctStation = getCorrectStationName(cleanStation);
const streamName = getStationStreamName(cleanStation);
const hlsUrl = getStationHlsUrl(streamName);
log('INFO', `Playing sequence for ${correctStation}: ${seq.join(', ')}`);
const builtAudio = buildSequenceWavFile(seq);
if (builtAudio) {
const priority = Number.isFinite(Number(data.priority))
? Number(data.priority)
: (String(data.category || '').toLowerCase() === 'station' ? 0 : 1);
const interruptMode = data.interruptMode || getInterruptModeForPriority(priority);
const source = data.source || data.category || 'sequence';
const audioId = String(requestId || `${Date.now()}-${Math.random().toString(16).slice(2)}`);
enqueueStationAudioTask(cleanStation, ws, {
audioFormat: builtAudio.audioFormat,
streamUrl: builtAudio.streamUrl,
durationSec: builtAudio.durationSec,
priority,
interruptMode,
source,
audioId,
requeueOnPreempt: priority <= 0,
consoleStreamStart: { type: 'stream_start', station: cleanStation, seq: seq, streamName, hlsUrl },
consoleStreamEnd: { type: 'stream_end', station: cleanStation }
});
} else {
log('WARN', `Unable to build WAV sequence for ${cleanStation}`);
}
}
function handleStationTimeRequest(ws, data) {
// Simple logic: default to 60s or lookup schedule
const stationTime = 60;