Up to date fork #1

Merged
MiTask merged 33 commits from snxraven/LinkUp-P2P-Chat:main into main 2024-06-14 04:32:25 -04:00
Showing only changes of commit 7a31202ac3 - Show all commits

20
app.js
View File

@ -141,9 +141,8 @@ function handleIncomingMessage(messageObj) {
const username = messageObj.username; const username = messageObj.username;
if (messageObj.avatar) { if (messageObj.avatar) {
const avatarBuffer = b4a.from(messageObj.avatar, 'base64'); const avatarBuffer = b4a.from(messageObj.avatar, 'base64');
drive.put(`/icons/${username}.png`, avatarBuffer).then(() => { drive.put(`/icons/${username}.png`, avatarBuffer);
updateIcon(username, avatarBuffer); updateIcon(username, avatarBuffer);
});
} else { } else {
console.error('Received icon message with missing avatar data:', messageObj); 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); 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) => { connection.on('data', (data) => {
const messageObj = JSON.parse(data.toString()); const messageObj = JSON.parse(data.toString());
eventEmitter.emit('onMessage', messageObj); eventEmitter.emit('onMessage', messageObj);
@ -193,7 +206,6 @@ function handleConnection(connection, info) {
updatePeerCount(); updatePeerCount();
} }
function retryConnection(topicBuffer) { function retryConnection(topicBuffer) {
const topic = b4a.toString(topicBuffer, 'hex'); const topic = b4a.toString(topicBuffer, 'hex');
const room = activeRooms.find(room => room.topic === topic); const room = activeRooms.find(room => room.topic === topic);