c64-ready 1.0.0 → 1.0.1
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/dist/assets/CHANGELOG-B12WeYEc.js +116 -0
- package/dist/assets/index-fUdEY2R7.js +610 -0
- package/dist/index.html +1 -1
- package/dist-ts/emulator/c64-emulator.d.ts +3 -0
- package/dist-ts/emulator/c64-emulator.d.ts.map +1 -1
- package/dist-ts/emulator/c64-emulator.js +36 -4
- package/dist-ts/emulator/c64-emulator.js.map +1 -1
- package/dist-ts/emulator/crt-info.d.ts +61 -0
- package/dist-ts/emulator/crt-info.d.ts.map +1 -0
- package/dist-ts/emulator/crt-info.js +190 -0
- package/dist-ts/emulator/crt-info.js.map +1 -0
- package/dist-ts/emulator/input.d.ts +96 -0
- package/dist-ts/emulator/input.d.ts.map +1 -1
- package/dist-ts/emulator/input.js +549 -4
- package/dist-ts/emulator/input.js.map +1 -1
- package/dist-ts/headless/c64-headless.d.ts +1 -0
- package/dist-ts/headless/c64-headless.d.ts.map +1 -1
- package/dist-ts/headless/c64-headless.js +5 -0
- package/dist-ts/headless/c64-headless.js.map +1 -1
- package/dist-ts/types/emulator.d.ts +2 -1
- package/dist-ts/types/emulator.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/emulator/c64-emulator.ts +34 -2
- package/src/emulator/crt-info.ts +35 -23
- package/src/headless/c64-headless.ts +5 -0
- package/src/headless/headless-cli.mjs +406 -229
- package/src/headless/input-server.mjs +397 -200
- package/src/headless/webrtc-server.mjs +168 -67
- package/src/main.ts +18 -4
- package/src/player/c64-player.ts +102 -36
- package/src/player/styles/ui-controller.css +90 -21
- package/src/player/ui-controller.ts +58 -11
- package/dist/assets/CHANGELOG-CPlXKLCV.js +0 -279
- package/dist/assets/index-Ckbi7gQo.js +0 -535
|
@@ -56,7 +56,9 @@ function buildIceServers({
|
|
|
56
56
|
credential: turnPassword,
|
|
57
57
|
});
|
|
58
58
|
} else if (turnUrls.length > 0 && verbose) {
|
|
59
|
-
console.error(
|
|
59
|
+
console.error(
|
|
60
|
+
'[webrtc] ICE_TURN_URLS provided without ICE_TURN_USERNAME/ICE_TURN_PASSWORD; skipping TURN',
|
|
61
|
+
);
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
if (iceServers.length === 0) {
|
|
@@ -67,7 +69,9 @@ function buildIceServers({
|
|
|
67
69
|
const stunCount = stunUrls.length;
|
|
68
70
|
const turnCount = turnUrls.length;
|
|
69
71
|
const turnEnabled = turnUrls.length > 0 && turnUsername && turnPassword;
|
|
70
|
-
console.error(
|
|
72
|
+
console.error(
|
|
73
|
+
`[webrtc] ICE config stunUrls=${stunCount} turnUrls=${turnCount} turnEnabled=${turnEnabled ? 'yes' : 'no'}`,
|
|
74
|
+
);
|
|
71
75
|
}
|
|
72
76
|
|
|
73
77
|
return iceServers;
|
|
@@ -124,7 +128,9 @@ export function createWebRTCServer({
|
|
|
124
128
|
function logEv(tag, fields = {}) {
|
|
125
129
|
if (!logEvents) return;
|
|
126
130
|
const ts = new Date().toISOString();
|
|
127
|
-
const pairs = Object.entries(fields)
|
|
131
|
+
const pairs = Object.entries(fields)
|
|
132
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
133
|
+
.join(' ');
|
|
128
134
|
console.error(`[event] ${ts} ${tag}${pairs ? ' ' + pairs : ''}`);
|
|
129
135
|
}
|
|
130
136
|
// Track all active peer connections so forceKeyframe() can reach them all.
|
|
@@ -145,12 +151,12 @@ export function createWebRTCServer({
|
|
|
145
151
|
};
|
|
146
152
|
let lastPressureLogAt = 0;
|
|
147
153
|
let lastPressureSignature = '';
|
|
148
|
-
const minBitrateKbpsSafe =
|
|
149
|
-
? Math.round(minBitrateKbps)
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
+
const minBitrateKbpsSafe =
|
|
155
|
+
Number.isFinite(minBitrateKbps) && minBitrateKbps > 0 ? Math.round(minBitrateKbps) : 200;
|
|
156
|
+
const maxBitrateKbpsSafe =
|
|
157
|
+
Number.isFinite(maxBitrateKbps) && maxBitrateKbps > 0
|
|
158
|
+
? Math.max(minBitrateKbpsSafe, Math.round(maxBitrateKbps))
|
|
159
|
+
: Math.max(minBitrateKbpsSafe, 600);
|
|
154
160
|
|
|
155
161
|
// Total capacity = 2 player slots + maxSpectators.
|
|
156
162
|
// We track all in-flight WS connections (including those not yet ICE-connected)
|
|
@@ -167,7 +173,10 @@ export function createWebRTCServer({
|
|
|
167
173
|
...extra,
|
|
168
174
|
};
|
|
169
175
|
logEv(tag, snapshot);
|
|
170
|
-
if (verbose)
|
|
176
|
+
if (verbose)
|
|
177
|
+
console.error(
|
|
178
|
+
`[webrtc-load] ${tag} active=${snapshot.active} pending=${snapshot.pending} total=${snapshot.total}/${snapshot.max}`,
|
|
179
|
+
);
|
|
171
180
|
}
|
|
172
181
|
|
|
173
182
|
async function logRouteSnapshot(pc, remoteAddr) {
|
|
@@ -177,14 +186,21 @@ export function createWebRTCServer({
|
|
|
177
186
|
const localById = new Map();
|
|
178
187
|
const remoteById = new Map();
|
|
179
188
|
for (const stat of report.values()) {
|
|
180
|
-
if (
|
|
189
|
+
if (
|
|
190
|
+
stat.type === 'candidate-pair' &&
|
|
191
|
+
stat.nominated &&
|
|
192
|
+
(stat.state === 'succeeded' || stat.selected)
|
|
193
|
+
)
|
|
194
|
+
selected = stat;
|
|
181
195
|
if (stat.type === 'local-candidate') localById.set(stat.id, stat);
|
|
182
196
|
if (stat.type === 'remote-candidate') remoteById.set(stat.id, stat);
|
|
183
197
|
}
|
|
184
198
|
if (!selected) return;
|
|
185
199
|
const local = localById.get(selected.localCandidateId);
|
|
186
200
|
const remote = remoteById.get(selected.remoteCandidateId);
|
|
187
|
-
const rttMs = Number.isFinite(selected.currentRoundTripTime)
|
|
201
|
+
const rttMs = Number.isFinite(selected.currentRoundTripTime)
|
|
202
|
+
? Math.round(selected.currentRoundTripTime * 1000)
|
|
203
|
+
: null;
|
|
188
204
|
logEv('webrtc-route', {
|
|
189
205
|
addr: remoteAddr,
|
|
190
206
|
protocol: selected.protocol ?? '-',
|
|
@@ -194,7 +210,9 @@ export function createWebRTCServer({
|
|
|
194
210
|
rttMs: rttMs ?? '-',
|
|
195
211
|
});
|
|
196
212
|
if (verbose) {
|
|
197
|
-
console.error(
|
|
213
|
+
console.error(
|
|
214
|
+
`[webrtc-route] addr=${remoteAddr} protocol=${selected.protocol ?? '-'} local=${local?.candidateType ?? '-'} remote=${remote?.candidateType ?? '-'} net=${local?.networkType ?? '-'} rtt=${rttMs ?? '-'}ms`,
|
|
215
|
+
);
|
|
198
216
|
}
|
|
199
217
|
} catch (_) {
|
|
200
218
|
// Best-effort diagnostics only
|
|
@@ -221,7 +239,11 @@ export function createWebRTCServer({
|
|
|
221
239
|
let selected = null;
|
|
222
240
|
let outboundVideo = null;
|
|
223
241
|
for (const stat of report.values()) {
|
|
224
|
-
if (
|
|
242
|
+
if (
|
|
243
|
+
stat.type === 'candidate-pair' &&
|
|
244
|
+
stat.nominated &&
|
|
245
|
+
(stat.state === 'succeeded' || stat.selected)
|
|
246
|
+
) {
|
|
225
247
|
selected = stat;
|
|
226
248
|
}
|
|
227
249
|
if (stat.type === 'outbound-rtp' && stat.kind === 'video' && !stat.isRemote) {
|
|
@@ -241,33 +263,65 @@ export function createWebRTCServer({
|
|
|
241
263
|
const current = {
|
|
242
264
|
timestampMs: Number.isFinite(outboundVideo.timestamp) ? outboundVideo.timestamp : nowWall,
|
|
243
265
|
framesSent: Number.isFinite(outboundVideo.framesSent) ? outboundVideo.framesSent : null,
|
|
244
|
-
framesEncoded: Number.isFinite(outboundVideo.framesEncoded)
|
|
266
|
+
framesEncoded: Number.isFinite(outboundVideo.framesEncoded)
|
|
267
|
+
? outboundVideo.framesEncoded
|
|
268
|
+
: null,
|
|
245
269
|
bytesSent: Number.isFinite(outboundVideo.bytesSent) ? outboundVideo.bytesSent : null,
|
|
246
|
-
packetsSent: Number.isFinite(outboundVideo.packetsSent)
|
|
247
|
-
|
|
248
|
-
|
|
270
|
+
packetsSent: Number.isFinite(outboundVideo.packetsSent)
|
|
271
|
+
? outboundVideo.packetsSent
|
|
272
|
+
: null,
|
|
273
|
+
totalPacketSendDelay: Number.isFinite(outboundVideo.totalPacketSendDelay)
|
|
274
|
+
? outboundVideo.totalPacketSendDelay
|
|
275
|
+
: null,
|
|
276
|
+
totalEncodeTime: Number.isFinite(outboundVideo.totalEncodeTime)
|
|
277
|
+
? outboundVideo.totalEncodeTime
|
|
278
|
+
: null,
|
|
249
279
|
};
|
|
250
280
|
|
|
251
281
|
const prev = peerStatsPrev.get(pc);
|
|
252
282
|
peerStatsPrev.set(pc, current);
|
|
253
283
|
if (!prev) continue;
|
|
254
284
|
|
|
255
|
-
if (
|
|
285
|
+
if (
|
|
286
|
+
current.framesSent != null &&
|
|
287
|
+
prev.framesSent != null &&
|
|
288
|
+
current.framesSent >= prev.framesSent
|
|
289
|
+
) {
|
|
256
290
|
deltaFramesSent += current.framesSent - prev.framesSent;
|
|
257
291
|
}
|
|
258
|
-
if (
|
|
292
|
+
if (
|
|
293
|
+
current.framesEncoded != null &&
|
|
294
|
+
prev.framesEncoded != null &&
|
|
295
|
+
current.framesEncoded >= prev.framesEncoded
|
|
296
|
+
) {
|
|
259
297
|
deltaFramesEncoded += current.framesEncoded - prev.framesEncoded;
|
|
260
298
|
}
|
|
261
|
-
if (
|
|
299
|
+
if (
|
|
300
|
+
current.bytesSent != null &&
|
|
301
|
+
prev.bytesSent != null &&
|
|
302
|
+
current.bytesSent >= prev.bytesSent
|
|
303
|
+
) {
|
|
262
304
|
deltaBytesSent += current.bytesSent - prev.bytesSent;
|
|
263
305
|
}
|
|
264
|
-
if (
|
|
306
|
+
if (
|
|
307
|
+
current.packetsSent != null &&
|
|
308
|
+
prev.packetsSent != null &&
|
|
309
|
+
current.packetsSent >= prev.packetsSent
|
|
310
|
+
) {
|
|
265
311
|
deltaPacketsSent += current.packetsSent - prev.packetsSent;
|
|
266
312
|
}
|
|
267
|
-
if (
|
|
313
|
+
if (
|
|
314
|
+
current.totalPacketSendDelay != null &&
|
|
315
|
+
prev.totalPacketSendDelay != null &&
|
|
316
|
+
current.totalPacketSendDelay >= prev.totalPacketSendDelay
|
|
317
|
+
) {
|
|
268
318
|
deltaPacketSendDelay += current.totalPacketSendDelay - prev.totalPacketSendDelay;
|
|
269
319
|
}
|
|
270
|
-
if (
|
|
320
|
+
if (
|
|
321
|
+
current.totalEncodeTime != null &&
|
|
322
|
+
prev.totalEncodeTime != null &&
|
|
323
|
+
current.totalEncodeTime >= prev.totalEncodeTime
|
|
324
|
+
) {
|
|
271
325
|
deltaEncodeTime += current.totalEncodeTime - prev.totalEncodeTime;
|
|
272
326
|
}
|
|
273
327
|
} catch (_) {
|
|
@@ -278,9 +332,11 @@ export function createWebRTCServer({
|
|
|
278
332
|
const sampleIntervalS = 5;
|
|
279
333
|
senderTelemetry.sampledAt = nowWall;
|
|
280
334
|
senderTelemetry.peerCount = peerCount;
|
|
281
|
-
senderTelemetry.avgRttMs = rttCount > 0 ?
|
|
282
|
-
senderTelemetry.sendDelayMsPerPacket =
|
|
283
|
-
|
|
335
|
+
senderTelemetry.avgRttMs = rttCount > 0 ? rttSum / rttCount : null;
|
|
336
|
+
senderTelemetry.sendDelayMsPerPacket =
|
|
337
|
+
deltaPacketsSent > 0 ? (deltaPacketSendDelay / deltaPacketsSent) * 1000 : null;
|
|
338
|
+
senderTelemetry.encodeMsPerFrame =
|
|
339
|
+
deltaFramesEncoded > 0 ? (deltaEncodeTime / deltaFramesEncoded) * 1000 : null;
|
|
284
340
|
senderTelemetry.framesSentPerSec = deltaFramesSent / sampleIntervalS;
|
|
285
341
|
senderTelemetry.framesEncodedPerSec = deltaFramesEncoded / sampleIntervalS;
|
|
286
342
|
senderTelemetry.bytesSentPerSec = deltaBytesSent / sampleIntervalS;
|
|
@@ -305,11 +361,12 @@ export function createWebRTCServer({
|
|
|
305
361
|
const bitrateKbps = Number.isFinite(senderTelemetry.bytesSentPerSec)
|
|
306
362
|
? ((senderTelemetry.bytesSentPerSec * 8) / 1000).toFixed(0)
|
|
307
363
|
: '-';
|
|
308
|
-
const qualitySummary =
|
|
309
|
-
.
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
364
|
+
const qualitySummary =
|
|
365
|
+
Object.entries(qualityCounts)
|
|
366
|
+
.filter(([, count]) => Number.isFinite(count) && count > 0)
|
|
367
|
+
.sort((a, b) => b[1] - a[1])
|
|
368
|
+
.map(([reason, count]) => `${reason}:${count}`)
|
|
369
|
+
.join('|') || 'none:0';
|
|
313
370
|
|
|
314
371
|
logEv('webrtc-sender-telemetry', {
|
|
315
372
|
peers: peerCount,
|
|
@@ -323,13 +380,22 @@ export function createWebRTCServer({
|
|
|
323
380
|
});
|
|
324
381
|
|
|
325
382
|
const pressureReasons = [];
|
|
326
|
-
if (
|
|
383
|
+
if (
|
|
384
|
+
Number.isFinite(senderTelemetry.framesSentPerSec) &&
|
|
385
|
+
senderTelemetry.framesSentPerSec < 44
|
|
386
|
+
) {
|
|
327
387
|
pressureReasons.push('low-fps-out');
|
|
328
388
|
}
|
|
329
|
-
if (
|
|
389
|
+
if (
|
|
390
|
+
Number.isFinite(senderTelemetry.encodeMsPerFrame) &&
|
|
391
|
+
senderTelemetry.encodeMsPerFrame > 12
|
|
392
|
+
) {
|
|
330
393
|
pressureReasons.push('slow-encode');
|
|
331
394
|
}
|
|
332
|
-
if (
|
|
395
|
+
if (
|
|
396
|
+
Number.isFinite(senderTelemetry.sendDelayMsPerPacket) &&
|
|
397
|
+
senderTelemetry.sendDelayMsPerPacket > 4
|
|
398
|
+
) {
|
|
333
399
|
pressureReasons.push('packet-send-delay');
|
|
334
400
|
}
|
|
335
401
|
if ((qualityCounts.cpu ?? 0) > 0) pressureReasons.push('quality-cpu');
|
|
@@ -338,7 +404,8 @@ export function createWebRTCServer({
|
|
|
338
404
|
if (pressureReasons.length > 0) {
|
|
339
405
|
const signature = pressureReasons.join('|');
|
|
340
406
|
const now = Date.now();
|
|
341
|
-
const shouldLogPressure =
|
|
407
|
+
const shouldLogPressure =
|
|
408
|
+
signature !== lastPressureSignature || now - lastPressureLogAt >= 30_000;
|
|
342
409
|
if (shouldLogPressure) {
|
|
343
410
|
lastPressureSignature = signature;
|
|
344
411
|
lastPressureLogAt = now;
|
|
@@ -382,7 +449,9 @@ export function createWebRTCServer({
|
|
|
382
449
|
newAddr: controller.remoteAddr ?? '-',
|
|
383
450
|
source,
|
|
384
451
|
});
|
|
385
|
-
try {
|
|
452
|
+
try {
|
|
453
|
+
previous.closePeer?.('session-replaced');
|
|
454
|
+
} catch (_) {}
|
|
386
455
|
}
|
|
387
456
|
|
|
388
457
|
peerBySession.set(sessionKey, controller);
|
|
@@ -436,14 +505,15 @@ export function createWebRTCServer({
|
|
|
436
505
|
|
|
437
506
|
wss.on('connection', (ws, req) => {
|
|
438
507
|
ws._sigAlive = true; // initialise alive flag
|
|
439
|
-
ws.on('pong', () => {
|
|
508
|
+
ws.on('pong', () => {
|
|
509
|
+
ws._sigAlive = true;
|
|
510
|
+
});
|
|
440
511
|
const remoteAddr = req.socket.remoteAddress;
|
|
441
512
|
let initialSessionId = null;
|
|
442
513
|
try {
|
|
443
514
|
const reqUrl = new URL(req.url || '/', 'http://localhost');
|
|
444
|
-
initialSessionId =
|
|
445
|
-
|| reqUrl.searchParams.get('sessionId')
|
|
446
|
-
|| null;
|
|
515
|
+
initialSessionId =
|
|
516
|
+
reqUrl.searchParams.get('sid') || reqUrl.searchParams.get('sessionId') || null;
|
|
447
517
|
} catch (_) {}
|
|
448
518
|
|
|
449
519
|
// ── Capacity gate ─────────────────────────────────────────────────────────
|
|
@@ -451,15 +521,23 @@ export function createWebRTCServer({
|
|
|
451
521
|
// Players take 2 of the MAX_CONNECTIONS slots; remaining slots are spectators.
|
|
452
522
|
const currentTotal = activePeers.size + pendingPeers;
|
|
453
523
|
if (currentTotal >= MAX_CONNECTIONS) {
|
|
454
|
-
console.error(
|
|
455
|
-
|
|
524
|
+
console.error(
|
|
525
|
+
`[webrtc] capacity full (${currentTotal}/${MAX_CONNECTIONS}) — rejecting ${remoteAddr}`,
|
|
526
|
+
);
|
|
527
|
+
logEv('webrtc-capacity-full', {
|
|
528
|
+
addr: remoteAddr,
|
|
529
|
+
current: currentTotal,
|
|
530
|
+
max: MAX_CONNECTIONS,
|
|
531
|
+
});
|
|
456
532
|
try {
|
|
457
|
-
ws.send(
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
533
|
+
ws.send(
|
|
534
|
+
JSON.stringify({
|
|
535
|
+
type: 'capacity-full',
|
|
536
|
+
current: currentTotal,
|
|
537
|
+
max: MAX_CONNECTIONS,
|
|
538
|
+
maxSpectators,
|
|
539
|
+
}),
|
|
540
|
+
);
|
|
463
541
|
} catch (_) {}
|
|
464
542
|
ws.close();
|
|
465
543
|
return;
|
|
@@ -490,7 +568,10 @@ export function createWebRTCServer({
|
|
|
490
568
|
let disconnectTimer = null;
|
|
491
569
|
|
|
492
570
|
function clearDisconnectTimer() {
|
|
493
|
-
if (disconnectTimer) {
|
|
571
|
+
if (disconnectTimer) {
|
|
572
|
+
clearTimeout(disconnectTimer);
|
|
573
|
+
disconnectTimer = null;
|
|
574
|
+
}
|
|
494
575
|
}
|
|
495
576
|
|
|
496
577
|
// Track whether this peer has ever reached ICE connected (to manage pendingPeers correctly).
|
|
@@ -506,7 +587,7 @@ export function createWebRTCServer({
|
|
|
506
587
|
const errName = err?.name ?? 'Error';
|
|
507
588
|
const errMsg = err?.message ?? String(err);
|
|
508
589
|
console.error(
|
|
509
|
-
`[webrtc] addIceCandidate failed (${source}) addr=${remoteAddr} hasRemoteDescription=${hasRemoteDescription} signalingState=${signalingState} err=${errName}: ${errMsg}
|
|
590
|
+
`[webrtc] addIceCandidate failed (${source}) addr=${remoteAddr} hasRemoteDescription=${hasRemoteDescription} signalingState=${signalingState} err=${errName}: ${errMsg}`,
|
|
510
591
|
);
|
|
511
592
|
logEv('webrtc-ice-candidate-error', {
|
|
512
593
|
addr: remoteAddr,
|
|
@@ -536,14 +617,18 @@ export function createWebRTCServer({
|
|
|
536
617
|
}
|
|
537
618
|
peerControllers.delete(controller);
|
|
538
619
|
// Decrement pendingPeers only if this peer never made it to ICE connected.
|
|
539
|
-
if (!wasActive && !everConnected) {
|
|
620
|
+
if (!wasActive && !everConnected) {
|
|
621
|
+
if (pendingPeers > 0) pendingPeers--;
|
|
622
|
+
}
|
|
540
623
|
console.error(`[webrtc] closing peer (${remoteAddr}): ${reason}`);
|
|
541
624
|
logEv('webrtc-peer-closed', { addr: remoteAddr, reason });
|
|
542
625
|
logLoadSnapshot('webrtc-load-change', { reason: `peer-closed:${reason}` });
|
|
543
626
|
// Tell the browser the stream died so it can reconnect immediately
|
|
544
627
|
// rather than sitting on a frozen frame.
|
|
545
628
|
if (ws.readyState === ws.OPEN) {
|
|
546
|
-
try {
|
|
629
|
+
try {
|
|
630
|
+
ws.send(JSON.stringify({ type: 'peer-closed', reason }));
|
|
631
|
+
} catch (_) {}
|
|
547
632
|
}
|
|
548
633
|
pc.close();
|
|
549
634
|
}
|
|
@@ -612,7 +697,11 @@ export function createWebRTCServer({
|
|
|
612
697
|
|
|
613
698
|
try {
|
|
614
699
|
if (msg.type === 'offer') {
|
|
615
|
-
bindControllerSession(
|
|
700
|
+
bindControllerSession(
|
|
701
|
+
controller,
|
|
702
|
+
msg.sessionId ?? msg.sid ?? msg.clientSessionId ?? null,
|
|
703
|
+
'offer',
|
|
704
|
+
);
|
|
616
705
|
await pc.setRemoteDescription(msg);
|
|
617
706
|
await flushRemoteCandidates('post-offer');
|
|
618
707
|
|
|
@@ -633,15 +722,12 @@ export function createWebRTCServer({
|
|
|
633
722
|
let sdp = answer.sdp;
|
|
634
723
|
if (sdp) {
|
|
635
724
|
// Find VP8 payload type in the offer and append fmtp constraints
|
|
636
|
-
sdp = sdp.replace(
|
|
637
|
-
|
|
638
|
-
(
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
return line + fmtp;
|
|
643
|
-
}
|
|
644
|
-
);
|
|
725
|
+
sdp = sdp.replace(/(a=rtpmap:(\d+) VP8\/\d+\r?\n)/, (match, line, pt) => {
|
|
726
|
+
const minKbps = Math.max(50, minBitrateKbpsSafe);
|
|
727
|
+
const maxKbps = Math.max(minKbps, maxBitrateKbpsSafe);
|
|
728
|
+
const fmtp = `a=fmtp:${pt} x-google-min-bitrate=${minKbps};x-google-max-bitrate=${maxKbps}\r\n`;
|
|
729
|
+
return line + fmtp;
|
|
730
|
+
});
|
|
645
731
|
answer.sdp = sdp;
|
|
646
732
|
}
|
|
647
733
|
|
|
@@ -651,12 +737,13 @@ export function createWebRTCServer({
|
|
|
651
737
|
ws.send(JSON.stringify(pc.localDescription));
|
|
652
738
|
}
|
|
653
739
|
if (verbose) console.error(`[webrtc] answered offer from ${remoteAddr}`);
|
|
654
|
-
|
|
655
740
|
} else if (msg.type === 'candidate' && msg.candidate) {
|
|
656
741
|
if (!pc.remoteDescription) {
|
|
657
742
|
pendingRemoteCandidates.push(msg.candidate);
|
|
658
743
|
if (verbose) {
|
|
659
|
-
console.error(
|
|
744
|
+
console.error(
|
|
745
|
+
`[webrtc] queued remote candidate (${pendingRemoteCandidates.length}) pending offer (${remoteAddr})`,
|
|
746
|
+
);
|
|
660
747
|
}
|
|
661
748
|
} else {
|
|
662
749
|
await addRemoteCandidate(msg.candidate, 'live');
|
|
@@ -779,7 +866,12 @@ export function createWebRTCServer({
|
|
|
779
866
|
}
|
|
780
867
|
|
|
781
868
|
// ─── Embedded browser-side player page ──────────────────────────────────────
|
|
782
|
-
function buildBrowserHtml(
|
|
869
|
+
function buildBrowserHtml(
|
|
870
|
+
inputPort,
|
|
871
|
+
minBitrateKbps = 200,
|
|
872
|
+
maxBitrateKbps = 600,
|
|
873
|
+
iceServers = [{ urls: 'stun:stun.l.google.com:19302' }],
|
|
874
|
+
) {
|
|
783
875
|
const minKbps = Math.max(50, Math.round(minBitrateKbps));
|
|
784
876
|
const maxKbps = Math.max(minKbps, Math.round(maxBitrateKbps));
|
|
785
877
|
const iceServersJson = JSON.stringify(iceServers).replace(/</g, '\\u003c');
|
|
@@ -888,6 +980,7 @@ function buildBrowserHtml(inputPort, minBitrateKbps = 200, maxBitrateKbps = 600,
|
|
|
888
980
|
<button id="load-btn" title="Load a .crt cartridge file">📂 load .crt</button>
|
|
889
981
|
<button id="detach-btn" title="Eject cartridge → BASIC prompt" disabled>⏏ detach</button>
|
|
890
982
|
<button id="reset-btn" title="Hard reset (BASIC prompt)" disabled>↺ reset</button>
|
|
983
|
+
<button id="reboot-btn" title="Re-instantiate emulator with no game loaded">⟲ reboot</button>
|
|
891
984
|
<span class="sep">|</span>
|
|
892
985
|
<button id="sync-btn" title="Flush video to live edge — use if display feels laggy">⟳ sync</button>
|
|
893
986
|
<span class="sep">|</span>
|
|
@@ -911,6 +1004,7 @@ function buildBrowserHtml(inputPort, minBitrateKbps = 200, maxBitrateKbps = 600,
|
|
|
911
1004
|
const loadBtn = document.getElementById('load-btn');
|
|
912
1005
|
const detachBtn = document.getElementById('detach-btn');
|
|
913
1006
|
const resetBtn = document.getElementById('reset-btn');
|
|
1007
|
+
const rebootBtn = document.getElementById('reboot-btn');
|
|
914
1008
|
const syncBtn = document.getElementById('sync-btn');
|
|
915
1009
|
const modeBtn = document.getElementById('mode-btn');
|
|
916
1010
|
const fileInput = document.getElementById('file-input');
|
|
@@ -1240,12 +1334,18 @@ function buildBrowserHtml(inputPort, minBitrateKbps = 200, maxBitrateKbps = 600,
|
|
|
1240
1334
|
try {
|
|
1241
1335
|
const msg = JSON.parse(data);
|
|
1242
1336
|
// Cart lifecycle
|
|
1243
|
-
if (msg.type === 'cart-loaded' || msg.type === 'machine-reset' || msg.type === 'cart-detached') {
|
|
1337
|
+
if (msg.type === 'cart-loaded' || msg.type === 'machine-reset' || msg.type === 'cart-detached' || msg.type === 'machine-rebooted') {
|
|
1244
1338
|
blurAll();
|
|
1245
1339
|
const cartName = msg.filename ? msg.filename.replace(/\\.crt$/i,'').replace(/[-_]/g,' ') : '';
|
|
1246
1340
|
if (msg.type === 'cart-loaded') { setBadge(gameBadge, '🎮 ' + (cartName || 'game loaded'), 'ok'); setLoadStatus('loaded', 'ok'); detachBtn.disabled = false; resetBtn.disabled = false; }
|
|
1247
1341
|
if (msg.type === 'cart-detached') { setBadge(gameBadge, 'no game', 'dim'); setLoadStatus('', ''); detachBtn.disabled = true; }
|
|
1248
1342
|
if (msg.type === 'machine-reset') { setLoadStatus('reset', 'warn'); }
|
|
1343
|
+
if (msg.type === 'machine-rebooted') {
|
|
1344
|
+
setBadge(gameBadge, 'no game', 'dim');
|
|
1345
|
+
setLoadStatus('rebooted', 'warn');
|
|
1346
|
+
detachBtn.disabled = true;
|
|
1347
|
+
resetBtn.disabled = true;
|
|
1348
|
+
}
|
|
1249
1349
|
// Reconnect the RTCPeerConnection entirely — this is the only
|
|
1250
1350
|
// reliable way to clear the jitter buffer and decoder state that
|
|
1251
1351
|
// accumulates during the ~1600ms cart-load gap. Anything less
|
|
@@ -1328,6 +1428,7 @@ function buildBrowserHtml(inputPort, minBitrateKbps = 200, maxBitrateKbps = 600,
|
|
|
1328
1428
|
});
|
|
1329
1429
|
detachBtn.addEventListener('click', () => { sendInput({ type: 'detach-crt' }); setLoadStatus('detaching…', 'warn'); blurAll(); });
|
|
1330
1430
|
resetBtn.addEventListener('click', () => { sendInput({ type: 'hard-reset' }); setLoadStatus('resetting…', 'warn'); blurAll(); });
|
|
1431
|
+
rebootBtn.addEventListener('click', () => { sendInput({ type: 'reboot' }); setLoadStatus('rebooting…', 'warn'); blurAll(); });
|
|
1331
1432
|
syncBtn.addEventListener('click', () => {
|
|
1332
1433
|
const wasMuted = videoEl.muted;
|
|
1333
1434
|
connectWebRTC();
|
package/src/main.ts
CHANGED
|
@@ -45,7 +45,7 @@ player
|
|
|
45
45
|
.catch((err) => {
|
|
46
46
|
console.error(err);
|
|
47
47
|
renderer.setError('ERROR');
|
|
48
|
-
status.textContent = `Error: ${err}`;
|
|
48
|
+
status.textContent = `Error: ${normalizeErrorMessage(String(err))}`;
|
|
49
49
|
status.style.color = '#f44';
|
|
50
50
|
});
|
|
51
51
|
|
|
@@ -84,7 +84,7 @@ window.addEventListener('c64-load-file', async (e: Event) => {
|
|
|
84
84
|
} catch (err) {
|
|
85
85
|
console.error(err);
|
|
86
86
|
renderer.setError('LOAD ERROR');
|
|
87
|
-
status.textContent = `Load error: ${err}`;
|
|
87
|
+
status.textContent = `Load error: ${normalizeErrorMessage(String(err))}`;
|
|
88
88
|
status.style.color = '#f44';
|
|
89
89
|
}
|
|
90
90
|
});
|
|
@@ -104,7 +104,7 @@ window.addEventListener('c64-load-tool', async (e: Event) => {
|
|
|
104
104
|
} catch (err) {
|
|
105
105
|
console.error(err);
|
|
106
106
|
renderer.setError('LOAD ERROR');
|
|
107
|
-
status.textContent = `Tool load error: ${err}`;
|
|
107
|
+
status.textContent = `Tool load error: ${normalizeErrorMessage(String(err))}`;
|
|
108
108
|
status.style.color = '#f44';
|
|
109
109
|
}
|
|
110
110
|
});
|
|
@@ -114,7 +114,7 @@ window.addEventListener('c64-load-error', (e: Event) => {
|
|
|
114
114
|
const detail = (e as CustomEvent).detail as
|
|
115
115
|
| { error?: string; url?: string; file?: string; type?: string }
|
|
116
116
|
| undefined;
|
|
117
|
-
const msg = detail?.error ?? 'Unknown load error';
|
|
117
|
+
const msg = normalizeErrorMessage(detail?.error ?? 'Unknown load error');
|
|
118
118
|
console.error('C64 load error event:', detail);
|
|
119
119
|
renderer.setError('LOAD ERROR');
|
|
120
120
|
status.textContent = `Load error: ${msg}`;
|
|
@@ -130,3 +130,17 @@ window.addEventListener('c64-load-info', (e: Event) => {
|
|
|
130
130
|
status.style.color = detail.mode === 'warning' ? '#f9c74f' : '#9ecbff';
|
|
131
131
|
console.info('C64 load info event:', detail);
|
|
132
132
|
});
|
|
133
|
+
|
|
134
|
+
window.addEventListener('c64-reboot', () => {
|
|
135
|
+
status.textContent = 'Emulator rebooted. Load a cartridge to continue.';
|
|
136
|
+
status.style.color = '#9ecbff';
|
|
137
|
+
renderer.hideLoader(0);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
function normalizeErrorMessage(msg: string): string {
|
|
141
|
+
let out = String(msg ?? '').trim();
|
|
142
|
+
while (/^(uncaught\s+)?error\s*:\s*/i.test(out)) {
|
|
143
|
+
out = out.replace(/^(uncaught\s+)?error\s*:\s*/i, '').trim();
|
|
144
|
+
}
|
|
145
|
+
return out || 'Unknown load error';
|
|
146
|
+
}
|