add debug

This commit is contained in:
Raven Scott 2024-06-09 06:35:45 -04:00
parent 206d095bcf
commit 3835149c92

14
app.js
View File

@ -29,7 +29,7 @@ let config = {
rooms: [] rooms: []
}; };
// Function to get a random port between 1337 and 2223 // Function to get a random port between 49152 and 65535
function getRandomPort() { function getRandomPort() {
return Math.floor(Math.random() * (65535 - 49152 + 1)) + 49152; return Math.floor(Math.random() * (65535 - 49152 + 1)) + 49152;
} }
@ -121,9 +121,17 @@ async function initialize() {
await drive.put(`/icons/${username}.png`, avatarBuffer); await drive.put(`/icons/${username}.png`, avatarBuffer);
updateIcon(username, avatarBuffer); updateIcon(username, avatarBuffer);
} else if (messageObj.type === 'file') { } else if (messageObj.type === 'file') {
try {
const fileBuffer = await drive.get(messageObj.filePath); const fileBuffer = await drive.get(messageObj.filePath);
if (fileBuffer) {
const fileUrl = `http://localhost:${servePort}${messageObj.filePath}`; const fileUrl = `http://localhost:${servePort}${messageObj.filePath}`;
addFileMessage(messageObj.name, messageObj.fileName, fileUrl, messageObj.fileType, messageObj.avatar); 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 { } else {
onMessageAdded(messageObj.name, messageObj.message, messageObj.avatar); onMessageAdded(messageObj.name, messageObj.message, messageObj.avatar);
} }
@ -135,6 +143,7 @@ async function initialize() {
console.log('Peer connected, current peer count:', peerCount); console.log('Peer connected, current peer count:', peerCount);
// Send the current user's icon to the new peer // Send the current user's icon to the new peer
try {
const iconBuffer = await drive.get(`/icons/${config.userName}.png`); const iconBuffer = await drive.get(`/icons/${config.userName}.png`);
if (iconBuffer) { if (iconBuffer) {
const iconMessage = JSON.stringify({ const iconMessage = JSON.stringify({
@ -144,6 +153,9 @@ async function initialize() {
}); });
connection.write(iconMessage); connection.write(iconMessage);
} }
} catch (error) {
console.error('Error getting icon:', error);
}
connection.on('data', (data) => { connection.on('data', (data) => {
const messageObj = JSON.parse(data.toString()); const messageObj = JSON.parse(data.toString());