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
Showing only changes of commit 75be3a5b33 - Show all commits

View File

@ -43,17 +43,18 @@ class Client extends EventEmitter {
const messageObj = JSON.parse(message.toString()); const messageObj = JSON.parse(message.toString());
if (this.joinedRooms.has(messageObj.topic)) { // Process message only if it is from a joined room if (this.joinedRooms.has(messageObj.topic)) { // Process message only if it is from a joined room
this.currentTopic = messageObj.topic; // Set the current topic from the incoming message this.currentTopic = messageObj.topic; // Set the current topic from the incoming message
if (messageObj.type === "message") if (messageObj.type === "message")
this.emit('onMessage', peer, new TextMessage(messageObj.name, messageObj.avatar, messageObj.topic, messageObj.timestamp, messageObj.message)); this.emit('onMessage', peer, new TextMessage(messageObj.name, messageObj.avatar, messageObj.topic, messageObj.timestamp, messageObj.message));
if (messageObj.type === "file") if (messageObj.type === "file")
this.emit('onFile', peer, new FileMessage(messageObj.name, messageObj.avatar, messageObj.fileName, messageObj.fileUrl, messageObj.fileType, messageObj.avatar, messageObj.topic, messageObj.timestamp)); this.emit('onFile', peer, new FileMessage(messageObj.name, messageObj.avatar, messageObj.avatar, messageObj.topic, messageObj.timestamp, messageObj.fileName, messageObj.fileUrl, messageObj.fileType));
if (messageObj.type === "icon") if (messageObj.type === "icon")
this.emit('onIcon', peer, messageObj); this.emit('onIcon', peer, messageObj);
if (messageObj.type === "audio") if (messageObj.type === "audio")
this.emit('onAudio', peer, new AudioMessage()); this.emit('onAudio', peer, new AudioMessage(messageObj.name, messageObj.avatar, messageObj.avatar, messageObj.topic, messageObj.timestamp, messageObj.audio, messageObj.audioType));
} }
}); });