fix(audio): call a new leader only when the change is confirmed, not at every qualifying swap (1.65.4)

This commit is contained in:
larssand committed 2026-11-05 19:38:37 +01:00
1 parent 13f32fc0d6
commit fed83ddf67
7 files changed
+72 -7

No files matched your search

+6
View File
@@ -8,6 +8,12 @@ The application version is maintained in `package.json` and displayed in the adm
No changes recorded yet.
## 1.65.4 - 2026-11-05
### Fixed
- "New race leader" was called at nearly every lap in qualifying: with a clock per driver the live order goes by laps and then each driver's own time, so the lead swaps at every crossing (B reaches 4 laps in less time than A, then A reaches 5). A new leader is now called only once confirmed: the previous leader has crossed the line since and the new one still leads (a real pass), or the new one has led for a minute. The 2-minute "X leads, N laps" call follows the confirmed leader too.
## 1.65.3 - 2026-11-05
### Fixed
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "rc-racecore",
"version": "1.65.3",
"version": "1.65.4",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "rc-racecore",
"version": "1.65.3",
"version": "1.65.4",
"hasInstallScript": true,
"dependencies": {
"better-sqlite3": "^12.11.1",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "rc-racecore",
"version": "1.65.3",
"version": "1.65.4",
"private": true,
"description": "RC RaceCore live timing and race control with AMMC ingest and SQLite persistence",
"engines": {
+11 -4
View File
@@ -5,6 +5,7 @@ import { isSuspectLap, getSuspectReferenceLaps, releaseSettledSuspectLaps } from
import { shouldCallPracticePersonalBest } from "./practice_callouts_logic.js";
import { normalizeRaceAudioSettings, formatSpokenLapTime, formatShortLapCall, LEADER_UPDATE_INTERVAL_MS } from "./race_audio.js";
import { findDriverByCarTransponder } from "./sponsor_event_logic.js";
import { confirmLeaderChange } from "./leader_call_logic.js";
import { pickPracticeHype, getDriverLapTimes, getClassRank, getLastTimeBestMs, findDuelRival } from "./practice_hype_logic.js";
import { decoderClockCheck, describeDecoderClockSkew } from "./decoder_clock_check.js";
import { getCompetitorEndTs } from "./timing_logic.js";
@@ -14,6 +15,7 @@ const PRACTICE_SESSION_TYPES = new Set(["open_practice", "free_practice", "pract
const lastPracticePbCall = new Map();
const practiceHypeMemory = new Map();
const lastLeaderCallBySession = new Map();
const leaderMemoryByHeat = new Map();
const spokenName = (row) => row?.speechName || row?.displayName || row?.driverName || "";
// Practice hype (practice_hype_logic.js): gathers this lap's numbers and returns at most one
@@ -688,17 +690,22 @@ export function processDecoderMessageHelper(msg, deps, decoderRole = "main") {
if (leader?.key && lastOverlayLeaderKeyBySession[session.id] !== leader.key) {
lastOverlayLeaderKeyBySession[session.id] = leader.key;
pushOverlayEvent("leader", `${leader.displayName || leader.driverName} • P1`);
// Qualifying and finals: no leader calls in the first 30 s (everyone swaps places on the
// first lap) and at most one every 10 s.
}
// "New race leader" only for a confirmed change (leader_call_logic.js), not for every swap
// of the live order. Qualifying and finals: not in the first 30 s, at most one every 10 s.
const heatKey = `${session.id}:${Number(session.startedAt || 0)}:${Number(session.resultsResetAt || 0)}`;
if (!leaderMemoryByHeat.has(heatKey)) leaderMemoryByHeat.set(heatKey, previousLeaderKey ? { called: previousLeaderKey } : {});
const confirmedLeaderKey = confirmLeaderChange(leaderMemoryByHeat.get(heatKey), { leaderKey: leader?.key, passingKey: key });
{
const settled = isPracticeSession || Date.now() - Number(session.startedAt || 0) >= 30000;
if (previousLeaderKey && previousLeaderKey !== leader.key && settled) {
if (confirmedLeaderKey && settled) {
const raceScope = isPracticeSession ? {} : { scope: `leader:${session.id}`, cooldownMs: 10000 };
const call = triggerRaceAudio("new_leader", { ...raceScope, variables: { driverName: spokenName(leader) }, driverId: leader.driverId, competitorKey: leader.key, logData: { raceId: session.eventId, driverId: leader.driverId } });
if (!call?.skipped) lastLeaderCallBySession.set(session.id, Date.now());
}
}
// Qualifying and finals: "Anders leads, 12 laps" when the leader crosses the line, every 2 minutes.
if (!isPracticeSession && leader?.key === key && !entry.finishedAt) {
if (!isPracticeSession && leader?.key === key && leaderMemoryByHeat.get(heatKey)?.called === key && !entry.finishedAt) {
if (!lastLeaderCallBySession.has(session.id)) lastLeaderCallBySession.set(session.id, Date.now());
else if (Date.now() - lastLeaderCallBySession.get(session.id) >= LEADER_UPDATE_INTERVAL_MS) {
lastLeaderCallBySession.set(session.id, Date.now());
+23
View File
@@ -0,0 +1,23 @@
// When to call "New race leader". With a clock per driver (qualifying, staggered or flying
// start) the live order goes by laps, then each driver's own time, so the lead swaps at every
// crossing: B gets to 4 laps in less time than A and leads, A gets to 5 and leads again. A new
// leader is only called once it is confirmed: the called leader has crossed the line since
// and the new one still leads, or the new one has led for a minute (the old one stopped).
const CONFIRM_AFTER_MS = 60000;
// memory: one object per heat, kept by the caller. Returns the leader key to call, or null.
export function confirmLeaderChange(memory, { leaderKey, passingKey, now = Date.now() }) {
if (!leaderKey) return null;
if (!memory.called) { memory.called = leaderKey; return null; } // the first leader is not a change
if (leaderKey === memory.called) { memory.pending = null; return null; }
if (!memory.pending || memory.pending.key !== leaderKey) {
memory.pending = { key: leaderKey, since: now };
return null;
}
if (passingKey === memory.called || now - memory.pending.since >= CONFIRM_AFTER_MS) {
memory.called = leaderKey;
memory.pending = null;
return leaderKey;
}
return null;
}
+28
View File
@@ -0,0 +1,28 @@
import test from "node:test";
import assert from "node:assert/strict";
import { confirmLeaderChange } from "../src/leader_call_logic.js";
test("qualifying swaps at every crossing are not called as new leaders", () => {
const memory = {};
assert.equal(confirmLeaderChange(memory, { leaderKey: "A", passingKey: "A", now: 0 }), null, "first leader is not a change");
// B reaches 4 laps in less time: leads until A crosses for lap 5.
assert.equal(confirmLeaderChange(memory, { leaderKey: "B", passingKey: "B", now: 18000 }), null);
assert.equal(confirmLeaderChange(memory, { leaderKey: "A", passingKey: "A", now: 19000 }), null);
assert.equal(confirmLeaderChange(memory, { leaderKey: "B", passingKey: "B", now: 36000 }), null);
assert.equal(confirmLeaderChange(memory, { leaderKey: "A", passingKey: "A", now: 37000 }), null);
});
test("a real pass is called once the old leader has crossed behind", () => {
const memory = {};
confirmLeaderChange(memory, { leaderKey: "A", passingKey: "A", now: 0 });
assert.equal(confirmLeaderChange(memory, { leaderKey: "B", passingKey: "B", now: 18000 }), null);
assert.equal(confirmLeaderChange(memory, { leaderKey: "B", passingKey: "C", now: 18500 }), null, "a third car crossing confirms nothing");
assert.equal(confirmLeaderChange(memory, { leaderKey: "B", passingKey: "A", now: 19000 }), "B");
assert.equal(confirmLeaderChange(memory, { leaderKey: "B", passingKey: "B", now: 36000 }), null, "called once");
});
test("a leader that stops is replaced after a minute", () => {
const memory = { called: "A" };
assert.equal(confirmLeaderChange(memory, { leaderKey: "B", passingKey: "B", now: 0 }), null);
assert.equal(confirmLeaderChange(memory, { leaderKey: "B", passingKey: "B", now: 60000 }), "B");
});
+1
View File
@@ -1,4 +1,5 @@
import "./auth.test.js";
import "./leader_call_logic.test.js";
import "./decoder_sim.test.js";
import "./sponsor_event.test.js";
import "./practice_hype.test.js";