forked from snxraven/LinkUp-P2P-Chat
Up to date fork #1
24
app.js
24
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);
|
||||
|
Loading…
Reference in New Issue
Block a user