freertc 0.1.2 → 0.1.4

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 CHANGED
@@ -216,7 +216,7 @@ Quick checks:
216
216
  Expected `/health` response includes JSON like:
217
217
 
218
218
  ```json
219
- {"ok":true,"version":"1.0","peers":0}
219
+ {"ok":true,"version":"0.1.3","protocol_version":"1.0","peers":0}
220
220
  ```
221
221
 
222
222
  ## Auto WebRTC two-tab test
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "freertc",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Cloudflare Worker signaling relay for WebRTC peers with D1 storage.",
5
5
  "keywords": [
6
6
  "webrtc",
@@ -7,6 +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.3';
10
11
  const DEFAULT_TTL_MS = 30_000;
11
12
  const MAX_TTL_MS = 120_000;
12
13
  const MAX_MESSAGE_SIZE = 64 * 1024;
@@ -387,7 +388,12 @@ const server = createServer((req, res) => {
387
388
 
388
389
  const reqUrl = new URL(req.url, `http://${req.headers.host || 'localhost'}`);
389
390
  if (reqUrl.pathname === '/health') {
390
- json(res, { ok: true, version: PSP_VERSION, peers: livePeers.size }, 200);
391
+ json(res, {
392
+ ok: true,
393
+ version: WORKER_VERSION,
394
+ protocol_version: PSP_VERSION,
395
+ peers: livePeers.size,
396
+ }, 200);
391
397
  return;
392
398
  }
393
399
 
@@ -65,22 +65,22 @@ export function ensureProjectFiles(projectRoot) {
65
65
  return [];
66
66
  }
67
67
 
68
- const copied = [];
68
+ const synced = [];
69
69
 
70
70
  for (const [sourceRelativePath, targetRelativePath] of PROJECT_FILE_MAPPINGS) {
71
71
  const sourcePath = path.join(PACKAGE_ROOT, sourceRelativePath);
72
72
  const targetPath = path.join(targetRoot, targetRelativePath);
73
73
 
74
- if (fs.existsSync(targetPath) || !fs.existsSync(sourcePath)) {
74
+ if (!fs.existsSync(sourcePath)) {
75
75
  continue;
76
76
  }
77
77
 
78
78
  fs.mkdirSync(path.dirname(targetPath), { recursive: true });
79
79
  fs.copyFileSync(sourcePath, targetPath);
80
- copied.push(targetRelativePath);
80
+ synced.push(targetRelativePath);
81
81
  }
82
82
 
83
- return copied;
83
+ return synced;
84
84
  }
85
85
 
86
86
  export function resolveWranglerCommand(cwd = process.cwd()) {
@@ -416,7 +416,7 @@ async function main() {
416
416
  }
417
417
 
418
418
  if (copiedFiles.length > 0) {
419
- console.log('Copied package files into this project:');
419
+ console.log('Overwrote package-managed files in this project:');
420
420
  for (const file of copiedFiles) {
421
421
  console.log(` - ${file}`);
422
422
  }
@@ -447,7 +447,7 @@ async function main() {
447
447
  if (copiedFiles.length === 0) {
448
448
  console.log('Required worker files already exist in this project.');
449
449
  } else {
450
- console.log('Project bootstrapped from the published freertc package.');
450
+ console.log('Project files overwritten from the published freertc package.');
451
451
  }
452
452
 
453
453
  resolveWrangler();
package/src/index.js CHANGED
@@ -63,7 +63,12 @@ export default {
63
63
  }
64
64
 
65
65
  if (url.pathname === "/health") {
66
- return jsonResponse({ ok: true, version: PSP_VERSION, peers: livePeers.size }, 200);
66
+ return jsonResponse({
67
+ ok: true,
68
+ version: WORKER_VERSION,
69
+ protocol_version: PSP_VERSION,
70
+ peers: livePeers.size
71
+ }, 200);
67
72
  }
68
73
 
69
74
  // Federation: relay registry endpoints (any worker can serve these from its own D1)
@@ -227,15 +232,29 @@ async function forwardToRelay(relayUrl, message, selfRelayId) {
227
232
  const ws = resp.webSocket;
228
233
  ws.accept();
229
234
 
230
- // Outbound Worker WebSocket: send immediately after accept(), no open event needed
231
- const relayPeerId = selfRelayId || "relay-bridge";
232
- ws.send(JSON.stringify({
233
- psp_version: PSP_VERSION, type: "announce", network: message.network,
234
- from: relayPeerId, message_id: crypto.randomUUID(),
235
- timestamp: Date.now(), ttl_ms: 10_000, body: { capabilities: { relay: true } }
236
- }));
237
- ws.send(JSON.stringify(message));
238
- ws.close();
235
+ await new Promise((resolve) => {
236
+ const relayPeerId = selfRelayId || "relay-bridge";
237
+ const closeTimer = setTimeout(() => {
238
+ try { ws.close(); } catch {}
239
+ resolve();
240
+ }, 250);
241
+
242
+ const finish = () => {
243
+ clearTimeout(closeTimer);
244
+ resolve();
245
+ };
246
+
247
+ ws.addEventListener("error", finish, { once: true });
248
+ ws.addEventListener("close", finish, { once: true });
249
+
250
+ // Outbound Worker WebSocket: send immediately after accept(), no open event needed.
251
+ ws.send(JSON.stringify({
252
+ psp_version: PSP_VERSION, type: "announce", network: message.network,
253
+ from: relayPeerId, message_id: crypto.randomUUID(),
254
+ timestamp: Date.now(), ttl_ms: 10_000, body: { capabilities: { relay: true } }
255
+ }));
256
+ ws.send(JSON.stringify(message));
257
+ });
239
258
  } catch {}
240
259
  }
241
260