From 4d2988f9cddb2061da851f7e154d6d26fbd2b25d Mon Sep 17 00:00:00 2001 From: Alex Vanderveen Date: Fri, 20 Mar 2026 17:32:25 -0400 Subject: [PATCH] Update Syntax --- data/emulator.debug.js | 64 +++++++++++++++++++++++++--------------- data/src/emulator.js | 67 +++++++++++++++++++++++++++++------------- 2 files changed, 87 insertions(+), 44 deletions(-) diff --git a/data/emulator.debug.js b/data/emulator.debug.js index 2fac9aa6..b2229023 100644 --- a/data/emulator.debug.js +++ b/data/emulator.debug.js @@ -6927,9 +6927,14 @@ class NetplayEngine { this.config.callbacks.onSocketConnect(socketId); } // On reconnect after disconnect: trigger full session recreate immediately - if (this._socketWasDisconnected && this.emulator?.netplay?.currentRoomId) { + if ( + this._socketWasDisconnected && + this.emulator?.netplay?.currentRoomId + ) { this._socketWasDisconnected = false; - console.log("[Netplay] Socket reconnected, triggering session recreate"); + console.log( + "[Netplay] Socket reconnected, triggering session recreate", + ); this.recreateSfuSession().catch((e) => console.warn("[Netplay] Reconnect recreate failed:", e), ); @@ -8331,7 +8336,9 @@ class NetplayEngine { if (!this.sfuTransport?.useSFU) return; if (this._recreateInProgress) return; if (!this.socketTransport?.isConnected()) { - console.warn("[Netplay] recreateSfuSession: socket disconnected, skipping"); + console.warn( + "[Netplay] recreateSfuSession: socket disconnected, skipping", + ); return; } this._recreateInProgress = true; @@ -8353,14 +8360,22 @@ class NetplayEngine { netplayUsername: this.sessionState?.localNetplayUsername ?? "Player", preferredSlot: this.sessionState?.getLocalPlayerSlot?.() ?? 0, romHash: this.emulator.config?.romHash ?? null, - romName: this.emulator.config?.romName ?? this.emulator.config?.romFilename ?? null, + romName: + this.emulator.config?.romName ?? + this.emulator.config?.romFilename ?? + null, romFilename: this.emulator.config?.romFilename ?? null, - core: this.emulator.config?.core ?? this.emulator.config?.system ?? null, + core: + this.emulator.config?.core ?? this.emulator.config?.system ?? null, system: this.emulator.config?.system ?? null, platform: this.emulator.config?.platform ?? null, - coreId: this.emulator.config?.coreId ?? this.emulator.config?.system ?? null, + coreId: + this.emulator.config?.coreId ?? this.emulator.config?.system ?? null, coreVersion: this.emulator.config?.coreVersion ?? null, - systemType: this.emulator.config?.systemType ?? this.emulator.config?.system ?? null, + systemType: + this.emulator.config?.systemType ?? + this.emulator.config?.system ?? + null, }; await this.joinRoom(null, roomName, maxPlayers, password, playerInfo); console.log("[Netplay] Rejoin confirmed"); @@ -8384,18 +8399,23 @@ class NetplayEngine { await doRecreate(); console.log("[Netplay] SFU session recreated successfully"); } catch (error) { - const errMsg = typeof error === "string" ? error : error?.message ?? ""; + const errMsg = typeof error === "string" ? error : (error?.message ?? ""); const isNoRoom = errMsg.includes("no room") || errMsg.includes("transport not found"); if (isNoRoom && this.roomManager) { - console.warn("[Netplay] Transport create failed (no room), retrying rejoin and recreate"); + console.warn( + "[Netplay] Transport create failed (no room), retrying rejoin and recreate", + ); try { await doRejoin(); await new Promise((r) => setTimeout(r, 300)); await doRecreate(); console.log("[Netplay] SFU session recreated successfully (retry)"); } catch (retryError) { - console.error("[Netplay] SFU session recreate retry failed:", retryError); + console.error( + "[Netplay] SFU session recreate retry failed:", + retryError, + ); } } else { console.error("[Netplay] SFU session recreate failed:", error); @@ -12352,10 +12372,7 @@ class NetplayEngine { consumer.rtpReceiver.jitterBufferTarget = 50; console.log("[Netplay] Set video consumer jitterBufferTarget=50ms"); } catch (e) { - console.log( - "[Netplay] Could not set jitterBufferTarget:", - e?.message, - ); + console.log("[Netplay] Could not set jitterBufferTarget:", e?.message); } } } @@ -12478,8 +12495,9 @@ class NetplayEngine { `[Netplay] Direct emulator canvas captureStream (${fps === 0 ? "natural" : fps + "fps"})`, ); return ( - this._netplayWrapTrackWithFormatConversion(directTrack) || - directTrack + this._netplayWrapTrackWithFormatConversion( + directTrack, + ) || directTrack ); } } catch (e) { @@ -12554,10 +12572,7 @@ class NetplayEngine { `[Netplay] Found video element, attempting ${resLabel} capture...`, ); try { - let videoTrack = this._netplayCaptureViaOffscreen( - video, - targetFps, - ); + let videoTrack = this._netplayCaptureViaOffscreen(video, targetFps); if (!videoTrack && isMobile) { videoTrack = this._netplayCaptureViaOffscreen(video, 60); } @@ -12636,10 +12651,11 @@ class NetplayEngine { } if (videoTrack) { const res = this._netplayGetStreamResolution(); - console.log( - `[Netplay] Canvas via offscreen (${res.label}):`, - { width: res.width, height: res.height, frameRate: targetFps }, - ); + console.log(`[Netplay] Canvas via offscreen (${res.label}):`, { + width: res.width, + height: res.height, + frameRate: targetFps, + }); return ( this._netplayWrapTrackWithFormatConversion(videoTrack) || videoTrack diff --git a/data/src/emulator.js b/data/src/emulator.js index d53b03b0..5808bff0 100644 --- a/data/src/emulator.js +++ b/data/src/emulator.js @@ -427,7 +427,8 @@ class EmulatorJS { // Resolution (host stream source): 1080p | 720p | 480p | 360p (default 480p, optimized for latency) const normalizeResolution = (v) => { const s = (typeof v === "string" ? v.trim() : "").toLowerCase(); - if (s === "1080p" || s === "720p" || s === "480p" || s === "360p") return s; + if (s === "1080p" || s === "720p" || s === "480p" || s === "360p") + return s; return "480p"; }; const storedResolution = this.preGetSetting("netplayStreamResolution"); @@ -440,7 +441,9 @@ class EmulatorJS { ? this.config.netplayStreamResolution : envResolution; this.netplayStreamResolution = normalizeResolution( - typeof storedResolution === "string" ? storedResolution : configResolution, + typeof storedResolution === "string" + ? storedResolution + : configResolution, ); window.EJS_NETPLAY_STREAM_RESOLUTION = this.netplayStreamResolution; @@ -484,7 +487,9 @@ class EmulatorJS { ? this.config.netplayHostScalabilityMode : envHostScalability; this.netplayHostScalabilityMode = normalizeHostScalability( - typeof storedHostScalability === "string" ? storedHostScalability : configHostScalability, + typeof storedHostScalability === "string" + ? storedHostScalability + : configHostScalability, ); window.EJS_NETPLAY_HOST_SCALABILITY_MODE = this.netplayHostScalabilityMode; @@ -1773,7 +1778,10 @@ class EmulatorJS { const originalAlcCreateContext = this.Module.AL.alcCreateContext; if (originalAlcCreateContext) { this.Module.AL.alcCreateContext = (...args) => { - const ctx = originalAlcCreateContext.apply(this.Module.AL, args); + const ctx = originalAlcCreateContext.apply( + this.Module.AL, + args, + ); if (ctx && ctx.audioCtx) { // Expose the master gain node for EmulatorJS audio capture if (!ctx.masterGain) { @@ -1783,7 +1791,9 @@ class EmulatorJS { if (ctx.masterGain && ctx.audioCtx.destination) { ctx.masterGain.connect(ctx.audioCtx.destination); } - console.log("[EmulatorJS] Exposed masterGain node for audio capture"); + console.log( + "[EmulatorJS] Exposed masterGain node for audio capture", + ); } } return ctx; @@ -1829,7 +1839,7 @@ class EmulatorJS { }) .then((module) => { this.Module = module; - + // Set up audio node exposure for EmulatorJS after module loads const setupAudioExposure = () => { if (this.Module && this.Module.AL && this.Module.AL.currentCtx) { @@ -1844,18 +1854,20 @@ class EmulatorJS { } else if (ctx.audioCtx.destination) { ctx.masterGain.connect(ctx.audioCtx.destination); } - console.log("[EmulatorJS] Exposed masterGain node for audio capture"); + console.log( + "[EmulatorJS] Exposed masterGain node for audio capture", + ); } } }; - + // Check immediately and then periodically setupAudioExposure(); const audioCheckInterval = setInterval(setupAudioExposure, 1000); - + // Clear interval after 10 seconds setTimeout(() => clearInterval(audioCheckInterval), 10000); - + this.downloadFiles(); }) .catch((e) => { @@ -7154,7 +7166,8 @@ class EmulatorJS { } else if (option === "netplayStreamResolution") { const normalizeResolution = (v) => { const s = (typeof v === "string" ? v.trim() : "").toLowerCase(); - if (s === "1080p" || s === "720p" || s === "480p" || s === "360p") return s; + if (s === "1080p" || s === "720p" || s === "480p" || s === "360p") + return s; return "480p"; }; this.netplayStreamResolution = normalizeResolution(value); @@ -7191,7 +7204,8 @@ class EmulatorJS { return "L1T1"; }; this.netplayHostScalabilityMode = normalizeHostScalability(value); - window.EJS_NETPLAY_HOST_SCALABILITY_MODE = this.netplayHostScalabilityMode; + window.EJS_NETPLAY_HOST_SCALABILITY_MODE = + this.netplayHostScalabilityMode; try { if ( this.isNetplay && @@ -8550,17 +8564,21 @@ class EmulatorJS { // Create a master gain node and connect all source gains to it console.log("[EmulatorJS] Checking OpenAL sources fallback:", { hasSources: !!openALCtx.sources, - sourcesLength: openALCtx.sources ? openALCtx.sources.length : 'undefined', + sourcesLength: openALCtx.sources + ? openALCtx.sources.length + : "undefined", }); if (openALCtx.sources && openALCtx.sources.length > 0) { - console.log("[EmulatorJS] Attempting to create master gain from OpenAL sources"); + console.log( + "[EmulatorJS] Attempting to create master gain from OpenAL sources", + ); try { // Find the audio context from the first source const firstSource = openALCtx.sources[0]; console.log("[EmulatorJS] First source info:", { hasSource: !!firstSource, hasGain: !!firstSource.gain, - gainType: firstSource.gain ? typeof firstSource.gain : 'undefined', + gainType: firstSource.gain ? typeof firstSource.gain : "undefined", hasContext: !!(firstSource.gain && firstSource.gain.context), }); if (firstSource && firstSource.gain && firstSource.gain.context) { @@ -8570,7 +8588,7 @@ class EmulatorJS { // Connect all source gains to the master gain let connectedCount = 0; - openALCtx.sources.forEach(source => { + openALCtx.sources.forEach((source) => { if (source.gain && typeof source.gain.connect === "function") { source.gain.connect(masterGain); connectedCount++; @@ -8578,16 +8596,25 @@ class EmulatorJS { }); if (connectedCount > 0) { - console.log(`[EmulatorJS] Created master gain node from ${connectedCount} OpenAL sources`); + console.log( + `[EmulatorJS] Created master gain node from ${connectedCount} OpenAL sources`, + ); return masterGain; } else { - console.log("[EmulatorJS] No OpenAL sources could be connected to master gain"); + console.log( + "[EmulatorJS] No OpenAL sources could be connected to master gain", + ); } } else { - console.log("[EmulatorJS] OpenAL sources found but no valid gain context"); + console.log( + "[EmulatorJS] OpenAL sources found but no valid gain context", + ); } } catch (e) { - console.warn("[EmulatorJS] Failed to create master gain from OpenAL sources:", e); + console.warn( + "[EmulatorJS] Failed to create master gain from OpenAL sources:", + e, + ); } } }