update
This commit is contained in:
parent
2faf2b6f78
commit
af37909b3f
22
app.js
22
app.js
@ -173,6 +173,7 @@ function handleIncomingMessage(messageObj) {
|
|||||||
|
|
||||||
function handleConnection(connection, info) {
|
function handleConnection(connection, info) {
|
||||||
console.log('New connection', info);
|
console.log('New connection', info);
|
||||||
|
|
||||||
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);
|
||||||
@ -183,9 +184,28 @@ function handleConnection(connection, info) {
|
|||||||
updatePeerCount();
|
updatePeerCount();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connection.on('error', (error) => {
|
||||||
|
console.error('Connection error', error);
|
||||||
|
if (error.code === 'ETIMEDOUT') {
|
||||||
|
retryConnection(info.topicBuffer);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
updatePeerCount();
|
updatePeerCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function retryConnection(topicBuffer) {
|
||||||
|
const topic = b4a.toString(topicBuffer, 'hex');
|
||||||
|
const room = activeRooms.find(room => room.topic === topic);
|
||||||
|
if (room) {
|
||||||
|
console.log('Retrying connection to room:', topic);
|
||||||
|
room.swarm.leave(topicBuffer);
|
||||||
|
joinSwarm(topicBuffer).catch((error) => {
|
||||||
|
console.error('Failed to rejoin room after timeout:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setupTalkButton() {
|
function setupTalkButton() {
|
||||||
const talkButton = document.getElementById('talk-btn');
|
const talkButton = document.getElementById('talk-btn');
|
||||||
if (!talkButton) return;
|
if (!talkButton) return;
|
||||||
@ -763,4 +783,4 @@ async function connectToAllRooms() {
|
|||||||
// Call this function when loading the rooms initially
|
// Call this function when loading the rooms initially
|
||||||
renderRoomList();
|
renderRoomList();
|
||||||
|
|
||||||
initialize();
|
initialize();
|
Loading…
Reference in New Issue
Block a user