From 7a31202ac3b2c6a1700ab6f565de9d019b3e2420 Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Thu, 13 Jun 2024 23:12:31 -0400 Subject: [PATCH] Fixing user avatars/icons concerning all of the major changes today --- app.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app.js b/app.js index 0d3eb91..aa6c3f5 100644 --- a/app.js +++ b/app.js @@ -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);