Reworked message format, added support for audio messages, made Message class #10

Merged
snxraven merged 20 commits from MiTask/LinkUp-P2P-Chat:main into main 2024-06-14 14:15:43 -04:00
2 changed files with 3 additions and 2 deletions
Showing only changes of commit 70655ce901 - Show all commits

View File

@ -39,7 +39,7 @@ loadCommands().then(commands => {
// We use Event Emitter here to handle new messages // We use Event Emitter here to handle new messages
bot.on('onMessage', (peer, message) => { bot.on('onMessage', (peer, message) => {
console.log(message); // console.log(message);
console.log(`Message received from ${message.peerName}@${message.topic} at ${new Date(message.timestamp).toLocaleTimeString()}: ${message.message}`); console.log(`Message received from ${message.peerName}@${message.topic} at ${new Date(message.timestamp).toLocaleTimeString()}: ${message.message}`);

View File

@ -90,7 +90,8 @@ class Client extends EventEmitter {
sendMessage(message) { sendMessage(message) {
if(!(message instanceof Message)) return console.log(`message does not extend Message class (TextMessage, FileMessage, AudioMessage).`, message); if(!(message instanceof Message)) return console.log(`message does not extend Message class (TextMessage, FileMessage, AudioMessage).`, message);
console.log('Bot name:', this.botName); // console.log('Bot name:', this.botName);
console.log("Sending message:", message);
const data = message.toJsonString(); const data = message.toJsonString();
const peers = [...this.swarm.connections]; const peers = [...this.swarm.connections];
for (const peer of peers) peer.write(data); for (const peer of peers) peer.write(data);