freertc 0.1.18 → 0.1.20
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/README.md +1 -1
- package/package.json +1 -1
- package/public/app.js +29 -0
- package/scripts/non-cloudflare-server.mjs +1 -1
- package/scripts/postinstall-message.mjs +27 -4
- package/src/index.js +7 -1
package/README.md
CHANGED
|
@@ -216,7 +216,7 @@ Quick checks:
|
|
|
216
216
|
Expected `/health` response includes JSON like:
|
|
217
217
|
|
|
218
218
|
```json
|
|
219
|
-
{"ok":true,"version":"0.1.
|
|
219
|
+
{"ok":true,"version":"0.1.20","protocol_version":"1.0","peers":0}
|
|
220
220
|
```
|
|
221
221
|
|
|
222
222
|
## Auto WebRTC two-tab test
|
package/package.json
CHANGED
package/public/app.js
CHANGED
|
@@ -1283,6 +1283,12 @@ createApp({
|
|
|
1283
1283
|
|
|
1284
1284
|
function selectPeer(peerId, options = {}) {
|
|
1285
1285
|
const { manual = false, allowUnannounced = false } = options;
|
|
1286
|
+
|
|
1287
|
+
if (peerId === fromPeer.value) {
|
|
1288
|
+
pushLog("discovery:error", "Ignoring self peer selection");
|
|
1289
|
+
toPeer.value = "";
|
|
1290
|
+
return;
|
|
1291
|
+
}
|
|
1286
1292
|
|
|
1287
1293
|
// Only allow selecting announced peers to prevent phantom links.
|
|
1288
1294
|
const isAnnounced = discoveredPeers.value.some((p) => p?.peer_id === peerId);
|
|
@@ -1889,6 +1895,10 @@ createApp({
|
|
|
1889
1895
|
return;
|
|
1890
1896
|
}
|
|
1891
1897
|
|
|
1898
|
+
if (message.from && message.from === fromPeer.value) {
|
|
1899
|
+
return;
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1892
1902
|
if (message.type === "error") {
|
|
1893
1903
|
pushLog("server:error", message.body || {});
|
|
1894
1904
|
return;
|
|
@@ -2087,6 +2097,9 @@ createApp({
|
|
|
2087
2097
|
}
|
|
2088
2098
|
|
|
2089
2099
|
const peerId = message.from;
|
|
2100
|
+
if (peerId === fromPeer.value) {
|
|
2101
|
+
return;
|
|
2102
|
+
}
|
|
2090
2103
|
const link = getMeshLink(peerId);
|
|
2091
2104
|
|
|
2092
2105
|
if (!hasMeshCapacityForPeer(peerId)) {
|
|
@@ -2144,6 +2157,9 @@ createApp({
|
|
|
2144
2157
|
return;
|
|
2145
2158
|
}
|
|
2146
2159
|
const peerId = message.from;
|
|
2160
|
+
if (peerId === fromPeer.value) {
|
|
2161
|
+
return;
|
|
2162
|
+
}
|
|
2147
2163
|
const link = getMeshLink(peerId);
|
|
2148
2164
|
|
|
2149
2165
|
if (link.dc && link.dc.readyState === "open") {
|
|
@@ -2176,6 +2192,9 @@ createApp({
|
|
|
2176
2192
|
return;
|
|
2177
2193
|
}
|
|
2178
2194
|
const peerId = message.from;
|
|
2195
|
+
if (peerId === fromPeer.value) {
|
|
2196
|
+
return;
|
|
2197
|
+
}
|
|
2179
2198
|
const rejectCode = message.body?.code || "connect_reject";
|
|
2180
2199
|
const link = getMeshLink(peerId);
|
|
2181
2200
|
link.connectRequested = false;
|
|
@@ -2205,6 +2224,9 @@ createApp({
|
|
|
2205
2224
|
return;
|
|
2206
2225
|
}
|
|
2207
2226
|
const peerId = message.from;
|
|
2227
|
+
if (peerId === fromPeer.value) {
|
|
2228
|
+
return;
|
|
2229
|
+
}
|
|
2208
2230
|
|
|
2209
2231
|
if (!hasMeshCapacityForPeer(peerId)) {
|
|
2210
2232
|
sendRelayEnvelope(
|
|
@@ -2288,6 +2310,9 @@ createApp({
|
|
|
2288
2310
|
return;
|
|
2289
2311
|
}
|
|
2290
2312
|
const peerId = message.from;
|
|
2313
|
+
if (peerId === fromPeer.value) {
|
|
2314
|
+
return;
|
|
2315
|
+
}
|
|
2291
2316
|
const link = getMeshLink(peerId, false);
|
|
2292
2317
|
if (!link?.pc || link.phase === "connected") {
|
|
2293
2318
|
return;
|
|
@@ -2331,6 +2356,10 @@ createApp({
|
|
|
2331
2356
|
return;
|
|
2332
2357
|
}
|
|
2333
2358
|
|
|
2359
|
+
if (message.from === fromPeer.value) {
|
|
2360
|
+
return;
|
|
2361
|
+
}
|
|
2362
|
+
|
|
2334
2363
|
const link = getMeshLink(message.from);
|
|
2335
2364
|
if (!Array.isArray(link.pendingCandidates)) {
|
|
2336
2365
|
link.pendingCandidates = [];
|
|
@@ -7,7 +7,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
7
7
|
import { WebSocketServer } from 'ws';
|
|
8
8
|
|
|
9
9
|
const PSP_VERSION = '1.0';
|
|
10
|
-
const WORKER_VERSION = '0.1.
|
|
10
|
+
const WORKER_VERSION = '0.1.20';
|
|
11
11
|
const DEFAULT_TTL_MS = 30_000;
|
|
12
12
|
const MAX_TTL_MS = 120_000;
|
|
13
13
|
const MAX_MESSAGE_SIZE = 64 * 1024;
|
|
@@ -52,7 +52,15 @@ async function maybeSelfHealInstall() {
|
|
|
52
52
|
const projectRoot = process.env.INIT_CWD ? path.resolve(process.env.INIT_CWD) : null;
|
|
53
53
|
if (!projectRoot) return;
|
|
54
54
|
if (projectRoot === PACKAGE_ROOT) return;
|
|
55
|
-
|
|
55
|
+
const projectPackagePath = path.join(projectRoot, 'package.json');
|
|
56
|
+
if (!fs.existsSync(projectPackagePath)) return;
|
|
57
|
+
|
|
58
|
+
let hostPackage;
|
|
59
|
+
try {
|
|
60
|
+
hostPackage = JSON.parse(fs.readFileSync(projectPackagePath, 'utf8'));
|
|
61
|
+
} catch {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
56
64
|
|
|
57
65
|
let latestVersion;
|
|
58
66
|
try {
|
|
@@ -61,15 +69,30 @@ async function maybeSelfHealInstall() {
|
|
|
61
69
|
return;
|
|
62
70
|
}
|
|
63
71
|
|
|
64
|
-
|
|
72
|
+
let dependencyRewritten = false;
|
|
73
|
+
for (const section of ['dependencies', 'devDependencies', 'optionalDependencies']) {
|
|
74
|
+
const table = hostPackage?.[section];
|
|
75
|
+
if (table && typeof table === 'object' && Object.prototype.hasOwnProperty.call(table, 'freertc') && table.freertc !== 'latest') {
|
|
76
|
+
table.freertc = 'latest';
|
|
77
|
+
dependencyRewritten = true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (dependencyRewritten) {
|
|
82
|
+
fs.writeFileSync(projectPackagePath, `${JSON.stringify(hostPackage, null, 2)}\n`, 'utf8');
|
|
83
|
+
console.log('freertc postinstall updated host package.json dependency to "latest".');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const needsUpgrade = compareVersions(CLI_VERSION, latestVersion) < 0;
|
|
87
|
+
if (!needsUpgrade && !dependencyRewritten) {
|
|
65
88
|
return;
|
|
66
89
|
}
|
|
67
90
|
|
|
68
|
-
console.log(`freertc postinstall
|
|
91
|
+
console.log(`freertc postinstall syncing host project to latest (${latestVersion})...`);
|
|
69
92
|
|
|
70
93
|
const installResult = spawnSync(
|
|
71
94
|
'npm',
|
|
72
|
-
['install'
|
|
95
|
+
['install'],
|
|
73
96
|
{
|
|
74
97
|
cwd: projectRoot,
|
|
75
98
|
stdio: 'inherit',
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const PSP_VERSION = "1.0";
|
|
2
|
-
const WORKER_VERSION = "0.1.
|
|
2
|
+
const WORKER_VERSION = "0.1.20";
|
|
3
3
|
|
|
4
4
|
const DISCOVERY_TYPES = new Set(["announce", "withdraw", "discover", "peer_list", "redirect"]);
|
|
5
5
|
const NEGOTIATION_TYPES = new Set(["connect_request", "connect_accept", "connect_reject", "offer", "answer", "ice_candidate", "ice_end", "renegotiate"]);
|
|
@@ -554,6 +554,11 @@ async function handleClientMessage(socket, rawData, env, ctx, prevPeerKey = null
|
|
|
554
554
|
const db = env.DB;
|
|
555
555
|
const peerKey = `${network}:${peerId}`;
|
|
556
556
|
|
|
557
|
+
// Never relay or process peer-to-peer negotiation from a peer to itself.
|
|
558
|
+
if (message.to && message.to === peerId && RELAY_TYPES.has(type)) {
|
|
559
|
+
return { peerKey, network, peerId };
|
|
560
|
+
}
|
|
561
|
+
|
|
557
562
|
// Subscribe to network on first message and whenever network changes on the same socket.
|
|
558
563
|
if (!prevPeerKey || prevNetwork !== network) {
|
|
559
564
|
if (prevNetwork && prevNetwork !== network) {
|
|
@@ -660,6 +665,7 @@ async function handleClientMessage(socket, rawData, env, ctx, prevPeerKey = null
|
|
|
660
665
|
} else if (RELAY_TYPES.has(type)) {
|
|
661
666
|
// RTC negotiation messages - relay immediately if online, queue if offline
|
|
662
667
|
if (!message.to) return { peerKey, network, peerId };
|
|
668
|
+
if (message.to === peerId) return { peerKey, network, peerId };
|
|
663
669
|
|
|
664
670
|
// Try immediate delivery to live peer
|
|
665
671
|
const liveKey = `${network}:${message.to}`;
|