freertc 0.1.5 → 0.1.7
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 +86 -28
- package/package.json +2 -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.7","protocol_version":"1.0","peers":0}
|
|
220
220
|
```
|
|
221
221
|
|
|
222
222
|
## Auto WebRTC two-tab test
|
package/bin/freertc.mjs
CHANGED
|
@@ -9,6 +9,8 @@ import { ensureProjectFiles, resolveProjectRoot, resolveWranglerCommand } from '
|
|
|
9
9
|
const __filename = fileURLToPath(import.meta.url);
|
|
10
10
|
const PACKAGE_ROOT = path.resolve(path.dirname(__filename), '..');
|
|
11
11
|
const PROJECT_ROOT = resolveProjectRoot(process.cwd());
|
|
12
|
+
const PACKAGE_JSON = JSON.parse(fs.readFileSync(path.join(PACKAGE_ROOT, 'package.json'), 'utf8'));
|
|
13
|
+
const CLI_VERSION = PACKAGE_JSON.version;
|
|
12
14
|
|
|
13
15
|
function printHelp() {
|
|
14
16
|
console.log(`freertc CLI
|
|
@@ -63,44 +65,100 @@ function requireWranglerConfig() {
|
|
|
63
65
|
process.exit(1);
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
|
|
68
|
+
function compareVersions(left, right) {
|
|
69
|
+
const leftParts = String(left).split('.').map((value) => Number.parseInt(value, 10) || 0);
|
|
70
|
+
const rightParts = String(right).split('.').map((value) => Number.parseInt(value, 10) || 0);
|
|
71
|
+
const length = Math.max(leftParts.length, rightParts.length);
|
|
67
72
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
73
|
+
for (let index = 0; index < length; index += 1) {
|
|
74
|
+
const leftValue = leftParts[index] ?? 0;
|
|
75
|
+
const rightValue = rightParts[index] ?? 0;
|
|
76
|
+
if (leftValue > rightValue) return 1;
|
|
77
|
+
if (leftValue < rightValue) return -1;
|
|
78
|
+
}
|
|
71
79
|
|
|
72
|
-
|
|
73
|
-
printHelp();
|
|
74
|
-
process.exit(0);
|
|
80
|
+
return 0;
|
|
75
81
|
}
|
|
76
82
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
83
|
+
async function fetchLatestCliVersion() {
|
|
84
|
+
const response = await fetch('https://registry.npmjs.org/freertc/latest', {
|
|
85
|
+
headers: { Accept: 'application/json' }
|
|
86
|
+
});
|
|
87
|
+
if (!response.ok) {
|
|
88
|
+
throw new Error(`npm registry responded with ${response.status}`);
|
|
89
|
+
}
|
|
80
90
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
91
|
+
const payload = await response.json();
|
|
92
|
+
const version = payload?.version;
|
|
93
|
+
if (typeof version !== 'string' || !version.trim()) {
|
|
94
|
+
throw new Error('npm registry response did not include a version');
|
|
95
|
+
}
|
|
84
96
|
|
|
85
|
-
|
|
86
|
-
runInProject(process.execPath, [path.join(PACKAGE_ROOT, 'scripts', 'wrangler-install-wizard.mjs'), '--mode', 'both', ...rest], { bootstrap: true });
|
|
97
|
+
return version;
|
|
87
98
|
}
|
|
88
99
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
runInProject(wrangler.command, [...wrangler.baseArgs, 'deploy', '--env', 'production', ...rest]);
|
|
94
|
-
}
|
|
100
|
+
async function assertLatestCliForDeploy() {
|
|
101
|
+
if (process.env.FREERTC_SKIP_LATEST_CHECK === '1') {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
95
104
|
|
|
96
|
-
|
|
97
|
-
|
|
105
|
+
try {
|
|
106
|
+
const latestVersion = await fetchLatestCliVersion();
|
|
107
|
+
if (compareVersions(CLI_VERSION, latestVersion) < 0) {
|
|
108
|
+
console.error(`freertc ${CLI_VERSION} is older than npm latest ${latestVersion}.`);
|
|
109
|
+
console.error('Use "npx freertc@latest deploy" or update the local freertc dependency before deploying.');
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error(`Unable to verify freertc version before deploy: ${error?.message || String(error)}`);
|
|
114
|
+
console.error('Set FREERTC_SKIP_LATEST_CHECK=1 to bypass this check if you need an offline deploy.');
|
|
115
|
+
process.exit(1);
|
|
116
|
+
}
|
|
98
117
|
}
|
|
99
118
|
|
|
100
|
-
|
|
101
|
-
|
|
119
|
+
async function main() {
|
|
120
|
+
const [, , subcommand, ...rest] = process.argv;
|
|
121
|
+
|
|
122
|
+
if (!subcommand) {
|
|
123
|
+
runInProject(process.execPath, [path.join(PACKAGE_ROOT, 'scripts', 'wrangler-install-wizard.mjs'), '--mode', 'both'], { bootstrap: true });
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (subcommand === '--help' || subcommand === '-h' || subcommand === 'help') {
|
|
127
|
+
printHelp();
|
|
128
|
+
process.exit(0);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (subcommand === 'wizard') {
|
|
132
|
+
runInProject(process.execPath, [path.join(PACKAGE_ROOT, 'scripts', 'wrangler-install-wizard.mjs'), ...rest], { bootstrap: true });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (subcommand === 'setup') {
|
|
136
|
+
runInProject(process.execPath, [path.join(PACKAGE_ROOT, 'scripts', 'wrangler-install-wizard.mjs'), '--mode', 'both', ...rest], { bootstrap: true });
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (subcommand === 'init' || subcommand === 'install') {
|
|
140
|
+
runInProject(process.execPath, [path.join(PACKAGE_ROOT, 'scripts', 'wrangler-install-wizard.mjs'), '--mode', 'both', ...rest], { bootstrap: true });
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (subcommand === 'deploy') {
|
|
144
|
+
await assertLatestCliForDeploy();
|
|
145
|
+
ensureProjectFiles(PROJECT_ROOT);
|
|
146
|
+
requireWranglerConfig();
|
|
147
|
+
const wrangler = resolveWranglerCommand(PROJECT_ROOT);
|
|
148
|
+
runInProject(wrangler.command, [...wrangler.baseArgs, 'deploy', '--env', 'production', ...rest]);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (subcommand === 'dev') {
|
|
152
|
+
runInProject(process.execPath, [path.join(PACKAGE_ROOT, 'scripts', 'non-cloudflare-server.mjs'), ...rest], { bootstrap: true });
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (subcommand === 'dev:cf' || subcommand === 'dev-cf') {
|
|
156
|
+
runInProject(process.execPath, [path.join(PACKAGE_ROOT, 'scripts', 'dev-server.mjs'), ...rest], { bootstrap: true });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
console.error(`Unknown command: ${subcommand}\n`);
|
|
160
|
+
printHelp();
|
|
161
|
+
process.exit(1);
|
|
102
162
|
}
|
|
103
163
|
|
|
104
|
-
|
|
105
|
-
printHelp();
|
|
106
|
-
process.exit(1);
|
|
164
|
+
await main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "freertc",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Cloudflare Worker signaling relay for WebRTC peers with D1 storage.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webrtc",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"wrangler.workers-dev.jsonc"
|
|
41
41
|
],
|
|
42
42
|
"scripts": {
|
|
43
|
+
"prepack": "node scripts/sync-worker-version.mjs",
|
|
43
44
|
"build": "worker-build --release",
|
|
44
45
|
"dev": "node scripts/non-cloudflare-server.mjs",
|
|
45
46
|
"dev:cf": "node scripts/dev-server.mjs",
|
|
@@ -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.7';
|
|
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.7";
|
|
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"]);
|