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 <noreply@anthropic.com>
This commit is contained in:
Administrator 2026-03-12 07:39:20 +01:00
parent e19c36b1fb
commit efcaa760df
2 changed files with 24 additions and 2 deletions

24
main.js
View File

@ -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(),

View File

@ -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": {