From 3835149c925457d6ca3c744b10806ddb2dea70d0 Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Sun, 9 Jun 2024 06:35:45 -0400 Subject: [PATCH] add debug --- app.js | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/app.js b/app.js index 3319e8d..cdf9e41 100644 --- a/app.js +++ b/app.js @@ -29,7 +29,7 @@ let config = { rooms: [] }; -// Function to get a random port between 1337 and 2223 +// Function to get a random port between 49152 and 65535 function getRandomPort() { return Math.floor(Math.random() * (65535 - 49152 + 1)) + 49152; } @@ -121,9 +121,17 @@ async function initialize() { await drive.put(`/icons/${username}.png`, avatarBuffer); updateIcon(username, avatarBuffer); } else if (messageObj.type === 'file') { - const fileBuffer = await drive.get(messageObj.filePath); - const fileUrl = `http://localhost:${servePort}${messageObj.filePath}`; - addFileMessage(messageObj.name, messageObj.fileName, fileUrl, messageObj.fileType, messageObj.avatar); + try { + const fileBuffer = await drive.get(messageObj.filePath); + if (fileBuffer) { + const fileUrl = `http://localhost:${servePort}${messageObj.filePath}`; + addFileMessage(messageObj.name, messageObj.fileName, fileUrl, messageObj.fileType, messageObj.avatar); + } else { + console.error('File not found:', messageObj.filePath); + } + } catch (error) { + console.error('Error getting file:', error); + } } else { onMessageAdded(messageObj.name, messageObj.message, messageObj.avatar); } @@ -135,14 +143,18 @@ async function initialize() { console.log('Peer connected, current peer count:', peerCount); // Send the current user's icon to the new peer - const iconBuffer = await drive.get(`/icons/${config.userName}.png`); - if (iconBuffer) { - const iconMessage = JSON.stringify({ - type: 'icon', - username: config.userName, - avatar: iconBuffer.toString('base64'), - }); - connection.write(iconMessage); + try { + const iconBuffer = await drive.get(`/icons/${config.userName}.png`); + if (iconBuffer) { + const iconMessage = JSON.stringify({ + type: 'icon', + username: config.userName, + avatar: iconBuffer.toString('base64'), + }); + connection.write(iconMessage); + } + } catch (error) { + console.error('Error getting icon:', error); } connection.on('data', (data) => {