Revert back
This commit is contained in:
parent
310f1bd14d
commit
607480c91b
13
app.js
13
app.js
@ -65,7 +65,6 @@ async function initialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
swarm.on('connection', async (connection, info) => {
|
swarm.on('connection', async (connection, info) => {
|
||||||
console.log('New connection established');
|
|
||||||
peerCount++;
|
peerCount++;
|
||||||
updatePeerCount();
|
updatePeerCount();
|
||||||
|
|
||||||
@ -76,15 +75,11 @@ async function initialize() {
|
|||||||
username: userName,
|
username: userName,
|
||||||
avatar: iconBuffer.toString('base64'),
|
avatar: iconBuffer.toString('base64'),
|
||||||
});
|
});
|
||||||
console.log('Sending icon:', iconMessage);
|
|
||||||
connection.write(iconMessage);
|
connection.write(iconMessage);
|
||||||
} else {
|
|
||||||
console.log('Icon not found for user:', userName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
connection.on('data', async (data) => {
|
connection.on('data', async (data) => {
|
||||||
const messageObj = JSON.parse(data.toString());
|
const messageObj = JSON.parse(data.toString());
|
||||||
console.log('Received message:', messageObj);
|
|
||||||
if (messageObj.type === 'icon') {
|
if (messageObj.type === 'icon') {
|
||||||
const username = messageObj.username;
|
const username = messageObj.username;
|
||||||
const avatarBuffer = Buffer.from(messageObj.avatar, 'base64');
|
const avatarBuffer = Buffer.from(messageObj.avatar, 'base64');
|
||||||
@ -96,7 +91,6 @@ async function initialize() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
connection.on('close', () => {
|
connection.on('close', () => {
|
||||||
console.log('Connection closed');
|
|
||||||
peerCount--;
|
peerCount--;
|
||||||
updatePeerCount();
|
updatePeerCount();
|
||||||
});
|
});
|
||||||
@ -282,13 +276,6 @@ async function updateIcon(username, avatarBuffer) {
|
|||||||
const userIcon = document.querySelector(`img[src*="${username}.png"]`);
|
const userIcon = document.querySelector(`img[src*="${username}.png"]`);
|
||||||
if (userIcon) {
|
if (userIcon) {
|
||||||
userIcon.src = URL.createObjectURL(new Blob([avatarBuffer]));
|
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]));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user