Fixing user avatars/icons concerning all of the major changes today

This commit is contained in:
Raven Scott 2024-06-13 23:12:31 -04:00
parent 7061aa1e5e
commit 7a31202ac3

24
app.js
View File

@ -141,9 +141,8 @@ function handleIncomingMessage(messageObj) {
const username = messageObj.username;
if (messageObj.avatar) {
const avatarBuffer = b4a.from(messageObj.avatar, 'base64');
drive.put(`/icons/${username}.png`, avatarBuffer).then(() => {
updateIcon(username, avatarBuffer);
});
drive.put(`/icons/${username}.png`, avatarBuffer);
updateIcon(username, avatarBuffer);
} else {
console.error('Received icon message with missing avatar data:', messageObj);
}
@ -171,9 +170,23 @@ function handleIncomingMessage(messageObj) {
}
}
function handleConnection(connection, info) {
async function handleConnection(connection, info) {
console.log('New connection', info);
// Sending the icon immediately upon connection
const iconBuffer = await drive.get(`/icons/${config.userName}.png`);
if (iconBuffer) {
const iconMessage = JSON.stringify({
type: 'icon',
username: config.userName,
avatar: b4a.toString(iconBuffer, 'base64'),
});
console.log('Sending icon to new peer:', iconMessage);
connection.write(iconMessage);
} else {
console.error('Icon not found for user:', config.userName);
}
connection.on('data', (data) => {
const messageObj = JSON.parse(data.toString());
eventEmitter.emit('onMessage', messageObj);
@ -193,7 +206,6 @@ function handleConnection(connection, info) {
updatePeerCount();
}
function retryConnection(topicBuffer) {
const topic = b4a.toString(topicBuffer, 'hex');
const room = activeRooms.find(room => room.topic === topic);