fix(sync): coalesce play/pause bursts and quiet absent-peer ACK logs

Media players fire bursts of native play/pause events (source swaps, ABR,
ads, teardown). Each was relayed as a distinct command, spamming peers and
tripping the relay's event rate limit. Add leading+trailing coalescing in
the content script: emit the first event instantly (zero added latency) and,
on a 150ms window, collapse a burst to its final state. Echo-suppression and
seek-flush stay synchronous on event arrival; the trailing send is never
deduped against the leading one (a remote command may change shared state
mid-window — re-sending is the safe, idempotent choice).

Server: split the EVENT_ACK handler's logging so only a genuine different-room
ACK is logged as [SECURITY]; an ACK to a peer that already left is logged
quietly as [ACKDROP] (verbose-only), so real signals are no longer drowned out.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Timo
2026-06-19 16:26:31 +02:00
parent a0c16df664
commit 027d2dbde5
2 changed files with 102 additions and 19 deletions
+9 -3
View File
@@ -150,7 +150,7 @@ const peerJoinLocks = new Map(); // peerId -> Promise (prevents race on same pee
function log(type, message, details = '') {
const debugLogging = process.env.DEBUG_LOGGING === '1';
const isVerbose = type === 'CONN' || type === 'ROOM' || type === 'DEDUPE' || type === 'CORS';
const isVerbose = type === 'CONN' || type === 'ROOM' || type === 'DEDUPE' || type === 'CORS' || type === 'ACKDROP';
if (!debugLogging && isVerbose) return;
const timestamp = new Date().toISOString();
@@ -569,12 +569,18 @@ io.on('connection', (socket) => {
// Security: Only relay ACK if both peers are in the same room
if (senderMapping && targetMapping && senderMapping.roomId === targetMapping.roomId) {
io.to(targetSocketId).emit(EVENTS.EVENT_ACK, {
io.to(targetSocketId).emit(EVENTS.EVENT_ACK, {
senderId: senderMapping.peerId,
actionTimestamp: data.actionTimestamp
});
} else {
} else if (senderMapping && targetMapping) {
// Both peers exist but live in different rooms — genuinely suspicious.
log('SECURITY', `Blocked cross-room ACK attempt from ${socket.id} to ${data.targetId}`);
} else {
// Benign + common: sender or target left/disconnected before the ACK
// arrived (a command was in-flight when they went). Not an attack —
// log quietly (verbose only) so it doesn't drown out real signals.
log('ACKDROP', `Dropped ACK from ${socket.id} to absent peer ${data.targetId}`);
}
});