forked from snxraven/LinkUp-P2P-Chat
Compare commits
5 Commits
9f514c31f9
...
e33244c1f1
Author | SHA1 | Date | |
---|---|---|---|
|
e33244c1f1 | ||
|
0587f261b7 | ||
|
ac2da1524d | ||
|
8c54e4ca77 | ||
|
28be0822f6 |
7
app.js
7
app.js
@ -67,6 +67,7 @@ async function initialize() {
|
|||||||
swarm.on('connection', async (connection, info) => {
|
swarm.on('connection', async (connection, info) => {
|
||||||
peerCount++;
|
peerCount++;
|
||||||
updatePeerCount();
|
updatePeerCount();
|
||||||
|
console.log('Peer connected, current peer count:', peerCount);
|
||||||
|
|
||||||
// Send the current user's icon to the new peer
|
// Send the current user's icon to the new peer
|
||||||
const iconBuffer = await drive.get(`/icons/${userName}.png`);
|
const iconBuffer = await drive.get(`/icons/${userName}.png`);
|
||||||
@ -94,6 +95,7 @@ async function initialize() {
|
|||||||
connection.on('close', () => {
|
connection.on('close', () => {
|
||||||
peerCount--;
|
peerCount--;
|
||||||
updatePeerCount();
|
updatePeerCount();
|
||||||
|
console.log('Peer disconnected, current peer count:', peerCount);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -121,7 +123,7 @@ function registerUser(e) {
|
|||||||
reader.onload = (event) => {
|
reader.onload = (event) => {
|
||||||
const buffer = new Uint8Array(event.target.result);
|
const buffer = new Uint8Array(event.target.result);
|
||||||
drive.put(`/icons/${regUsername}.png`, buffer);
|
drive.put(`/icons/${regUsername}.png`, buffer);
|
||||||
userAvatar = URL.createObjectURL(new Blob([buffer]));
|
userAvatar = `http://localhost:1337/icons/${regUsername}.png`; // Set the correct URL
|
||||||
registeredUsers[regUsername] = userAvatar;
|
registeredUsers[regUsername] = userAvatar;
|
||||||
localStorage.setItem('registeredUsers', JSON.stringify(registeredUsers));
|
localStorage.setItem('registeredUsers', JSON.stringify(registeredUsers));
|
||||||
continueRegistration(regUsername);
|
continueRegistration(regUsername);
|
||||||
@ -285,11 +287,10 @@ async function updateIcon(username, avatarBuffer) {
|
|||||||
// This can be adjusted as per your needs
|
// This can be adjusted as per your needs
|
||||||
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 = `http://localhost:1337/icons/${username}.png`; // Ensure the URL is correct
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function clearMessages() {
|
function clearMessages() {
|
||||||
const messagesContainer = document.querySelector('#messages');
|
const messagesContainer = document.querySelector('#messages');
|
||||||
while (messagesContainer.firstChild) {
|
while (messagesContainer.firstChild) {
|
||||||
|
Loading…
Reference in New Issue
Block a user