forked from snxraven/LinkUp-P2P-Chat
add debug
This commit is contained in:
parent
206d095bcf
commit
3835149c92
36
app.js
36
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) => {
|
||||
|
Loading…
Reference in New Issue
Block a user