c64-ready 0.6.1 → 0.10.0
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/LICENSE +22 -0
- package/README.md +91 -22
- package/bin/admin.mjs +196 -0
- package/bin/headless.mjs +26 -3
- package/bin/serve.mjs +9 -3
- package/package.json +6 -2
- package/public/games/cartridges/bubble-bobble.crt +0 -0
- package/public/games/cartridges/ghosts-n-goblins.crt +0 -0
- package/src/emulator/crt-info.ts +210 -0
- package/src/emulator/input.ts +542 -7
- package/src/headless/c64-key-map.mjs +254 -0
- package/src/headless/c64-wasm.mjs +4 -1
- package/src/headless/headless-cli.mjs +776 -123
- package/src/headless/input-server.mjs +855 -14
- package/src/headless/webrtc-encoder.mjs +251 -0
- package/src/headless/webrtc-server.mjs +1327 -0
- package/src/main.ts +5 -5
- package/src/player/c64-player.ts +24 -6
- package/src/player/input-handler.ts +22 -6
- package/src/player/ui-controller.ts +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 hayesmaker
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
CHANGED
|
@@ -59,53 +59,120 @@ npm run test:watch
|
|
|
59
59
|
|
|
60
60
|
## Headless streaming (Docker)
|
|
61
61
|
|
|
62
|
-
The headless player
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
| Container | Role |
|
|
66
|
-
|-----------|------|
|
|
67
|
-
| `c64-nms` | [Node Media Server](https://github.com/illuspas/Node-Media-Server) — RTMP ingest on `:1935`, HTTP-FLV on `:8000` |
|
|
68
|
-
| `c64-headless` | Headless C64 emulator — encodes frames with ffmpeg and pushes to NMS over RTMP |
|
|
62
|
+
The headless player streams the C64 output over **WebRTC** — a single container serves
|
|
63
|
+
a self-contained browser player page with sub-100ms latency and a built-in keyboard/
|
|
64
|
+
joystick input channel. No separate media server is required.
|
|
69
65
|
|
|
70
66
|
**Prerequisites:** Docker and Docker Compose v2.
|
|
71
67
|
|
|
72
68
|
### Quick start
|
|
73
69
|
|
|
70
|
+
#### With NPM
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
npx c64-ready```
|
|
74
|
+
```
|
|
75
|
+
This starts a static server that serves the browser player on `http://localhost:5173/c64-ready/` by default.
|
|
76
|
+
|
|
77
|
+
#### With Docker
|
|
78
|
+
|
|
74
79
|
```zsh
|
|
75
|
-
# 1. Copy the env file
|
|
80
|
+
# 1. Copy the env file and edit to taste (defaults: BASIC prompt, WebRTC on :9002)
|
|
76
81
|
cp docker/.env.example docker/.env
|
|
77
82
|
|
|
78
|
-
# 2. Build and start
|
|
83
|
+
# 2. Build and start
|
|
79
84
|
docker compose up --build
|
|
80
85
|
|
|
81
|
-
# 3.
|
|
82
|
-
|
|
83
|
-
# or open in VLC / OBS: http://localhost:8000/live/c64.flv
|
|
86
|
+
# 3. Open the player in a browser
|
|
87
|
+
open http://localhost:9002
|
|
84
88
|
```
|
|
85
89
|
|
|
90
|
+
The player page is self-contained — video, audio, and keyboard/joystick input are all
|
|
91
|
+
handled in the browser with no extra software needed.
|
|
92
|
+
|
|
86
93
|
### Load a cartridge
|
|
87
94
|
|
|
88
95
|
Games are bind-mounted from `public/games/` — no rebuild needed:
|
|
89
96
|
|
|
90
97
|
```zsh
|
|
98
|
+
# Set GAME_PATH in docker/.env, then restart
|
|
99
|
+
docker compose restart headless
|
|
100
|
+
|
|
101
|
+
# Or override inline for a one-off run
|
|
91
102
|
GAME_PATH=/app/public/games/cartridges/legend-of-wilf.crt docker compose up
|
|
92
103
|
```
|
|
93
104
|
|
|
105
|
+
You can also drag-and-drop a `.crt` file onto the player page at any time to load it
|
|
106
|
+
without restarting the container.
|
|
107
|
+
|
|
94
108
|
### Environment variables
|
|
95
109
|
|
|
96
|
-
All options
|
|
110
|
+
All options live in `docker/.env` (copy from `docker/.env.example`). See that file for
|
|
111
|
+
the full annotated list.
|
|
97
112
|
|
|
98
113
|
| Variable | Default | Description |
|
|
99
114
|
|----------|---------|-------------|
|
|
100
115
|
| `WASM_PATH` | `/app/public/c64.wasm` | Path to the WASM binary inside the container |
|
|
101
|
-
| `GAME_PATH` | *(empty)* | Cartridge
|
|
102
|
-
| `
|
|
103
|
-
| `
|
|
104
|
-
| `
|
|
105
|
-
| `
|
|
106
|
-
| `
|
|
107
|
-
| `
|
|
108
|
-
| `
|
|
116
|
+
| `GAME_PATH` | *(empty)* | Cartridge to load on startup — leave blank to boot to BASIC |
|
|
117
|
+
| `FPS` | `50` | Target frame rate (`50` = PAL, `60` = NTSC) |
|
|
118
|
+
| `AUDIO` | `1` | Set to `1` to include SID audio in the WebRTC stream |
|
|
119
|
+
| `DURATION` | *(empty = forever)* | Stop after this many seconds |
|
|
120
|
+
| `VERBOSE` | *(empty)* | Set to `1` for per-frame diagnostics in container logs |
|
|
121
|
+
| `LOG_EVENTS` | `1` | Log player joins/leaves, cart loads, input events |
|
|
122
|
+
| `WEBRTC_ENABLED` | `1` | Must be `1` — WebRTC is the only supported streaming mode |
|
|
123
|
+
| `WEBRTC_PORT` | `9002` | Port inside the container for the WebRTC server |
|
|
124
|
+
| `WEBRTC_HOST_PORT` | `9002` | Host-side port mapping for the WebRTC server |
|
|
125
|
+
| `MAX_SPECTATORS` | `3` | Max concurrent spectator connections (players are separate, see below) |
|
|
126
|
+
| `WEBRTC_MIN_BITRATE_KBPS` | `200` | VP8 SDP `x-google-min-bitrate` hint in kbps |
|
|
127
|
+
| `WEBRTC_MAX_BITRATE_KBPS` | `600` | VP8 SDP `x-google-max-bitrate` hint in kbps |
|
|
128
|
+
| `WEBRTC_OUTPUT_FPS` | `40` | Cap outgoing WebRTC video FPS (`0` disables cap) |
|
|
129
|
+
| `C64_ADMIN_TOKEN` | *(empty)* | Shared token required by `c64-admin` (`status`, `kick`) |
|
|
130
|
+
| `WS_PORT` | `9001` | WebSocket input server port inside the container |
|
|
131
|
+
| `WS_HOST_PORT` | `9001` | Host-side port mapping for the input WebSocket |
|
|
132
|
+
|
|
133
|
+
### Admin CLI
|
|
134
|
+
|
|
135
|
+
Use `c64-admin` to inspect active players/spectators and run admin actions over the input WebSocket:
|
|
136
|
+
|
|
137
|
+
```zsh
|
|
138
|
+
# show current room/client state
|
|
139
|
+
c64-admin --token "$C64_ADMIN_TOKEN" status
|
|
140
|
+
|
|
141
|
+
# kick a specific player slot
|
|
142
|
+
c64-admin --token "$C64_ADMIN_TOKEN" kick --player host
|
|
143
|
+
|
|
144
|
+
# kick all clients and disconnect all WebRTC peers
|
|
145
|
+
c64-admin --token "$C64_ADMIN_TOKEN" kick --all
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
#### Spectator limit
|
|
149
|
+
|
|
150
|
+
Up to **2 player slots** (host + P2) are always reserved. `MAX_SPECTATORS` controls how
|
|
151
|
+
many additional viewers can connect simultaneously. Total WebRTC peers = `MAX_SPECTATORS + 2`.
|
|
152
|
+
Connections beyond the limit receive a `capacity-full` message and are rejected immediately.
|
|
153
|
+
|
|
154
|
+
### FFmpeg recording / capture
|
|
155
|
+
|
|
156
|
+
FFmpeg can be used alongside the WebRTC stream for local recording or debugging. Pass
|
|
157
|
+
`--record` to the CLI to enable it — both modes run concurrently:
|
|
158
|
+
|
|
159
|
+
```zsh
|
|
160
|
+
# Record a 60-second session to a file (no Docker needed)
|
|
161
|
+
node bin/headless.mjs --wasm public/c64.wasm --no-game \
|
|
162
|
+
--record --output out.mp4 --duration 60
|
|
163
|
+
|
|
164
|
+
# WebRTC stream + simultaneous local recording
|
|
165
|
+
node bin/headless.mjs --wasm public/c64.wasm --game public/games/cartridges/game.crt \
|
|
166
|
+
--webrtc --webrtc-port 9002 \
|
|
167
|
+
--record --output recording.mp4 \
|
|
168
|
+
--input --ws-port 9001 --fps 50
|
|
169
|
+
|
|
170
|
+
# Push to an RTMP endpoint (e.g. for OBS / Twitch ingest)
|
|
171
|
+
node bin/headless.mjs --wasm public/c64.wasm --no-game \
|
|
172
|
+
--record --output rtmp://localhost:1935/live/c64
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
`ffmpeg` must be on `PATH` for `--record` to work.
|
|
109
176
|
|
|
110
177
|
### Stop
|
|
111
178
|
|
|
@@ -470,6 +537,9 @@ On every push to `master`:
|
|
|
470
537
|
- [x] Docker headless streaming (RTMP / HTTP-FLV via Node Media Server)
|
|
471
538
|
- [ ] Gamepad support
|
|
472
539
|
- [ ] Touch controls
|
|
540
|
+
- [ ] Loading more game formats (e.g., .d64 disk images)
|
|
541
|
+
- [ ] Performance optimizations (e.g., offscreen canvas, audio worklets)
|
|
542
|
+
- [ ] Fix creeping video jitter (currently starts at 100ms and grows over time)
|
|
473
543
|
|
|
474
544
|
## Changelog & Releases
|
|
475
545
|
|
|
@@ -502,4 +572,3 @@ on every push to `master`. To publish manually:
|
|
|
502
572
|
```bash
|
|
503
573
|
./tools/publish_wiki.sh git@github.com:YOUR_USER/c64-ready.wiki.git
|
|
504
574
|
```
|
|
505
|
-
|
package/bin/admin.mjs
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import WebSocket from 'ws';
|
|
4
|
+
|
|
5
|
+
function printHelp() {
|
|
6
|
+
console.log(`
|
|
7
|
+
c64-admin - admin commands for c64-headless input server
|
|
8
|
+
|
|
9
|
+
Usage:
|
|
10
|
+
c64-admin [global options] <command> [command options]
|
|
11
|
+
|
|
12
|
+
Global options:
|
|
13
|
+
--ws-url <url> Input WS URL (default: ws://127.0.0.1:9001)
|
|
14
|
+
--token <token> Admin token (or set C64_ADMIN_TOKEN)
|
|
15
|
+
--json Output JSON
|
|
16
|
+
--help Show help
|
|
17
|
+
|
|
18
|
+
Commands:
|
|
19
|
+
status
|
|
20
|
+
Show host/p2/spectator state and WebRTC peer counts.
|
|
21
|
+
|
|
22
|
+
kick --player <host|p2>
|
|
23
|
+
Kick one player.
|
|
24
|
+
|
|
25
|
+
kick --all
|
|
26
|
+
Kick host, p2, all spectators, and disconnect all WebRTC peers.
|
|
27
|
+
|
|
28
|
+
Examples:
|
|
29
|
+
c64-admin --token "$C64_ADMIN_TOKEN" status
|
|
30
|
+
c64-admin --token "$C64_ADMIN_TOKEN" kick --player host
|
|
31
|
+
c64-admin --token "$C64_ADMIN_TOKEN" kick --all
|
|
32
|
+
`.trim());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function parseArgs(argv) {
|
|
36
|
+
const args = [...argv];
|
|
37
|
+
let wsUrl = process.env.C64_INPUT_WS_URL || 'ws://127.0.0.1:9001';
|
|
38
|
+
let token = process.env.C64_ADMIN_TOKEN || '';
|
|
39
|
+
let json = false;
|
|
40
|
+
const positional = [];
|
|
41
|
+
|
|
42
|
+
for (let i = 0; i < args.length; i++) {
|
|
43
|
+
const a = args[i];
|
|
44
|
+
if (a === '--help' || a === '-h') return { help: true };
|
|
45
|
+
if (a === '--ws-url') wsUrl = args[++i] ?? wsUrl;
|
|
46
|
+
else if (a === '--token') token = args[++i] ?? token;
|
|
47
|
+
else if (a === '--json') json = true;
|
|
48
|
+
else positional.push(a);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const command = positional[0] ?? null;
|
|
52
|
+
const commandArgs = positional.slice(1);
|
|
53
|
+
return { help: false, wsUrl, token, json, command, commandArgs };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function parseCommand(command, commandArgs) {
|
|
57
|
+
if (command === 'status') {
|
|
58
|
+
return { type: 'admin-status' };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (command === 'kick') {
|
|
62
|
+
let target = null;
|
|
63
|
+
let all = false;
|
|
64
|
+
for (let i = 0; i < commandArgs.length; i++) {
|
|
65
|
+
const a = commandArgs[i];
|
|
66
|
+
if (a === '--all') all = true;
|
|
67
|
+
else if (a === '--player') target = commandArgs[++i] ?? null;
|
|
68
|
+
}
|
|
69
|
+
if (all && target) throw new Error('Use either --all or --player, not both.');
|
|
70
|
+
if (!all && !target) throw new Error('kick requires --all or --player <host|p2>.');
|
|
71
|
+
if (all) return { type: 'admin-kick-all' };
|
|
72
|
+
if (target !== 'host' && target !== 'p2') throw new Error('kick --player must be host or p2.');
|
|
73
|
+
return { type: 'admin-kick-player', target };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
throw new Error(`Unknown command: ${command ?? '(none)'}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function renderStatus(status) {
|
|
80
|
+
const lines = [];
|
|
81
|
+
const host = status?.host;
|
|
82
|
+
const p2 = status?.p2;
|
|
83
|
+
const spectators = Array.isArray(status?.spectators) ? status.spectators : [];
|
|
84
|
+
const counts = status?.counts ?? {};
|
|
85
|
+
|
|
86
|
+
if (host) {
|
|
87
|
+
lines.push(`Host: ${host.username ?? '-'} (${host.connected ? 'connected' : 'disconnected'}) addr=${host.addr ?? '-'} webrtcPeers=${host.webrtcPeers ?? 0}`);
|
|
88
|
+
} else {
|
|
89
|
+
lines.push('Host: (none)');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (p2) {
|
|
93
|
+
lines.push(`P2: ${p2.username ?? '-'} (${p2.connected ? 'connected' : 'disconnected'}) addr=${p2.addr ?? '-'} webrtcPeers=${p2.webrtcPeers ?? 0}`);
|
|
94
|
+
} else {
|
|
95
|
+
lines.push('P2: (none)');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
lines.push(`Spectators: ${spectators.length}`);
|
|
99
|
+
spectators.forEach((s, idx) => {
|
|
100
|
+
lines.push(` ${idx + 1}. addr=${s.addr ?? '-'} webrtcPeers=${s.webrtcPeers ?? 0}`);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
lines.push(`Counts: inputClients=${counts.inputClients ?? 0} spectators=${counts.spectators ?? 0} webrtcActive=${counts.webrtcActive ?? 0} webrtcPending=${counts.webrtcPending ?? 0} webrtcTotal=${counts.webrtcTotal ?? 0} webrtcAnonymous=${counts.anonymousWebrtcPeers ?? 0}`);
|
|
104
|
+
return lines.join('\n');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function callAdmin(wsUrl, payload, timeoutMs = 7000) {
|
|
108
|
+
return new Promise((resolve, reject) => {
|
|
109
|
+
const ws = new WebSocket(wsUrl);
|
|
110
|
+
let settled = false;
|
|
111
|
+
const finish = (fn, value) => {
|
|
112
|
+
if (settled) return;
|
|
113
|
+
settled = true;
|
|
114
|
+
clearTimeout(timer);
|
|
115
|
+
try { ws.close(); } catch (_) {}
|
|
116
|
+
fn(value);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const timer = setTimeout(() => {
|
|
120
|
+
finish(reject, new Error('Timed out waiting for admin response.'));
|
|
121
|
+
}, timeoutMs);
|
|
122
|
+
|
|
123
|
+
ws.on('open', () => {
|
|
124
|
+
ws.send(JSON.stringify(payload));
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
ws.on('message', (data) => {
|
|
128
|
+
let msg;
|
|
129
|
+
try {
|
|
130
|
+
msg = JSON.parse(typeof data === 'string' ? data : data.toString('utf8'));
|
|
131
|
+
} catch {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (!msg || typeof msg !== 'object') return;
|
|
135
|
+
if (msg.type === 'hello') return;
|
|
136
|
+
if (msg.type === 'admin-status-ok' || msg.type === 'admin-kick-player-ok' || msg.type === 'admin-kick-all-ok') {
|
|
137
|
+
finish(resolve, msg);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (msg.type === 'admin-error') {
|
|
141
|
+
finish(reject, new Error(`Admin error: ${msg.command ?? 'unknown'} (${msg.reason ?? 'unknown'})`));
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
ws.on('error', (err) => {
|
|
146
|
+
finish(reject, err);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
ws.on('close', () => {
|
|
150
|
+
if (!settled) finish(reject, new Error('Connection closed before admin response.'));
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async function main() {
|
|
156
|
+
const parsed = parseArgs(process.argv.slice(2));
|
|
157
|
+
if (parsed.help) {
|
|
158
|
+
printHelp();
|
|
159
|
+
process.exit(0);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (!parsed.token) {
|
|
163
|
+
throw new Error('Missing admin token. Pass --token or set C64_ADMIN_TOKEN.');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const cmd = parseCommand(parsed.command, parsed.commandArgs);
|
|
167
|
+
const payload = { ...cmd, token: parsed.token };
|
|
168
|
+
const res = await callAdmin(parsed.wsUrl, payload);
|
|
169
|
+
|
|
170
|
+
if (parsed.json) {
|
|
171
|
+
console.log(JSON.stringify(res, null, 2));
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (res.type === 'admin-status-ok') {
|
|
176
|
+
console.log(renderStatus(res.status));
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (res.type === 'admin-kick-player-ok') {
|
|
181
|
+
console.log(`Kicked ${res.target}: ${res.username ?? '-'}`);
|
|
182
|
+
console.log(renderStatus(res.status));
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (res.type === 'admin-kick-all-ok') {
|
|
187
|
+
const kicked = res.kicked ?? {};
|
|
188
|
+
console.log(`Kick-all complete: host=${kicked.host ?? '-'} p2=${kicked.p2 ?? '-'} spectators=${kicked.spectators ?? 0} webrtcPeers=${kicked.webrtcPeers ?? 0}`);
|
|
189
|
+
console.log(renderStatus(res.status));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
main().catch((err) => {
|
|
194
|
+
console.error(`Error: ${err?.message ?? String(err)}`);
|
|
195
|
+
process.exit(1);
|
|
196
|
+
});
|
package/bin/headless.mjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) 2026 hayesmaker
|
|
4
|
+
// See LICENSE in the project root for full license information.
|
|
2
5
|
/**
|
|
3
6
|
* c64-headless — CLI entry point
|
|
4
7
|
*
|
|
@@ -51,16 +54,32 @@ Options:
|
|
|
51
54
|
--output <path|url> Output file path or rtmp:// stream URL
|
|
52
55
|
--duration <secs> Recording duration in seconds (omit for endless streaming)
|
|
53
56
|
--fps <n> Target frame rate (default: 50 for PAL)
|
|
57
|
+
--webrtc Start a WebRTC streaming server (low-latency; replaces RTMP+flv.js)
|
|
58
|
+
--webrtc-port <n> WebRTC signalling + player HTTP port (default: 9002)
|
|
59
|
+
--max-spectators <n> Max concurrent spectator WebRTC connections (default: 3)
|
|
60
|
+
Players count separately (up to 2), so total WebRTC peers = n+2.
|
|
61
|
+
New connections beyond this limit receive { type: 'capacity-full' }.
|
|
62
|
+
--webrtc-min-bitrate-kbps <n> VP8 SDP x-google-min-bitrate hint (default: 200)
|
|
63
|
+
--webrtc-max-bitrate-kbps <n> VP8 SDP x-google-max-bitrate hint (default: 600)
|
|
64
|
+
--webrtc-output-fps <n> Max WebRTC video send FPS cap (default: 40)
|
|
65
|
+
--admin-token <token> Shared admin token for c64-admin commands
|
|
54
66
|
--input Start WebSocket input server for remote control
|
|
55
67
|
--ws-port <n> WebSocket server port (default: 9001)
|
|
56
68
|
--verbose Print per-frame diagnostics to stderr
|
|
69
|
+
--log-events Log player joins/leaves, input events, emulator commands and
|
|
70
|
+
A/V drift warnings (non-verbose; safe for production)
|
|
57
71
|
--help Show this help
|
|
58
72
|
|
|
59
73
|
Prerequisites:
|
|
60
74
|
ffmpeg must be on PATH for --record
|
|
75
|
+
@roamhq/wrtc must be installed for --webrtc (npm install @roamhq/wrtc)
|
|
61
76
|
ws npm package must be installed for --input (it is a dependency of c64-ready)
|
|
62
77
|
|
|
63
78
|
Examples:
|
|
79
|
+
# Low-latency WebRTC stream (open http://localhost:9002 in a browser)
|
|
80
|
+
c64-headless --wasm public/c64.wasm --no-game --webrtc \\
|
|
81
|
+
--webrtc-port 9002 --input --ws-port 9001 --fps 50
|
|
82
|
+
|
|
64
83
|
# RTMP live stream (5 minutes)
|
|
65
84
|
c64-headless --wasm public/c64.wasm --no-game --record \\
|
|
66
85
|
--output rtmp://localhost:1935/live/c64 --duration 300
|
|
@@ -69,9 +88,9 @@ Examples:
|
|
|
69
88
|
c64-headless --wasm public/c64.wasm --no-game --record \\
|
|
70
89
|
--output out.mp4 --duration 30
|
|
71
90
|
|
|
72
|
-
#
|
|
73
|
-
c64-headless --wasm public/c64.wasm --game game.crt --
|
|
74
|
-
--output rtmp://localhost:1935/live/c64 --input --ws-port 9001
|
|
91
|
+
# WebRTC + simultaneous RTMP (both active at once)
|
|
92
|
+
c64-headless --wasm public/c64.wasm --game game.crt --webrtc \\
|
|
93
|
+
--record --output rtmp://localhost:1935/live/c64 --input --ws-port 9001
|
|
75
94
|
`.trim();
|
|
76
95
|
console.log(help);
|
|
77
96
|
process.exit(0);
|
|
@@ -97,3 +116,7 @@ if (!res.ok) {
|
|
|
97
116
|
}
|
|
98
117
|
process.exit(1);
|
|
99
118
|
}
|
|
119
|
+
|
|
120
|
+
// Force exit: native addons (@roamhq/wrtc) keep the event loop alive
|
|
121
|
+
// even after all work is done. This is safe — all cleanup already ran above.
|
|
122
|
+
process.exit(0);
|
package/bin/serve.mjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) 2026 hayesmaker
|
|
4
|
+
// See LICENSE in the project root for full license information.
|
|
2
5
|
/**
|
|
3
6
|
* c64-ready — browser player CLI
|
|
4
7
|
*
|
|
@@ -117,9 +120,12 @@ const server = createServer((req, res) => {
|
|
|
117
120
|
}
|
|
118
121
|
|
|
119
122
|
// All other requests are resolved against dist/ directly.
|
|
120
|
-
//
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
+
// Vite bakes base='/c64-ready/' into all asset URLs, so strip that prefix
|
|
124
|
+
// before resolving so the path maps into dist/ correctly:
|
|
125
|
+
// /c64-ready/assets/index-xxx.js → dist/assets/index-xxx.js
|
|
126
|
+
// /c64.wasm → dist/c64.wasm
|
|
127
|
+
const stripped = urlPath.startsWith('/c64-ready/') ? urlPath.slice('/c64-ready/'.length) : urlPath;
|
|
128
|
+
const relative = stripped.startsWith('/') ? stripped.slice(1) : stripped;
|
|
123
129
|
const filePath = resolve(DIST_DIR, normalize(relative));
|
|
124
130
|
|
|
125
131
|
// Path traversal guard
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"retro"
|
|
11
11
|
],
|
|
12
12
|
"license": "MIT",
|
|
13
|
-
"version": "0.
|
|
13
|
+
"version": "0.10.0",
|
|
14
14
|
"type": "module",
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=24.14"
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
},
|
|
33
33
|
"bin": {
|
|
34
34
|
"c64-ready": "bin/serve.mjs",
|
|
35
|
-
"c64-headless": "bin/headless.mjs"
|
|
35
|
+
"c64-headless": "bin/headless.mjs",
|
|
36
|
+
"c64-admin": "bin/admin.mjs"
|
|
36
37
|
},
|
|
37
38
|
"exports": {
|
|
38
39
|
".": {
|
|
@@ -54,6 +55,7 @@
|
|
|
54
55
|
"./wasm": "./public/c64.wasm"
|
|
55
56
|
},
|
|
56
57
|
"files": [
|
|
58
|
+
"LICENSE",
|
|
57
59
|
"bin/",
|
|
58
60
|
"src/",
|
|
59
61
|
"dist/",
|
|
@@ -70,6 +72,7 @@
|
|
|
70
72
|
"@types/gif.js": "^0.2.5",
|
|
71
73
|
"@types/marked": "^5.0.2",
|
|
72
74
|
"@types/node": "^25.5.0",
|
|
75
|
+
"@types/ws": "^8.18.1",
|
|
73
76
|
"eslint": "^10.1.0",
|
|
74
77
|
"eslint-config-prettier": "^10.1.8",
|
|
75
78
|
"eslint-plugin-prettier": "^5.5.5",
|
|
@@ -83,6 +86,7 @@
|
|
|
83
86
|
"vitest": "^3.2.4"
|
|
84
87
|
},
|
|
85
88
|
"dependencies": {
|
|
89
|
+
"@roamhq/wrtc": "^0.10.0",
|
|
86
90
|
"dompurify": "^3.0.5",
|
|
87
91
|
"marked": "^5.0.2",
|
|
88
92
|
"ws": "^8.20.0"
|
|
Binary file
|
|
Binary file
|