Skip to content

A platform for community discussion. Free, open, simple.

UX: Surface missing public addresses and dedupe errors in live connection diagnostics (#45530)

Rafael dos Santos Silvacc26fe11ae0e
diff --git a/plugins/live/assets/javascripts/discourse/components/modal/live-connection-diagnostics.gjs b/plugins/live/assets/javascripts/discourse/components/modal/live-connection-diagnostics.gjs
index 191282a4f5a..3c574d8e998 100644
--- a/plugins/live/assets/javascripts/discourse/components/modal/live-connection-diagnostics.gjs
+++ b/plugins/live/assets/javascripts/discourse/components/modal/live-connection-diagnostics.gjs
@@ -13,6 +13,7 @@ import { i18n } from "discourse-i18n";
import {
formatBitrate,
formatCandidateCounts,
+ formatIceError,
formatReport,
formatRtt,
} from "../../lib/live/connection-diagnostics.js";
@@ -157,9 +158,7 @@ export default class LiveConnectionDiagnosticsModal extends Component {
recovery.restartAttempts >= recovery.maxRestartAttempts &&
status !== "connected",
iceErrors: recovery.iceCandidateErrors.map((error) =>
- [error.url, error.errorCode, error.errorText]
- .filter(Boolean)
- .join(" — ")
+ formatIceError(error)
),
};
})
@@ -196,15 +195,18 @@ export default class LiveConnectionDiagnosticsModal extends Component {
return {
url: probe.url,
kind: probe.kind.toUpperCase(),
- addresses: probe.addresses.join(", "),
+ relayAddresses: probe.relayAddresses.join(", "),
+ publicAddresses: probe.publicAddresses.join(", "),
+ missingPublicAddress: probe.udp && !probe.publicAddresses.length,
status,
statusLabel: probe.reachable
? i18n("live.connection_diagnostics.probe.ok", {
ms: probe.durationMs,
})
: i18n(`live.connection_diagnostics.probe.${status}`),
+ // The probe only talks to this one server, so its URL is redundant.
errors: probe.errors.map((error) =>
- [error.errorCode, error.errorText].filter(Boolean).join(" — ")
+ formatIceError(error, { includeUrl: false })
),
};
});
@@ -318,14 +320,18 @@ export default class LiveConnectionDiagnosticsModal extends Component {
>
<:body>
{{#if this.diagnostics}}
- <p class="live-connection-diagnostics__summary">
- {{this.summary}}
- {{#if this.relayOnly}}
- <span class="live-connection-diagnostics__note">
- {{i18n "live.connection_diagnostics.relay_only"}}
- </span>
- {{/if}}
- </p>
+ {{#if (or this.peers.length this.relayOnly)}}
+ <p class="live-connection-diagnostics__summary">
+ {{#if this.peers.length}}
+ {{this.summary}}
+ {{/if}}
+ {{#if this.relayOnly}}
+ <span class="live-connection-diagnostics__note">
+ {{i18n "live.connection_diagnostics.relay_only"}}
+ </span>
+ {{/if}}
+ </p>
+ {{/if}}
<section class="live-connection-diagnostics__section">
<h3>{{i18n "live.connection_diagnostics.peers"}}</h3>
@@ -444,21 +450,39 @@ export default class LiveConnectionDiagnosticsModal extends Component {
{{else}}
{{#each this.probeRows as |probe|}}
<div class="live-connection-diagnostics__server">
- <span
- class="live-connection-diagnostics__server-kind"
- >{{probe.kind}}</span>
- <code>{{probe.url}}</code>
- <span
- class={{dConcatClass
- "live-connection-diagnostics__badge"
- (concat "--" probe.status)
- }}
- >{{probe.statusLabel}}</span>
- {{#if probe.addresses}}
+ <div class="live-connection-diagnostics__server-header">
<span
- class="live-connection-diagnostics__server-addresses"
- >{{probe.addresses}}</span>
- {{/if}}
+ class="live-connection-diagnostics__server-kind"
+ >{{probe.kind}}</span>
+ <code>{{probe.url}}</code>
+ <span
+ class={{dConcatClass
+ "live-connection-diagnostics__badge"
+ (concat "--" probe.status)
+ }}
+ >{{probe.statusLabel}}</span>
+ </div>
+ <dl class="live-connection-diagnostics__details">
+ {{#if probe.relayAddresses}}
+ <dt>{{i18n
+ "live.connection_diagnostics.relay_address"
+ }}</dt>
+ <dd>{{probe.relayAddresses}}</dd>
+ {{/if}}
+ {{#if probe.publicAddresses}}
+ <dt>{{i18n
+ "live.connection_diagnostics.public_address"
+ }}</dt>
+ <dd>{{probe.publicAddresses}}</dd>
+ {{else if probe.missingPublicAddress}}
+ <dt>{{i18n
+ "live.connection_diagnostics.public_address"
+ }}</dt>
+ <dd class="live-connection-diagnostics__warning">
+ {{i18n "live.connection_diagnostics.no_public_address"}}
+ </dd>
+ {{/if}}
+ </dl>
{{#if probe.errors.length}}
<ul class="live-connection-diagnostics__errors">
{{#each probe.errors as |error|}}
diff --git a/plugins/live/assets/javascripts/discourse/lib/live/connection-diagnostics.js b/plugins/live/assets/javascripts/discourse/lib/live/connection-diagnostics.js
index 5e26c9a7fca..48b19891d1c 100644
--- a/plugins/live/assets/javascripts/discourse/lib/live/connection-diagnostics.js
+++ b/plugins/live/assets/javascripts/discourse/lib/live/connection-diagnostics.js
@@ -8,6 +8,52 @@ const PROBE_TIMEOUT_MS = 6000;
const CANDIDATE_TYPES = ["host", "srflx", "prflx", "relay"];
+const MAX_ICE_ERRORS = 10;
+
+/**
+ * Records an ICE candidate error, folding repeats into a count: browsers retry
+ * each server per interface and transaction, so the same failure otherwise
+ * floods the list and pushes out the distinct ones.
+ *
+ * @param {Array<object>} errors - Mutated in place.
+ * @param {{url?: string, errorCode?: number, errorText?: string}} error
+ */
+export function recordIceError(errors, { url, errorCode, errorText }) {
+ const existing = errors.find(
+ (entry) =>
+ entry.url === url &&
+ entry.errorCode === errorCode &&
+ entry.errorText === errorText
+ );
+ if (existing) {
+ existing.count++;
+ existing.lastAt = Date.now();
+ return errors;
+ }
+
+ errors.push({ url, errorCode, errorText, count: 1, lastAt: Date.now() });
+ if (errors.length > MAX_ICE_ERRORS) {
+ errors.shift();
+ }
+ return errors;
+}
+
+/**
+ * @param {{url?: string, errorCode?: number, errorText?: string, count?: number}} error
+ * @param {{includeUrl?: boolean}} [options]
+ */
+export function formatIceError(error, { includeUrl = true } = {}) {
+ const text = [
+ includeUrl && error.url,
+ error.errorCode,
+ error.errorText,
+ error.count > 1 && `(×${error.count})`,
+ ]
+ .filter(Boolean)
+ .join(" ");
+ return text || "?";
+}
+
function statsValues(report) {
if (!report) {
return [];
@@ -268,15 +314,21 @@ export async function probeIceServer(url, server, options = {}) {
const timeoutMs = options.timeoutMs ?? PROBE_TIMEOUT_MS;
const isTurn = /^turns?:/i.test(url);
const expectedType = isTurn ? "relay" : "srflx";
+ // Browsers only learn their public address over UDP; a TCP/TLS server
+ // never yields one, so its absence there says nothing.
+ const udp = !/^turns:/i.test(url) && !/[?&]transport=tcp/i.test(url);
const startedAt = performance.now();
const result = {
url,
kind: isTurn ? "turn" : "stun",
reachable: false,
+ udp,
candidates: emptyCandidateCounts(),
- // The public (srflx) or relay addresses the server handed back.
- addresses: [],
+ relayAddresses: [],
+ // Our NAT's public address as the server saw it. Missing over UDP means
+ // direct (non-relayed) connections can't be set up through this network.
+ publicAddresses: [],
errors: [],
timedOut: false,
durationMs: null,
@@ -310,12 +362,14 @@ export async function probeIceServer(url, server, options = {}) {
if (type && type in result.candidates) {
result.candidates[type]++;
const address = event.candidate.address;
- if (
- type === expectedType &&
- address &&
- !result.addresses.includes(address)
- ) {
- result.addresses.push(address);
+ const addresses =
+ type === "relay"
+ ? result.relayAddresses
+ : type === "srflx"
+ ? result.publicAddresses
+ : null;
+ if (addresses && address && !addresses.includes(address)) {
+ addresses.push(address);
}
if (type === expectedType && !result.reachable) {
result.reachable = true;
@@ -328,7 +382,8 @@ export async function probeIceServer(url, server, options = {}) {
}
};
pc.onicecandidateerror = (event) => {
- result.errors.push({
+ recordIceError(result.errors, {
+ url: event.url,
errorCode: event.errorCode,
errorText: event.errorText,
});
@@ -508,11 +563,16 @@ export function formatReport({
: "FAILED";
push(`${probe.url}: ${status}`);
push(` candidates: ${formatCandidateCounts(probe.candidates)}`);
- if (probe.addresses?.length) {
- push(` addresses: ${probe.addresses.join(", ")}`);
+ if (probe.relayAddresses?.length) {
+ push(` relay address: ${probe.relayAddresses.join(", ")}`);
+ }
+ if (probe.publicAddresses?.length) {
+ push(` public address: ${probe.publicAddresses.join(", ")}`);
+ } else if (probe.udp) {
+ push(" public address: NONE (STUN binding got no answer)");
}
for (const error of probe.errors) {
- push(` error: ${error.errorCode ?? ""} ${error.errorText ?? ""}`.trim());
+ push(` error: ${formatIceError(error)}`);
}
}
push();
@@ -527,9 +587,7 @@ export function formatReport({
` restarts: ${recovery.restartAttempts}/${recovery.maxRestartAttempts}${recovery.restartScheduled ? " (restart pending)" : ""} offer retries: ${recovery.offerRetryAttempts}/${recovery.maxOfferRetries} queued candidates: ${recovery.pendingCandidates}`
);
for (const error of recovery.iceCandidateErrors) {
- push(
- ` ICE error: ${error.url ?? "?"} ${error.errorCode ?? ""} ${error.errorText ?? ""}`.trimEnd()
- );
+ push(` ICE error: ${formatIceError(error)}`);
}
const connection = peer.connection;
diff --git a/plugins/live/assets/javascripts/discourse/lib/live/peer-manager.js b/plugins/live/assets/javascripts/discourse/lib/live/peer-manager.js
index fe618d3abf7..bfa82efd67f 100644
--- a/plugins/live/assets/javascripts/discourse/lib/live/peer-manager.js
+++ b/plugins/live/assets/javascripts/discourse/lib/live/peer-manager.js
@@ -1,4 +1,5 @@
import liveLog from "discourse/plugins/live/discourse/lib/live/logger";
+import { recordIceError } from "./connection-diagnostics.js";
// The screen-share audio m-line is pre-negotiated like the video one, but
// both audio transceivers on a connection report kind "audio", so the screen
@@ -10,7 +11,6 @@ const screenAudioTransceivers = new WeakMap();
// they are the only signal that a STUN/TURN server rejected or never answered
// this peer's allocation.
const iceCandidateErrors = new WeakMap();
-const MAX_ICE_CANDIDATE_ERRORS = 10;
const DEFAULT_TIMING = {
offerRetryBaseDelayMs: 400,
@@ -392,14 +392,14 @@ export default class PeerManager {
pc.onicecandidateerror = (event) => {
liveLog.warn("[live] ICE candidate error for peer");
- const errors = iceCandidateErrors.get(pc) || [];
- errors.push({
+ if (!iceCandidateErrors.has(pc)) {
+ iceCandidateErrors.set(pc, []);
+ }
+ recordIceError(iceCandidateErrors.get(pc), {
url: event.url,
errorCode: event.errorCode,
errorText: event.errorText,
- at: Date.now(),
});
- iceCandidateErrors.set(pc, errors.slice(-MAX_ICE_CANDIDATE_ERRORS));
};
pc.onconnectionstatechange = () => {
diff --git a/plugins/live/assets/stylesheets/common/live.scss b/plugins/live/assets/stylesheets/common/live.scss
index 5c107c80446..e44a4a09b00 100644
--- a/plugins/live/assets/stylesheets/common/live.scss
+++ b/plugins/live/assets/stylesheets/common/live.scss
@@ -1443,26 +1443,26 @@
}
&__server {
- display: flex;
- flex-wrap: wrap;
- align-items: center;
- gap: 0.5rem;
- padding: 0.4rem 0;
+ padding: 0.5rem 0;
border-bottom: 1px solid var(--primary-very-low);
code {
overflow-wrap: anywhere;
}
+ }
- .live-connection-diagnostics__errors {
- flex-basis: 100%;
+ &__server-header {
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+
+ .live-connection-diagnostics__badge {
+ white-space: nowrap;
}
}
- &__server-addresses {
- font-size: var(--font-down-1);
- color: var(--primary-medium);
- overflow-wrap: anywhere;
+ &__warning {
+ color: var(--danger);
}
&__privacy {
diff --git a/plugins/live/config/locales/client.en.yml b/plugins/live/config/locales/client.en.yml
index ee75076dc4c..66e113dd6ef 100644
--- a/plugins/live/config/locales/client.en.yml
+++ b/plugins/live/config/locales/client.en.yml
@@ -301,6 +301,9 @@ en:
local_candidate: "Your side"
remote_candidate: "Their side"
via_server: "Through server"
+ relay_address: "Relay address"
+ public_address: "Public address"
+ no_public_address: "None. STUN requests got no answer, so direct connections can't be set up and calls will be relayed."
rtt: "Round-trip time"
bitrate: "Available upload"
candidate_pairs: "Candidate pairs"
diff --git a/plugins/live/test/javascripts/unit/lib/connection-diagnostics-test.js b/plugins/live/test/javascripts/unit/lib/connection-diagnostics-test.js
index b089d4b642b..e64750a1703 100644
--- a/plugins/live/test/javascripts/unit/lib/connection-diagnostics-test.js
+++ b/plugins/live/test/javascripts/unit/lib/connection-diagnostics-test.js
@@ -2,6 +2,7 @@ import { module, test } from "qunit";
import {
collectPeers,
formatReport,
+ recordIceError,
routeFor,
summarizeStats,
} from "discourse/plugins/live/discourse/lib/live/connection-diagnostics";
@@ -209,9 +210,11 @@ module("Live | Unit | Lib | connection-diagnostics", function () {
url: "stun:stun.example.com:3478",
reachable: false,
timedOut: true,
+ udp: true,
candidates: {},
- addresses: [],
- errors: [{ errorCode: 701, errorText: "STUN timeout" }],
+ relayAddresses: [],
+ publicAddresses: [],
+ errors: [{ errorCode: 701, errorText: "STUN timeout", count: 3 }],
},
],
peers,
@@ -224,6 +227,37 @@ module("Live | Unit | Lib | connection-diagnostics", function () {
assert.true(report.includes("198.51.100.7"), "includes remote address");
assert.true(report.includes("NO PEER CONNECTION (expected one)"));
assert.true(report.includes("stun:stun.example.com:3478: NO RESPONSE"));
- assert.true(report.includes("701 STUN timeout"));
+ assert.true(
+ report.includes("\n error: 701 STUN timeout (×3)"),
+ "keeps probe errors indented and shows repeat counts"
+ );
+ assert.true(report.includes("public address: NONE"));
+ });
+
+ test("recordIceError folds repeated errors into a count", function (assert) {
+ const errors = [];
+ const timeout = {
+ url: "stun:stun.example.com:3478",
+ errorCode: 701,
+ errorText: "STUN binding request timed out.",
+ };
+
+ recordIceError(errors, timeout);
+ recordIceError(errors, timeout);
+ recordIceError(errors, { ...timeout, errorCode: 1, errorText: "" });
+
+ assert.strictEqual(errors.length, 2);
+ assert.strictEqual(errors[0].count, 2);
+ assert.strictEqual(errors[1].count, 1);
+ });
+
+ test("recordIceError keeps only the most recent distinct errors", function (assert) {
+ const errors = [];
+ for (let code = 0; code < 12; code++) {
+ recordIceError(errors, { url: "turn:x", errorCode: code });
+ }
+
+ assert.strictEqual(errors.length, 10);
+ assert.strictEqual(errors[0].errorCode, 2);
});
});