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: []
};
// 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') {
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,6 +143,7 @@ async function initialize() {
console.log('Peer connected, current peer count:', peerCount);
// Send the current user's icon to the new peer
try {
const iconBuffer = await drive.get(`/icons/${config.userName}.png`);
if (iconBuffer) {
const iconMessage = JSON.stringify({
@ -144,6 +153,9 @@ async function initialize() {
});
connection.write(iconMessage);
}
} catch (error) {
console.error('Error getting icon:', error);
}
connection.on('data', (data) => {
const messageObj = JSON.parse(data.toString());