WIP III improve UX [snapshot task 2]
This commit is contained in:
1 parent
b2bab26981
commit
28c90d1d71
5 files changed
+97
-2
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user