add debug
This commit is contained in:
parent
206d095bcf
commit
3835149c92
36
app.js
36
app.js
@ -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') {
|
||||||
const fileBuffer = await drive.get(messageObj.filePath);
|
try {
|
||||||
const fileUrl = `http://localhost:${servePort}${messageObj.filePath}`;
|
const fileBuffer = await drive.get(messageObj.filePath);
|
||||||
addFileMessage(messageObj.name, messageObj.fileName, fileUrl, messageObj.fileType, messageObj.avatar);
|
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 {
|
} else {
|
||||||
onMessageAdded(messageObj.name, messageObj.message, messageObj.avatar);
|
onMessageAdded(messageObj.name, messageObj.message, messageObj.avatar);
|
||||||
}
|
}
|
||||||
@ -135,14 +143,18 @@ 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
|
||||||
const iconBuffer = await drive.get(`/icons/${config.userName}.png`);
|
try {
|
||||||
if (iconBuffer) {
|
const iconBuffer = await drive.get(`/icons/${config.userName}.png`);
|
||||||
const iconMessage = JSON.stringify({
|
if (iconBuffer) {
|
||||||
type: 'icon',
|
const iconMessage = JSON.stringify({
|
||||||
username: config.userName,
|
type: 'icon',
|
||||||
avatar: iconBuffer.toString('base64'),
|
username: config.userName,
|
||||||
});
|
avatar: iconBuffer.toString('base64'),
|
||||||
connection.write(iconMessage);
|
});
|
||||||
|
connection.write(iconMessage);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error getting icon:', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
connection.on('data', (data) => {
|
connection.on('data', (data) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user