Revert back

This commit is contained in:
Raven Scott 2024-06-08 15:19:39 -04:00
parent 310f1bd14d
commit 607480c91b

15
app.js
View File

@ -65,7 +65,6 @@ async function initialize() {
}
swarm.on('connection', async (connection, info) => {
console.log('New connection established');
peerCount++;
updatePeerCount();
@ -76,15 +75,11 @@ async function initialize() {
username: userName,
avatar: iconBuffer.toString('base64'),
});
console.log('Sending icon:', iconMessage);
connection.write(iconMessage);
} else {
console.log('Icon not found for user:', userName);
}
connection.on('data', async (data) => {
const messageObj = JSON.parse(data.toString());
console.log('Received message:', messageObj);
if (messageObj.type === 'icon') {
const username = messageObj.username;
const avatarBuffer = Buffer.from(messageObj.avatar, 'base64');
@ -96,7 +91,6 @@ async function initialize() {
});
connection.on('close', () => {
console.log('Connection closed');
peerCount--;
updatePeerCount();
});
@ -282,13 +276,6 @@ async function updateIcon(username, avatarBuffer) {
const userIcon = document.querySelector(`img[src*="${username}.png"]`);
if (userIcon) {
userIcon.src = URL.createObjectURL(new Blob([avatarBuffer]));
} else {
const imgElements = document.querySelectorAll('img'); // Find all img elements
imgElements.forEach(img => {
if (img.src.endsWith(`${username}.png`)) { // Update if it matches the username
img.src = URL.createObjectURL(new Blob([avatarBuffer]));
}
});
}
}
@ -304,4 +291,4 @@ function toggleSetupView() {
setupDiv.classList.toggle('hidden');
}
initialize();
initialize();