Skip to content

Commit 4d2988f

Browse files
Update Syntax
1 parent 393437f commit 4d2988f

2 files changed

Lines changed: 87 additions & 44 deletions

File tree

data/emulator.debug.js

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6927,9 +6927,14 @@ class NetplayEngine {
69276927
this.config.callbacks.onSocketConnect(socketId);
69286928
}
69296929
// On reconnect after disconnect: trigger full session recreate immediately
6930-
if (this._socketWasDisconnected && this.emulator?.netplay?.currentRoomId) {
6930+
if (
6931+
this._socketWasDisconnected &&
6932+
this.emulator?.netplay?.currentRoomId
6933+
) {
69316934
this._socketWasDisconnected = false;
6932-
console.log("[Netplay] Socket reconnected, triggering session recreate");
6935+
console.log(
6936+
"[Netplay] Socket reconnected, triggering session recreate",
6937+
);
69336938
this.recreateSfuSession().catch((e) =>
69346939
console.warn("[Netplay] Reconnect recreate failed:", e),
69356940
);
@@ -8331,7 +8336,9 @@ class NetplayEngine {
83318336
if (!this.sfuTransport?.useSFU) return;
83328337
if (this._recreateInProgress) return;
83338338
if (!this.socketTransport?.isConnected()) {
8334-
console.warn("[Netplay] recreateSfuSession: socket disconnected, skipping");
8339+
console.warn(
8340+
"[Netplay] recreateSfuSession: socket disconnected, skipping",
8341+
);
83358342
return;
83368343
}
83378344
this._recreateInProgress = true;
@@ -8353,14 +8360,22 @@ class NetplayEngine {
83538360
netplayUsername: this.sessionState?.localNetplayUsername ?? "Player",
83548361
preferredSlot: this.sessionState?.getLocalPlayerSlot?.() ?? 0,
83558362
romHash: this.emulator.config?.romHash ?? null,
8356-
romName: this.emulator.config?.romName ?? this.emulator.config?.romFilename ?? null,
8363+
romName:
8364+
this.emulator.config?.romName ??
8365+
this.emulator.config?.romFilename ??
8366+
null,
83578367
romFilename: this.emulator.config?.romFilename ?? null,
8358-
core: this.emulator.config?.core ?? this.emulator.config?.system ?? null,
8368+
core:
8369+
this.emulator.config?.core ?? this.emulator.config?.system ?? null,
83598370
system: this.emulator.config?.system ?? null,
83608371
platform: this.emulator.config?.platform ?? null,
8361-
coreId: this.emulator.config?.coreId ?? this.emulator.config?.system ?? null,
8372+
coreId:
8373+
this.emulator.config?.coreId ?? this.emulator.config?.system ?? null,
83628374
coreVersion: this.emulator.config?.coreVersion ?? null,
8363-
systemType: this.emulator.config?.systemType ?? this.emulator.config?.system ?? null,
8375+
systemType:
8376+
this.emulator.config?.systemType ??
8377+
this.emulator.config?.system ??
8378+
null,
83648379
};
83658380
await this.joinRoom(null, roomName, maxPlayers, password, playerInfo);
83668381
console.log("[Netplay] Rejoin confirmed");
@@ -8384,18 +8399,23 @@ class NetplayEngine {
83848399
await doRecreate();
83858400
console.log("[Netplay] SFU session recreated successfully");
83868401
} catch (error) {
8387-
const errMsg = typeof error === "string" ? error : error?.message ?? "";
8402+
const errMsg = typeof error === "string" ? error : (error?.message ?? "");
83888403
const isNoRoom =
83898404
errMsg.includes("no room") || errMsg.includes("transport not found");
83908405
if (isNoRoom && this.roomManager) {
8391-
console.warn("[Netplay] Transport create failed (no room), retrying rejoin and recreate");
8406+
console.warn(
8407+
"[Netplay] Transport create failed (no room), retrying rejoin and recreate",
8408+
);
83928409
try {
83938410
await doRejoin();
83948411
await new Promise((r) => setTimeout(r, 300));
83958412
await doRecreate();
83968413
console.log("[Netplay] SFU session recreated successfully (retry)");
83978414
} catch (retryError) {
8398-
console.error("[Netplay] SFU session recreate retry failed:", retryError);
8415+
console.error(
8416+
"[Netplay] SFU session recreate retry failed:",
8417+
retryError,
8418+
);
83998419
}
84008420
} else {
84018421
console.error("[Netplay] SFU session recreate failed:", error);
@@ -12352,10 +12372,7 @@ class NetplayEngine {
1235212372
consumer.rtpReceiver.jitterBufferTarget = 50;
1235312373
console.log("[Netplay] Set video consumer jitterBufferTarget=50ms");
1235412374
} catch (e) {
12355-
console.log(
12356-
"[Netplay] Could not set jitterBufferTarget:",
12357-
e?.message,
12358-
);
12375+
console.log("[Netplay] Could not set jitterBufferTarget:", e?.message);
1235912376
}
1236012377
}
1236112378
}
@@ -12478,8 +12495,9 @@ class NetplayEngine {
1247812495
`[Netplay] Direct emulator canvas captureStream (${fps === 0 ? "natural" : fps + "fps"})`,
1247912496
);
1248012497
return (
12481-
this._netplayWrapTrackWithFormatConversion(directTrack) ||
12482-
directTrack
12498+
this._netplayWrapTrackWithFormatConversion(
12499+
directTrack,
12500+
) || directTrack
1248312501
);
1248412502
}
1248512503
} catch (e) {
@@ -12554,10 +12572,7 @@ class NetplayEngine {
1255412572
`[Netplay] Found video element, attempting ${resLabel} capture...`,
1255512573
);
1255612574
try {
12557-
let videoTrack = this._netplayCaptureViaOffscreen(
12558-
video,
12559-
targetFps,
12560-
);
12575+
let videoTrack = this._netplayCaptureViaOffscreen(video, targetFps);
1256112576
if (!videoTrack && isMobile) {
1256212577
videoTrack = this._netplayCaptureViaOffscreen(video, 60);
1256312578
}
@@ -12636,10 +12651,11 @@ class NetplayEngine {
1263612651
}
1263712652
if (videoTrack) {
1263812653
const res = this._netplayGetStreamResolution();
12639-
console.log(
12640-
`[Netplay] Canvas via offscreen (${res.label}):`,
12641-
{ width: res.width, height: res.height, frameRate: targetFps },
12642-
);
12654+
console.log(`[Netplay] Canvas via offscreen (${res.label}):`, {
12655+
width: res.width,
12656+
height: res.height,
12657+
frameRate: targetFps,
12658+
});
1264312659
return (
1264412660
this._netplayWrapTrackWithFormatConversion(videoTrack) ||
1264512661
videoTrack

data/src/emulator.js

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ class EmulatorJS {
427427
// Resolution (host stream source): 1080p | 720p | 480p | 360p (default 480p, optimized for latency)
428428
const normalizeResolution = (v) => {
429429
const s = (typeof v === "string" ? v.trim() : "").toLowerCase();
430-
if (s === "1080p" || s === "720p" || s === "480p" || s === "360p") return s;
430+
if (s === "1080p" || s === "720p" || s === "480p" || s === "360p")
431+
return s;
431432
return "480p";
432433
};
433434
const storedResolution = this.preGetSetting("netplayStreamResolution");
@@ -440,7 +441,9 @@ class EmulatorJS {
440441
? this.config.netplayStreamResolution
441442
: envResolution;
442443
this.netplayStreamResolution = normalizeResolution(
443-
typeof storedResolution === "string" ? storedResolution : configResolution,
444+
typeof storedResolution === "string"
445+
? storedResolution
446+
: configResolution,
444447
);
445448
window.EJS_NETPLAY_STREAM_RESOLUTION = this.netplayStreamResolution;
446449

@@ -484,7 +487,9 @@ class EmulatorJS {
484487
? this.config.netplayHostScalabilityMode
485488
: envHostScalability;
486489
this.netplayHostScalabilityMode = normalizeHostScalability(
487-
typeof storedHostScalability === "string" ? storedHostScalability : configHostScalability,
490+
typeof storedHostScalability === "string"
491+
? storedHostScalability
492+
: configHostScalability,
488493
);
489494
window.EJS_NETPLAY_HOST_SCALABILITY_MODE = this.netplayHostScalabilityMode;
490495

@@ -1773,7 +1778,10 @@ class EmulatorJS {
17731778
const originalAlcCreateContext = this.Module.AL.alcCreateContext;
17741779
if (originalAlcCreateContext) {
17751780
this.Module.AL.alcCreateContext = (...args) => {
1776-
const ctx = originalAlcCreateContext.apply(this.Module.AL, args);
1781+
const ctx = originalAlcCreateContext.apply(
1782+
this.Module.AL,
1783+
args,
1784+
);
17771785
if (ctx && ctx.audioCtx) {
17781786
// Expose the master gain node for EmulatorJS audio capture
17791787
if (!ctx.masterGain) {
@@ -1783,7 +1791,9 @@ class EmulatorJS {
17831791
if (ctx.masterGain && ctx.audioCtx.destination) {
17841792
ctx.masterGain.connect(ctx.audioCtx.destination);
17851793
}
1786-
console.log("[EmulatorJS] Exposed masterGain node for audio capture");
1794+
console.log(
1795+
"[EmulatorJS] Exposed masterGain node for audio capture",
1796+
);
17871797
}
17881798
}
17891799
return ctx;
@@ -1829,7 +1839,7 @@ class EmulatorJS {
18291839
})
18301840
.then((module) => {
18311841
this.Module = module;
1832-
1842+
18331843
// Set up audio node exposure for EmulatorJS after module loads
18341844
const setupAudioExposure = () => {
18351845
if (this.Module && this.Module.AL && this.Module.AL.currentCtx) {
@@ -1844,18 +1854,20 @@ class EmulatorJS {
18441854
} else if (ctx.audioCtx.destination) {
18451855
ctx.masterGain.connect(ctx.audioCtx.destination);
18461856
}
1847-
console.log("[EmulatorJS] Exposed masterGain node for audio capture");
1857+
console.log(
1858+
"[EmulatorJS] Exposed masterGain node for audio capture",
1859+
);
18481860
}
18491861
}
18501862
};
1851-
1863+
18521864
// Check immediately and then periodically
18531865
setupAudioExposure();
18541866
const audioCheckInterval = setInterval(setupAudioExposure, 1000);
1855-
1867+
18561868
// Clear interval after 10 seconds
18571869
setTimeout(() => clearInterval(audioCheckInterval), 10000);
1858-
1870+
18591871
this.downloadFiles();
18601872
})
18611873
.catch((e) => {
@@ -7154,7 +7166,8 @@ class EmulatorJS {
71547166
} else if (option === "netplayStreamResolution") {
71557167
const normalizeResolution = (v) => {
71567168
const s = (typeof v === "string" ? v.trim() : "").toLowerCase();
7157-
if (s === "1080p" || s === "720p" || s === "480p" || s === "360p") return s;
7169+
if (s === "1080p" || s === "720p" || s === "480p" || s === "360p")
7170+
return s;
71587171
return "480p";
71597172
};
71607173
this.netplayStreamResolution = normalizeResolution(value);
@@ -7191,7 +7204,8 @@ class EmulatorJS {
71917204
return "L1T1";
71927205
};
71937206
this.netplayHostScalabilityMode = normalizeHostScalability(value);
7194-
window.EJS_NETPLAY_HOST_SCALABILITY_MODE = this.netplayHostScalabilityMode;
7207+
window.EJS_NETPLAY_HOST_SCALABILITY_MODE =
7208+
this.netplayHostScalabilityMode;
71957209
try {
71967210
if (
71977211
this.isNetplay &&
@@ -8550,17 +8564,21 @@ class EmulatorJS {
85508564
// Create a master gain node and connect all source gains to it
85518565
console.log("[EmulatorJS] Checking OpenAL sources fallback:", {
85528566
hasSources: !!openALCtx.sources,
8553-
sourcesLength: openALCtx.sources ? openALCtx.sources.length : 'undefined',
8567+
sourcesLength: openALCtx.sources
8568+
? openALCtx.sources.length
8569+
: "undefined",
85548570
});
85558571
if (openALCtx.sources && openALCtx.sources.length > 0) {
8556-
console.log("[EmulatorJS] Attempting to create master gain from OpenAL sources");
8572+
console.log(
8573+
"[EmulatorJS] Attempting to create master gain from OpenAL sources",
8574+
);
85578575
try {
85588576
// Find the audio context from the first source
85598577
const firstSource = openALCtx.sources[0];
85608578
console.log("[EmulatorJS] First source info:", {
85618579
hasSource: !!firstSource,
85628580
hasGain: !!firstSource.gain,
8563-
gainType: firstSource.gain ? typeof firstSource.gain : 'undefined',
8581+
gainType: firstSource.gain ? typeof firstSource.gain : "undefined",
85648582
hasContext: !!(firstSource.gain && firstSource.gain.context),
85658583
});
85668584
if (firstSource && firstSource.gain && firstSource.gain.context) {
@@ -8570,24 +8588,33 @@ class EmulatorJS {
85708588

85718589
// Connect all source gains to the master gain
85728590
let connectedCount = 0;
8573-
openALCtx.sources.forEach(source => {
8591+
openALCtx.sources.forEach((source) => {
85748592
if (source.gain && typeof source.gain.connect === "function") {
85758593
source.gain.connect(masterGain);
85768594
connectedCount++;
85778595
}
85788596
});
85798597

85808598
if (connectedCount > 0) {
8581-
console.log(`[EmulatorJS] Created master gain node from ${connectedCount} OpenAL sources`);
8599+
console.log(
8600+
`[EmulatorJS] Created master gain node from ${connectedCount} OpenAL sources`,
8601+
);
85828602
return masterGain;
85838603
} else {
8584-
console.log("[EmulatorJS] No OpenAL sources could be connected to master gain");
8604+
console.log(
8605+
"[EmulatorJS] No OpenAL sources could be connected to master gain",
8606+
);
85858607
}
85868608
} else {
8587-
console.log("[EmulatorJS] OpenAL sources found but no valid gain context");
8609+
console.log(
8610+
"[EmulatorJS] OpenAL sources found but no valid gain context",
8611+
);
85888612
}
85898613
} catch (e) {
8590-
console.warn("[EmulatorJS] Failed to create master gain from OpenAL sources:", e);
8614+
console.warn(
8615+
"[EmulatorJS] Failed to create master gain from OpenAL sources:",
8616+
e,
8617+
);
85918618
}
85928619
}
85938620
}

0 commit comments

Comments
 (0)