freertc 0.1.8 → 0.1.9
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/bin/freertc.mjs +72 -0
- package/package.json +1 -1
- package/scripts/non-cloudflare-server.mjs +1 -1
- package/src/index.js +1 -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.9","protocol_version":"1.0","peers":0}
|
|
220
220
|
```
|
|
221
221
|
|
|
222
222
|
## Auto WebRTC two-tab test
|
package/bin/freertc.mjs
CHANGED
|
@@ -65,6 +65,77 @@ function requireWranglerConfig() {
|
|
|
65
65
|
process.exit(1);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
function normalizeHost(value) {
|
|
69
|
+
if (!value || typeof value !== 'string') return null;
|
|
70
|
+
let host = value.trim().toLowerCase();
|
|
71
|
+
if (!host) return null;
|
|
72
|
+
host = host.replace(/^https?:\/\//, '');
|
|
73
|
+
host = host.replace(/^wss?:\/\//, '');
|
|
74
|
+
host = host.replace(/\/.*$/, '');
|
|
75
|
+
host = host.replace(/:\d+$/, '');
|
|
76
|
+
return host || null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function sanitizeDomain(domain) {
|
|
80
|
+
if (!domain || typeof domain !== 'string') return null;
|
|
81
|
+
return domain
|
|
82
|
+
.trim()
|
|
83
|
+
.toLowerCase()
|
|
84
|
+
.replace(/[^a-z0-9-]/g, '-')
|
|
85
|
+
.replace(/-+/g, '-')
|
|
86
|
+
.replace(/^-|-$/g, '') || null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function patchJsoncVar(text, varName, value) {
|
|
90
|
+
const escaped = varName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
91
|
+
const re = new RegExp(`("${escaped}"\\s*:\\s*)"[^"]*"`, 'g');
|
|
92
|
+
if (re.test(text)) {
|
|
93
|
+
return text.replace(re, `$1"${value}"`);
|
|
94
|
+
}
|
|
95
|
+
return text;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function extractRouteHost(configText) {
|
|
99
|
+
const routeMatch = configText.match(/"pattern"\s*:\s*"([^"]+)"/);
|
|
100
|
+
if (!routeMatch) return null;
|
|
101
|
+
const pattern = routeMatch[1];
|
|
102
|
+
return normalizeHost(pattern.split('/')[0]);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function extractRelayUrlHost(configText) {
|
|
106
|
+
const relayUrlMatch = configText.match(/"RELAY_URL"\s*:\s*"([^"]*)"/);
|
|
107
|
+
if (!relayUrlMatch) return null;
|
|
108
|
+
const raw = relayUrlMatch[1];
|
|
109
|
+
if (/your-domain\.example/i.test(raw)) return null;
|
|
110
|
+
return normalizeHost(raw);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function autoPatchWranglerConfig(configPath) {
|
|
114
|
+
let text = fs.readFileSync(configPath, 'utf8');
|
|
115
|
+
|
|
116
|
+
const routeHost = extractRouteHost(text);
|
|
117
|
+
const envDomainHost = normalizeHost(process.env.CF_DOMAIN || process.env.CLOUD_FLARE_DOMAIN || '');
|
|
118
|
+
const relayHost = routeHost || envDomainHost || extractRelayUrlHost(text);
|
|
119
|
+
|
|
120
|
+
if (!relayHost) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const relayWsUrl = `wss://${relayHost}/ws`;
|
|
125
|
+
const relayName = relayHost;
|
|
126
|
+
const dbName = `freertc-signal-${sanitizeDomain(relayHost)}`;
|
|
127
|
+
|
|
128
|
+
const before = text;
|
|
129
|
+
text = patchJsoncVar(text, 'RELAY_URL', relayWsUrl);
|
|
130
|
+
text = patchJsoncVar(text, 'RELAY_NAME', relayName);
|
|
131
|
+
text = text.replace(/("database_name"\s*:\s*)"freertc-signal(?:-your-domain)?"/g, `$1"${dbName}"`);
|
|
132
|
+
|
|
133
|
+
if (text !== before) {
|
|
134
|
+
fs.writeFileSync(configPath, text, 'utf8');
|
|
135
|
+
console.log(`Auto-patched wrangler.jsonc for deploy: RELAY_URL=${relayWsUrl}, RELAY_NAME=${relayName}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
68
139
|
function validateWranglerConfigForDeploy(configPath) {
|
|
69
140
|
const configText = fs.readFileSync(configPath, 'utf8');
|
|
70
141
|
const failures = [];
|
|
@@ -182,6 +253,7 @@ async function main() {
|
|
|
182
253
|
await assertLatestCliForDeploy();
|
|
183
254
|
ensureProjectFiles(PROJECT_ROOT);
|
|
184
255
|
const configPath = requireWranglerConfig();
|
|
256
|
+
autoPatchWranglerConfig(configPath);
|
|
185
257
|
validateWranglerConfigForDeploy(configPath);
|
|
186
258
|
const wrangler = resolveWranglerCommand(PROJECT_ROOT);
|
|
187
259
|
runInProject(wrangler.command, [...wrangler.baseArgs, 'deploy', '--env', 'production', ...rest]);
|
package/package.json
CHANGED
|
@@ -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.9';
|
|
11
11
|
const DEFAULT_TTL_MS = 30_000;
|
|
12
12
|
const MAX_TTL_MS = 120_000;
|
|
13
13
|
const MAX_MESSAGE_SIZE = 64 * 1024;
|
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.9";
|
|
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"]);
|