From efcaa760df0dfcd586d785c1f705dec5cd1e5243 Mon Sep 17 00:00:00 2001 From: Administrator Date: Thu, 12 Mar 2026 07:39:20 +0100 Subject: [PATCH] fix: buffer WebRTC signaling messages until capture window is ready The capture window creation is async but the browser's WebRTC offer arrives immediately after auth. Messages were silently dropped during window initialization, preventing video stream from establishing. Co-Authored-By: Claude Opus 4.6 --- main.js | 24 +++++++++++++++++++++++- package.json | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 197f5ef..454cd3a 100644 --- a/main.js +++ b/main.js @@ -21,6 +21,8 @@ let uploadManager = null; let folderMonitor = new FolderMonitor(); let remoteServer = null; let captureWindow = null; +let captureWindowReady = false; +let signalingQueue = []; const HEALTH_CHECK_TIMEOUT = 25000; // --- Debug logging (writes to upload-debug.log next to the app) --- @@ -918,6 +920,7 @@ function generateToken() { function createCaptureWindow() { if (captureWindow && !captureWindow.isDestroyed()) return; + captureWindowReady = false; captureWindow = new BrowserWindow({ show: false, webPreferences: { @@ -928,9 +931,21 @@ function createCaptureWindow() { }); captureWindow.loadFile(path.join(__dirname, 'lib', 'remote-capture.html')); + // Wait for window to be fully loaded before sending signaling messages + captureWindow.webContents.on('dom-ready', () => { + debugLog('remote: capture window ready, draining', signalingQueue.length, 'queued messages'); + captureWindowReady = true; + for (const msg of signalingQueue) { + captureWindow.webContents.send('remote:signaling-to-capture', msg); + } + signalingQueue = []; + }); + // Crash recovery: if hidden window closes unexpectedly while clients connected, recreate it captureWindow.on('closed', () => { captureWindow = null; + captureWindowReady = false; + signalingQueue = []; if (remoteServer && remoteServer.getClientCount() > 0) { debugLog('remote: capture window crashed, recreating...'); createCaptureWindow(); @@ -969,8 +984,15 @@ async function startRemoteServer() { allowInput: remote.allowInput !== false, mainWindow, onSignalingToCapture: (data) => { - if (captureWindow && !captureWindow.isDestroyed()) { + if (!captureWindow || captureWindow.isDestroyed()) { + debugLog('remote: signaling dropped, no capture window'); + return; + } + if (captureWindowReady) { captureWindow.webContents.send('remote:signaling-to-capture', data); + } else { + debugLog('remote: capture window not ready, queuing', data.type, 'message'); + signalingQueue.push(data); } }, onCreateCaptureWindow: () => createCaptureWindow(), diff --git a/package.json b/package.json index afb0859..cd58bfd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "multi-hoster-uploader", - "version": "2.1.1", + "version": "2.1.2", "description": "Upload files to doodstream, voe, vidmoly, byse simultaneously", "main": "main.js", "scripts": {