freertc 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/freertc.mjs +4 -2
- package/package.json +1 -1
- package/public/app.js +14 -1
- package/public/index.html +30 -0
- package/scripts/node-relay.mjs +14 -1
- package/src/client.js +5 -2
- package/src/index.js +6 -2
- package/src/node/stats-page.js +41 -8
package/bin/freertc.mjs
CHANGED
|
@@ -21,7 +21,7 @@ Usage:
|
|
|
21
21
|
freertc install
|
|
22
22
|
freertc relay:keygen
|
|
23
23
|
freertc deploy [-- <deploy-args>]
|
|
24
|
-
freertc dev
|
|
24
|
+
freertc dev (a relay on this machine: ws://127.0.0.1:8788/ws)
|
|
25
25
|
freertc dev:cf [-- <dev-args>]
|
|
26
26
|
freertc name [--domain example.com] [--worker <name>]
|
|
27
27
|
|
|
@@ -110,7 +110,9 @@ if (subcommand === 'name') {
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
if (subcommand === 'dev') {
|
|
113
|
-
|
|
113
|
+
// A relay on this machine (Node). It runs from the package's own files, so nothing is copied into the
|
|
114
|
+
// folder it is started from (the Worker's files are for deploy and dev:cf).
|
|
115
|
+
runInProject(process.execPath, [path.join(PACKAGE_ROOT, 'scripts', 'node-relay.mjs'), ...rest]);
|
|
114
116
|
}
|
|
115
117
|
|
|
116
118
|
if (subcommand === 'dev:cf' || subcommand === 'dev-cf') {
|
package/package.json
CHANGED
package/public/app.js
CHANGED
|
@@ -168,6 +168,13 @@ function normalizeText(value) {
|
|
|
168
168
|
|
|
169
169
|
createApp({
|
|
170
170
|
setup() {
|
|
171
|
+
// Light or dark (index.html picks it before the first paint; the switch in the top bar changes it).
|
|
172
|
+
const theme = ref(document.documentElement.dataset.theme === 'light' ? 'light' : 'dark');
|
|
173
|
+
const toggleTheme = () => {
|
|
174
|
+
theme.value = theme.value === 'dark' ? 'light' : 'dark';
|
|
175
|
+
document.documentElement.dataset.theme = theme.value;
|
|
176
|
+
try { localStorage.setItem('freertc:theme', theme.value); } catch (e) {}
|
|
177
|
+
};
|
|
171
178
|
const host = window.location.host;
|
|
172
179
|
const wsScheme = window.location.protocol === "https:" ? "wss" : "ws";
|
|
173
180
|
|
|
@@ -3168,7 +3175,9 @@ createApp({
|
|
|
3168
3175
|
regenerateNetworkAndRoom,
|
|
3169
3176
|
selectPeer,
|
|
3170
3177
|
selectPeerFromUi,
|
|
3171
|
-
handleSpecLinkClick
|
|
3178
|
+
handleSpecLinkClick,
|
|
3179
|
+
theme,
|
|
3180
|
+
toggleTheme
|
|
3172
3181
|
};
|
|
3173
3182
|
},
|
|
3174
3183
|
template: `
|
|
@@ -3199,6 +3208,10 @@ createApp({
|
|
|
3199
3208
|
<strong><a class="pill-link" :href="pspSpecUrl" target="_blank" rel="noopener noreferrer" @click="handleSpecLinkClick">{{ specPillLabel }}</a></strong>
|
|
3200
3209
|
{{ specWarningCount > 0 ? specWarningCount + ' warning' + (specWarningCount === 1 ? '' : 's') : 'ok' }}
|
|
3201
3210
|
</div>
|
|
3211
|
+
<button type="button" class="theme-switch" :aria-label="theme === 'dark' ? 'Switch to light mode' : 'Switch to dark mode'" :title="theme === 'dark' ? 'Light mode' : 'Dark mode'" @click="toggleTheme">
|
|
3212
|
+
<svg v-if="theme === 'dark'" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="4.5" /><path d="M12 2.5v2.5M12 19v2.5M2.5 12H5M19 12h2.5M5.3 5.3l1.8 1.8M16.9 16.9l1.8 1.8M5.3 18.7l1.8-1.8M16.9 7.1l1.8-1.8" /></svg>
|
|
3213
|
+
<svg v-else viewBox="0 0 24 24" aria-hidden="true"><path d="M20 14.5A8 8 0 0 1 9.5 4a8 8 0 1 0 10.5 10.5z" /></svg>
|
|
3214
|
+
</button>
|
|
3202
3215
|
</div>
|
|
3203
3216
|
</section>
|
|
3204
3217
|
|
package/public/index.html
CHANGED
|
@@ -4,6 +4,15 @@
|
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
6
|
<title>FreeRTC</title>
|
|
7
|
+
<script>
|
|
8
|
+
// The theme before the first paint: the one picked here last time, else the system's.
|
|
9
|
+
(function () {
|
|
10
|
+
var t = null;
|
|
11
|
+
try { t = localStorage.getItem('freertc:theme'); } catch (e) {}
|
|
12
|
+
if (t !== 'light' && t !== 'dark') t = window.matchMedia && matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';
|
|
13
|
+
document.documentElement.dataset.theme = t;
|
|
14
|
+
})();
|
|
15
|
+
</script>
|
|
7
16
|
<link rel="icon" type="image/svg+xml" href="/pigeonlogo.svg" />
|
|
8
17
|
<link rel="icon" type="image/png" sizes="192x192" href="/icon-192.png" />
|
|
9
18
|
<link rel="apple-touch-icon" sizes="180x180" href="/icon-180.png" />
|
|
@@ -36,6 +45,23 @@
|
|
|
36
45
|
--success: var(--sheen);
|
|
37
46
|
--warn: var(--warm);
|
|
38
47
|
}
|
|
48
|
+
/* By day: Cruise, as peer.ooo, PigeonChess and PigeonFeed. */
|
|
49
|
+
html[data-theme='light'] {
|
|
50
|
+
color-scheme: light;
|
|
51
|
+
--night: #e8f6f9;
|
|
52
|
+
--night-2: #f5fbfc;
|
|
53
|
+
--line: #bee6ee;
|
|
54
|
+
--line-strong: #8aa7b3;
|
|
55
|
+
--bright: #2a3747;
|
|
56
|
+
--bone: #2a3747;
|
|
57
|
+
--bone-2: #46586e;
|
|
58
|
+
--bone-3: #5a7187;
|
|
59
|
+
--sheen: #237a50;
|
|
60
|
+
--info: #2f62a3;
|
|
61
|
+
--warm: #9a6a1f;
|
|
62
|
+
--bad: #b4423a;
|
|
63
|
+
--on-bone: #ffffff;
|
|
64
|
+
}
|
|
39
65
|
*, *::before, *::after { box-sizing: border-box; }
|
|
40
66
|
html, body { margin: 0; }
|
|
41
67
|
body {
|
|
@@ -71,6 +97,10 @@
|
|
|
71
97
|
.inline-link, .pill-link { color: var(--bone); text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
|
|
72
98
|
.inline-link:hover, .pill-link:hover { text-decoration-color: var(--sheen); }
|
|
73
99
|
.hero-status { display: flex; align-items: center; gap: 10px; min-width: 0; }
|
|
100
|
+
/* The theme switch, as on every PeerPigeon site: a bare line icon. */
|
|
101
|
+
button.theme-switch { display: grid; place-items: center; width: 36px; height: 36px; flex: none; padding: 0; border: 0; background: none; color: var(--bone-2); }
|
|
102
|
+
button.theme-switch:hover:not(:disabled) { color: var(--bright); }
|
|
103
|
+
.theme-switch svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
|
|
74
104
|
|
|
75
105
|
/* Status and small labels: plain text with a dot, no pills. */
|
|
76
106
|
.status-pill, .pill { display: inline-flex; align-items: center; gap: 8px; padding: 0; border: 0; background: none; color: var(--bone-2); font-size: 0.85rem; text-transform: none; letter-spacing: 0; border-radius: 0; }
|
package/scripts/node-relay.mjs
CHANGED
|
@@ -227,12 +227,25 @@ setInterval(saveCredit, 60_000).unref();
|
|
|
227
227
|
process.on('exit', saveCredit);
|
|
228
228
|
// Punched connections need WebRTC in this process (werift, an optional dependency).
|
|
229
229
|
const PUNCH = !isOff(process.env.FREERTC_PUNCH) && await punchOfferAvailable();
|
|
230
|
+
// The name it goes by until it has its own (src/node/relay-name.js) or RELAY_NAME: once it federates,
|
|
231
|
+
// freertc-<the first 16 hex of its node id>, the label its wss:// name will have; pages show it, so it
|
|
232
|
+
// is never its loopback address. A relay that does not federate keeps host and port (seen locally only).
|
|
233
|
+
async function defaultRelayName() {
|
|
234
|
+
if (federating) {
|
|
235
|
+
try {
|
|
236
|
+
const { publicKey, privateKey } = decodeRelayIdentitySecret(await relayIdentitySecret());
|
|
237
|
+
const { nodeId } = await createRelayIdentity(publicKey, privateKey);
|
|
238
|
+
if (/^[0-9a-f]{16}/i.test(nodeId)) return `freertc-${nodeId.slice(0, 16).toLowerCase()}`;
|
|
239
|
+
} catch { /* below */ }
|
|
240
|
+
}
|
|
241
|
+
return `freertc-node-${SELF_HOST}-${PORT}`;
|
|
242
|
+
}
|
|
230
243
|
const env = {
|
|
231
244
|
RELAY_KIND: process.env.RELAY_KIND === 'cloud' ? 'cloud' : 'local',
|
|
232
245
|
...(PUNCH ? { PUNCH_OFFER: 'on' } : {}),
|
|
233
246
|
DB: meter.wrapD1(await openSqliteD1({ filename: path.resolve(process.env.DB_PATH || path.join(DATA_DIR, 'relay.sqlite')), migrationsDir: path.join(ROOT, 'migrations') })),
|
|
234
247
|
RELAY_URL,
|
|
235
|
-
RELAY_NAME: process.env.RELAY_NAME ||
|
|
248
|
+
RELAY_NAME: process.env.RELAY_NAME || await defaultRelayName(),
|
|
236
249
|
...(process.env.FREERTC_VERBOSE ? { FREERTC_VERBOSE: process.env.FREERTC_VERBOSE } : {}),
|
|
237
250
|
FREERTC_PUBLIC: PUBLIC ? 'true' : 'false',
|
|
238
251
|
KADEMLIA_BOOTSTRAP_URLS: federating ? bootstrap.join(',') : '',
|
package/src/client.js
CHANGED
|
@@ -2909,7 +2909,10 @@ export function createSignalingClient(options = {}) {
|
|
|
2909
2909
|
lastSignalPingSentAt = 0
|
|
2910
2910
|
|
|
2911
2911
|
send(pspEnvelope('announce', {
|
|
2912
|
-
|
|
2912
|
+
// The same lease the heartbeat asks for. This asked for 30 s while the first heartbeat comes 40 s
|
|
2913
|
+
// later: every peer dropped out of the relay's list for those 10 s, each time it registered, and a
|
|
2914
|
+
// newcomer asking in that gap was not told of it (a storage server nobody could find, say).
|
|
2915
|
+
ttl_ms: ADVERTISE_TTL_MS,
|
|
2913
2916
|
body: {
|
|
2914
2917
|
instance_id: networkId,
|
|
2915
2918
|
capabilities,
|
|
@@ -3176,7 +3179,7 @@ export function createSignalingClient(options = {}) {
|
|
|
3176
3179
|
advertise(nextCapabilities) {
|
|
3177
3180
|
if (!registered) return
|
|
3178
3181
|
send(pspEnvelope('announce', {
|
|
3179
|
-
ttl_ms:
|
|
3182
|
+
ttl_ms: ADVERTISE_TTL_MS,
|
|
3180
3183
|
body: { instance_id: networkId, capabilities: nextCapabilities, hints: { wants_peers: true } },
|
|
3181
3184
|
}))
|
|
3182
3185
|
},
|
package/src/index.js
CHANGED
|
@@ -36,7 +36,7 @@ function relayLog(what, line) {
|
|
|
36
36
|
export { RelayTunnel } from "./tunnel/home.js";
|
|
37
37
|
|
|
38
38
|
const PSP_VERSION = "1.0";
|
|
39
|
-
const WORKER_VERSION = "0.5.
|
|
39
|
+
const WORKER_VERSION = "0.5.2";
|
|
40
40
|
|
|
41
41
|
const DISCOVERY_TYPES = new Set(["announce", "withdraw", "discover", "peer_list", "redirect"]);
|
|
42
42
|
const NEGOTIATION_TYPES = new Set(["connect_request", "connect_accept", "connect_reject", "offer", "answer", "ice_candidate", "ice_end", "renegotiate"]);
|
|
@@ -59,6 +59,8 @@ const FEDERATED_PEER_QUERY_TIMEOUT_MS = 2_500;
|
|
|
59
59
|
// the local peers are sent alone if the federated lookup is still running.
|
|
60
60
|
const DISCOVER_REPLY_DEADLINE_MS = 4_000;
|
|
61
61
|
const MAX_TTL_MS = 120_000;
|
|
62
|
+
// The shortest lease an announcement is given (see upsertAnnouncement).
|
|
63
|
+
const MIN_ANNOUNCE_TTL_MS = 60_000;
|
|
62
64
|
const MAX_MESSAGE_SIZE = 64 * 1024;
|
|
63
65
|
const MAX_BATCH = 50;
|
|
64
66
|
const RELAY_EXPIRY_MS = 5 * 60_000; // relay entry expires after 5 min without heartbeat
|
|
@@ -1465,7 +1467,9 @@ export function announcedRole(message) {
|
|
|
1465
1467
|
export async function upsertAnnouncement(db, message) {
|
|
1466
1468
|
await ensureRoleColumn(db);
|
|
1467
1469
|
const now = Date.now();
|
|
1468
|
-
|
|
1470
|
+
// Never a lease shorter than a client's heartbeat (40 s): clients before 0.5.2 asked for 30 s when they
|
|
1471
|
+
// registered, and were gone from the list for 10 s before their first heartbeat renewed it.
|
|
1472
|
+
const ttl = Math.min(Math.max(message.ttl_ms || DEFAULT_TTL_MS, MIN_ANNOUNCE_TTL_MS), MAX_TTL_MS);
|
|
1469
1473
|
const expiresAt = now + ttl;
|
|
1470
1474
|
|
|
1471
1475
|
await db.prepare(`
|
package/src/node/stats-page.js
CHANGED
|
@@ -9,6 +9,16 @@ export const STATS_PAGE = `<!doctype html>
|
|
|
9
9
|
<meta charset="utf-8" />
|
|
10
10
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
11
11
|
<meta name="theme-color" content="#1b2430" />
|
|
12
|
+
<script>
|
|
13
|
+
// The theme before the first paint: the one picked here last time, else the system's.
|
|
14
|
+
(function () {
|
|
15
|
+
var t = null;
|
|
16
|
+
try { t = localStorage.getItem('freertc:theme'); } catch (e) {}
|
|
17
|
+
if (t !== 'light' && t !== 'dark') t = window.matchMedia && matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';
|
|
18
|
+
document.documentElement.dataset.theme = t;
|
|
19
|
+
if (t === 'light') document.querySelector('meta[name="theme-color"]').setAttribute('content', '#e8f6f9');
|
|
20
|
+
})();
|
|
21
|
+
</script>
|
|
12
22
|
<title>Relay stats</title>
|
|
13
23
|
<link rel="icon" type="image/svg+xml" href="/pigeonlogo.svg" />
|
|
14
24
|
<link rel="icon" type="image/png" sizes="192x192" href="/icon-192.png" />
|
|
@@ -21,6 +31,19 @@ export const STATS_PAGE = `<!doctype html>
|
|
|
21
31
|
--sheen: #7fd8a6; --info: #9cc3f5; --warn: #f2c879; --stop: #f29b91;
|
|
22
32
|
color-scheme: dark;
|
|
23
33
|
}
|
|
34
|
+
/* By day: Cruise, as peer.ooo, PigeonChess and PigeonFeed. */
|
|
35
|
+
html[data-theme='light'] {
|
|
36
|
+
--night: #e8f6f9; --night-2: #f5fbfc; --line: #bee6ee; --line-strong: #8aa7b3;
|
|
37
|
+
--bright: #2a3747; --bone: #2a3747; --bone-2: #46586e; --bone-3: #5a7187;
|
|
38
|
+
--sheen: #237a50; --info: #2f62a3; --warn: #9a6a1f; --stop: #b4423a;
|
|
39
|
+
color-scheme: light;
|
|
40
|
+
}
|
|
41
|
+
.top-right { display: flex; align-items: center; gap: 12px; }
|
|
42
|
+
/* The theme switch, as on every PeerPigeon site: a bare line icon. */
|
|
43
|
+
.theme-switch { display: grid; place-items: center; width: 36px; height: 36px; border: 0; background: none; color: var(--bone-2); cursor: pointer; }
|
|
44
|
+
.theme-switch:hover { color: var(--bright); }
|
|
45
|
+
.theme-switch svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
|
|
46
|
+
html[data-theme='dark'] .theme-switch .moon, html[data-theme='light'] .theme-switch .sun { display: none; }
|
|
24
47
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
25
48
|
body { background: var(--night); color: var(--bone); font: 14px/1.45 'Archivo', system-ui, -apple-system, 'Segoe UI', sans-serif; -webkit-font-smoothing: antialiased; }
|
|
26
49
|
main { max-width: 1180px; margin: 0 auto; padding: 28px clamp(16px, 4vw, 40px) 56px; }
|
|
@@ -70,7 +93,10 @@ export const STATS_PAGE = `<!doctype html>
|
|
|
70
93
|
<h1 id="name">Relay<small id="kind"></small></h1>
|
|
71
94
|
<p class="where" id="url"></p>
|
|
72
95
|
</div>
|
|
73
|
-
<
|
|
96
|
+
<div class="top-right">
|
|
97
|
+
<p class="live" id="live"><i></i><span>Connecting…</span></p>
|
|
98
|
+
<button type="button" class="theme-switch" id="theme-switch" aria-label="Switch theme" title="Switch theme"><svg class="sun" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="4.5" /><path d="M12 2.5v2.5M12 19v2.5M2.5 12H5M19 12h2.5M5.3 5.3l1.8 1.8M16.9 16.9l1.8 1.8M5.3 18.7l1.8-1.8M16.9 7.1l1.8-1.8" /></svg><svg class="moon" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 14.5A8 8 0 0 1 9.5 4a8 8 0 1 0 10.5 10.5z" /></svg></button>
|
|
99
|
+
</div>
|
|
74
100
|
</header>
|
|
75
101
|
|
|
76
102
|
<div class="tiles">
|
|
@@ -79,7 +105,7 @@ export const STATS_PAGE = `<!doctype html>
|
|
|
79
105
|
<div class="tile"><h2>Messages</h2><p class="big" id="msgs">–</p><p class="sub" id="msgs-sub"></p></div>
|
|
80
106
|
<div class="tile"><h2>Bandwidth</h2><p class="big" id="bw">–</p><p class="sub" id="bw-sub"></p></div>
|
|
81
107
|
<div class="tile"><h2>Pigeon Seeds</h2><p class="big" id="credit">–</p><p class="sub" id="credit-sub"></p></div>
|
|
82
|
-
<div class="tile" id="acc-tile"><h2>Accounts kept</h2><p class="big" id="acc">–</p><p class="sub" id="acc-sub"></p></div>
|
|
108
|
+
<div class="tile" id="acc-tile" hidden><h2>Accounts kept</h2><p class="big" id="acc">–</p><p class="sub" id="acc-sub"></p></div>
|
|
83
109
|
</div>
|
|
84
110
|
|
|
85
111
|
<div class="charts">
|
|
@@ -93,7 +119,7 @@ export const STATS_PAGE = `<!doctype html>
|
|
|
93
119
|
<div class="chart"><div class="chart-head"><h3>Memory (this relay)</h3><span id="c-mem"></span></div><svg id="g-mem" preserveAspectRatio="none"></svg></div>
|
|
94
120
|
</div>
|
|
95
121
|
|
|
96
|
-
<section id="acc-section">
|
|
122
|
+
<section id="acc-section" hidden>
|
|
97
123
|
<h2>Accounts</h2>
|
|
98
124
|
<div class="cols">
|
|
99
125
|
<dl id="acc-browsers"></dl>
|
|
@@ -101,7 +127,7 @@ export const STATS_PAGE = `<!doctype html>
|
|
|
101
127
|
</div>
|
|
102
128
|
</section>
|
|
103
129
|
|
|
104
|
-
<section id="events-section">
|
|
130
|
+
<section id="events-section" hidden>
|
|
105
131
|
<h2>Account events between relays</h2>
|
|
106
132
|
<ul class="relays" id="events"></ul>
|
|
107
133
|
</section>
|
|
@@ -158,13 +184,20 @@ export const STATS_PAGE = `<!doctype html>
|
|
|
158
184
|
if (values.length < 2) return '';
|
|
159
185
|
const step = w / (values.length - 1);
|
|
160
186
|
const points = values.map((v, j) => (j * step).toFixed(1) + ',' + (h - pad - (v / max) * (h - pad * 2)).toFixed(1)).join(' ');
|
|
161
|
-
const area = i === 0 ? '<polygon points="0,' + h + ' ' + points + ' ' + w + ',' + h + '"
|
|
162
|
-
return area + '<polyline points="' + points + '" fill="none"
|
|
187
|
+
const area = i === 0 ? '<polygon points="0,' + h + ' ' + points + ' ' + w + ',' + h + '" style="fill:' + colors[i] + '" fill-opacity="0.08"/>' : '';
|
|
188
|
+
return area + '<polyline points="' + points + '" fill="none" style="stroke:' + colors[i] + '" stroke-width="1.5" vector-effect="non-scaling-stroke" stroke-linejoin="round"/>';
|
|
163
189
|
}).join('');
|
|
164
|
-
svg.innerHTML = '<line x1="0" x2="' + w + '" y1="' + (h - 0.5) + '" y2="' + (h - 0.5) + '"
|
|
190
|
+
svg.innerHTML = '<line x1="0" x2="' + w + '" y1="' + (h - 0.5) + '" y2="' + (h - 0.5) + '" style="stroke:var(--line)"/>' + lines;
|
|
165
191
|
}
|
|
166
192
|
|
|
167
|
-
const SHEEN = '
|
|
193
|
+
const SHEEN = 'var(--sheen)', BONE = 'var(--bone-2)';
|
|
194
|
+
|
|
195
|
+
document.getElementById('theme-switch').addEventListener('click', () => {
|
|
196
|
+
const t = document.documentElement.dataset.theme === 'dark' ? 'light' : 'dark';
|
|
197
|
+
document.documentElement.dataset.theme = t;
|
|
198
|
+
document.querySelector('meta[name="theme-color"]').setAttribute('content', t === 'dark' ? '#1b2430' : '#e8f6f9');
|
|
199
|
+
try { localStorage.setItem('freertc:theme', t); } catch (e) {}
|
|
200
|
+
});
|
|
168
201
|
let lastOk = 0;
|
|
169
202
|
|
|
170
203
|
async function refresh() {
|