WIP III improve UX [snapshot task 2]

This commit is contained in:
Schluffe committed 2026-10-16 16:09:43 +02:00
1 parent b2bab26981
commit 28c90d1d71
5 files changed
+97 -2

No files matched your search

+2 -1
View File
@@ -75,7 +75,8 @@ failures; if a configured STUN server is unreachable, try None for a local test.
Expand **Connection diagnostics** to copy the last 80 timed events. The log
retains local/remote candidate type counts, candidate-pair states, selected
route types, and ICE check request/response counters after failure. Final stats
route types, DTLS transport states, and ICE check request/response counters after failure.
Four snapshots during ICE checking preserve evidence before failed pairs disappear. Final stats
are requested before closing the peer, with a 300 ms cleanup bound. A `?` means
the browser did not supply a counter; it does not mean zero. Addresses, raw SDP,
candidate IDs, credentials, server URLs and filenames are excluded.
+33
View File
@@ -65,3 +65,36 @@ sent with no responses are distinct observations, not diagnoses by themselves.
Do not change firewall rules or shorten user copy/paste time based only on the
same-machine tests. The original/current comparison has not yet identified a
code change that demonstrably explains the user's physical-device failures.
## Two Brave peers on different networks, subsequent report
The reported setup is the same two devices/networks used for the first-version
trial. In the new logs both peers gather two host candidates and one srflx
candidate, with no relay. Neither reports a connected state or transfer activity.
The sender's sole live snapshot is immediately after applying the answer: one
in-progress pair, one request sent, and zero responses so far. This is not a
snapshot of the whole failed attempt. Both final snapshots have no candidate
pairs; the browser has already discarded the useful evidence.
Each log has its own time origin. Sender “answer applied at 25.8 s” cannot be
compared directly with receiver “failed at 15.1 s” to establish whether the answer
was applied before or after receiver failure. A 701 event with a gathered srflx
candidate also does not identify the reason the peer connection failed.
The v3 UX work changed the signaling envelope version, not candidate gathering or
the SDP applied to the browser. The original default STUN provider was Google;
the current default is PageQuit. Matching that selection is necessary for an
original/current comparison, even with unchanged devices and networks.
Diagnostics now sample candidate-pair counters at 3, 6, 9 and 12 seconds while ICE
is checking, and include allowlisted DTLS transport states. Sampling stops when
checking ends or the session is disposed. Receiver answer creation also takes a
snapshot. These changes improve evidence collection; they are not a demonstrated
fix for the physical-device connection failure.
The isolated comparison was also rerun with `/usr/bin/brave`: original, current,
and current-without-immediate-cleanup all delivered the fixed probe at roughly
20.25 seconds after a deliberate 20-second answer delay. In this local test the
receiver did not report checking until the delayed answer was applied on the
sender, unlike the reported physical-device attempt. It does not reproduce that
attempt or establish that its answer-exchange timing is safe.
+4 -1
View File
@@ -219,7 +219,9 @@ function start() {
if (['failed', 'closed'].includes(pc.connectionState)) {
const unfinished = [sendState.value, receiveState.value].some(state => state && state !== 'done' && state !== 'closed');
if (connected.value && !unfinished) disconnect();
else fail(session, new Error('Connection failed. Unfinished files were cancelled. Direct connections may be blocked; TURN is available only if both people opt in.'));
else fail(session, new Error(connected.value
? 'Connection lost. Unfinished files were cancelled. Exchange fresh codes to reconnect.'
: 'Could not establish the peer connection. Retry with fresh codes. If it fails again, copy Connection diagnostics from both devices.'));
}
};
return session;
@@ -245,6 +247,7 @@ async function createCode() {
outputCode.value = code;
session.diagnostics.record(props.sending ? 'offer ready' : 'answer ready');
session.diagnostics.descriptions();
void session.diagnostics.capture();
if (!props.sending) fps.value = getFingerprints(session.pc, options);
step.value = props.sending ? 'offer-ready' : 'answer-ready';
} catch (err) {
+25
View File
@@ -43,6 +43,9 @@ export function summarizeStats(stats: Stats): string[] {
lines.push(`pair ${endpoint(pair.localCandidateId)} → ${endpoint(pair.remoteCandidateId)} ${category(pair.state, pairStates)}` +
` selected=${isSelected(pair)} nominated=${pair.nominated === true} ` + counters.map(key => `${key}=${count(pair[key])}`).join(' '));
}
stats.forEach((entry: StatsEntry) => {
if (entry.type === 'transport') lines.push(`transport dtls=${category(entry.dtlsState, ['new', 'connecting', 'connected', 'closed', 'failed'])}`);
});
if (pairs.length > 12) lines.push(`pairs omitted=${pairs.length - 12}`);
return lines;
}
@@ -51,6 +54,8 @@ export class ConnectionDiagnostics {
readonly lines: string[] = [];
private readonly started = performance.now();
private stopped = false;
private sampleTimers: ReturnType<typeof setTimeout>[] = [];
private samplingStarted = false;
private finishing: Promise<void> | undefined;
private readonly listeners: Array<[EventTarget, string, EventListener]> = [];
private readonly pc: RTCPeerConnection;
@@ -62,6 +67,7 @@ export class ConnectionDiagnostics {
this.listeners.push([target, event, listener]);
};
const state = () => {
this.sampleWhileChecking();
this.record(`pc=${category(pc.connectionState, ['new', 'connecting', 'connected', 'disconnected', 'failed', 'closed'])} ice=${category(pc.iceConnectionState, ['new', 'checking', 'connected', 'completed', 'disconnected', 'failed', 'closed'])} gathering=${category(pc.iceGatheringState, ['new', 'gathering', 'complete'])}`);
};
for (const event of ['connectionstatechange', 'iceconnectionstatechange', 'icegatheringstatechange']) listen(pc, event, state);
@@ -73,6 +79,23 @@ export class ConnectionDiagnostics {
}
state();
}
private sampleWhileChecking() {
if (this.stopped || this.finishing) return;
if (this.pc.iceConnectionState !== 'checking') {
for (const timer of this.sampleTimers) clearTimeout(timer);
this.sampleTimers = [];
return;
}
if (this.samplingStarted) return;
this.samplingStarted = true;
// Preserve evidence before browsers discard failed candidate pairs. Four
// bounded snapshots cover short setup failures without polling indefinitely.
this.sampleTimers = [3000, 6000, 9000, 12000].map(delay => setTimeout(() => {
if (this.stopped || this.finishing || this.pc.iceConnectionState !== 'checking') return;
this.record('connectivity sample');
void this.capture();
}, delay));
}
record(message: string) {
if (this.stopped) return;
this.lines.push(`${((performance.now() - this.started) / 1000).toFixed(1)}s ${message}`);
@@ -98,6 +121,8 @@ export class ConnectionDiagnostics {
// Request final stats while the connection is alive. Always close, even when
// getStats rejects or hangs. Reset can start a new session during this wait.
finish(close: () => void) {
for (const timer of this.sampleTimers) clearTimeout(timer);
this.sampleTimers = [];
return this.finishing ??= this.capture().finally(() => {
this.stopped = true;
for (const [target, event, listener] of this.listeners) target.removeEventListener(event, listener);
+33
View File
@@ -71,3 +71,36 @@ test('event history remains bounded', () => {
for (let i = 0; i < 100; i++) peer.dispatchEvent(new Event('iceconnectionstatechange'));
assert.equal(diagnostics.lines.length, 80);
});
test('checking snapshots retain live pairs before failure removes them', async t => {
t.mock.timers.enable({ apis: ['setTimeout'] });
const peer = new Peer();
peer.connectionState = 'connecting'; peer.iceConnectionState = 'checking';
let calls = 0;
peer.getStats = async () => { calls++; return new Map([
['pair', { type: 'candidate-pair', state: 'in-progress', requestsSent: 5, responsesReceived: 0 }],
['transport', { type: 'transport', dtlsState: 'new', privateValue: 'secret' }],
]); };
const diagnostics = diagnose(peer);
t.mock.timers.tick(3000);
await Promise.resolve(); await Promise.resolve();
assert.equal(calls, 1);
assert.match(diagnostics.lines.join('\n'), /requestsSent=5.*responsesReceived=0/);
assert.match(diagnostics.lines.join('\n'), /transport dtls=new/);
assert.doesNotMatch(diagnostics.lines.join('\n'), /secret/);
peer.iceConnectionState = 'failed';
peer.dispatchEvent(new Event('iceconnectionstatechange'));
peer.getStats = async () => { calls++; return new Map(); };
await diagnostics.finish(() => { peer.closed = true; });
t.mock.timers.tick(12000);
assert.equal(calls, 2);
assert.match(diagnostics.lines.join('\n'), /requestsSent=5/);
assert.ok(diagnostics.lines.at(-1)?.endsWith('pairs=0'));
});
test('DTLS diagnostics allowlist values and never retain transport details', () => {
const lines = summarizeStats(new Map([['transport-secret', { type: 'transport', dtlsState: 'private-value', remoteCertificateId: 'secret' }]]));
assert.ok(lines.includes('transport dtls=unknown'));
assert.doesNotMatch(lines.join('\n'), /private|secret/);
});