This commit is contained in:
Raven Scott 2024-06-13 14:50:23 -04:00
parent 6a7eb78d34
commit 3c803c811e

9
app.js
View File

@ -38,6 +38,7 @@ function getRandomPort() {
}
async function initialize() {
try {
swarm = new Hyperswarm();
servePort = getRandomPort();
@ -193,6 +194,9 @@ async function initialize() {
document.addEventListener("DOMContentLoaded", (event) => {
hljs.highlightAll();
});
} catch (error) {
console.error('Error during initialization:', error);
}
}
function setupTalkButton() {
@ -321,6 +325,7 @@ async function joinChatRoom(e) {
async function joinSwarm(topicBuffer) {
const topic = b4a.toString(topicBuffer, 'hex');
if (!activeRooms.some(room => room.topic === topic)) {
try {
const discovery = swarm.join(topicBuffer, { client: true, server: true });
await discovery.flushed();
@ -329,6 +334,9 @@ async function joinSwarm(topicBuffer) {
console.log('Joined room:', topic); // Debugging log
renderMessagesForRoom(topic);
} catch (error) {
console.error('Error joining swarm for topic:', topic, error);
}
}
}
@ -667,6 +675,7 @@ function addAudioMessage(from, audioUrl, avatar, topic) {
console.log(`Message for topic ${topic} not rendered because current topic is ${currentTopic}`); // Debugging log
}
}
function truncateHash(hash) {
return `${hash.slice(0, 6)}...${hash.slice(-6)}`;
}