forked from snxraven/LinkUp-P2P-Chat
Made Client.js->setupSwarm() parsing messages more readable
This commit is contained in:
23
chatBot/includes/message/AudioMessage.js
Normal file
23
chatBot/includes/message/AudioMessage.js
Normal file
@ -0,0 +1,23 @@
|
||||
import Message from "./Message.js";
|
||||
|
||||
class AudioMessage extends Message {
|
||||
constructor(peerName, peerAvatar, topic, timestamp, audio, audioType) {
|
||||
super("audio", peerName, peerAvatar, topic, timestamp);
|
||||
this.audio = audio;
|
||||
this.audioType = audioType;
|
||||
}
|
||||
|
||||
toJsonString() {
|
||||
return JSON.stringify({
|
||||
...this.toJson(),
|
||||
audio: this.audio,
|
||||
audioType: this.audioType
|
||||
});
|
||||
}
|
||||
|
||||
static new(bot, audio, audioType) {
|
||||
return new AudioMessage(bot.botName, bot.botAvatar, bot.currentTopic, Date.now(), audio, audioType);
|
||||
}
|
||||
}
|
||||
|
||||
export default AudioMessage;
|
25
chatBot/includes/message/FileMessage.js
Normal file
25
chatBot/includes/message/FileMessage.js
Normal file
@ -0,0 +1,25 @@
|
||||
import Message from "./Message.js";
|
||||
|
||||
class FileMessage extends Message {
|
||||
constructor(peerName, peerAvatar, topic, timestamp, fileName, fileUrl, fileType) {
|
||||
super("file", peerName, peerAvatar, topic, timestamp);
|
||||
this.fileName = fileName;
|
||||
this.fileUrl = fileUrl;
|
||||
this.fileType = fileType;
|
||||
}
|
||||
|
||||
toJsonString() {
|
||||
return JSON.stringify({
|
||||
...this.toJson(),
|
||||
fileName: this.fileName,
|
||||
fileUrl: this.fileUrl,
|
||||
fileType: this.fileType
|
||||
});
|
||||
}
|
||||
|
||||
static new(bot, fileName, fileUrl, fileType) {
|
||||
return new FileMessage(bot.botName, bot.botAvatar, bot.currentTopic, Date.now(), fileName, fileUrl, fileType);
|
||||
}
|
||||
}
|
||||
|
||||
export default FileMessage;
|
20
chatBot/includes/message/IconMessage.js
Normal file
20
chatBot/includes/message/IconMessage.js
Normal file
@ -0,0 +1,20 @@
|
||||
import Message from "./Message.js";
|
||||
import b4a from "b4a";
|
||||
|
||||
class IconMessage extends Message {
|
||||
constructor(peerName, peerAvatar, topic, timestamp) {
|
||||
super("icon", peerName, peerAvatar, topic, timestamp);
|
||||
}
|
||||
|
||||
toJsonString() {
|
||||
return JSON.stringify({
|
||||
...this.toJson()
|
||||
});
|
||||
}
|
||||
|
||||
static new(bot, avatarBuffer) {
|
||||
return new IconMessage(bot.botName, b4a.toString(avatarBuffer, 'base64'), Date.now());
|
||||
}
|
||||
}
|
||||
|
||||
export default IconMessage;
|
21
chatBot/includes/message/Message.js
Normal file
21
chatBot/includes/message/Message.js
Normal file
@ -0,0 +1,21 @@
|
||||
class Message {
|
||||
constructor(messageType, peerName, peerAvatar, topic, timestamp) {
|
||||
this.type = messageType;
|
||||
this.peerName = peerName;
|
||||
this.peerAvatar = peerAvatar;
|
||||
this.topic = topic;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
toJson() {
|
||||
return {
|
||||
type: this.type,
|
||||
name: this.peerName,
|
||||
avatar: this.peerAvatar,
|
||||
topic: this.topic,
|
||||
timestamp: this.timestamp
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default Message;
|
21
chatBot/includes/message/TextMessage.js
Normal file
21
chatBot/includes/message/TextMessage.js
Normal file
@ -0,0 +1,21 @@
|
||||
import Message from "./Message.js";
|
||||
|
||||
class TextMessage extends Message {
|
||||
constructor(peerName, peerAvatar, topic, timestamp, message) {
|
||||
super("message", peerName, peerAvatar, topic, timestamp);
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
toJsonString() {
|
||||
return JSON.stringify({
|
||||
...this.toJson(),
|
||||
message: this.message,
|
||||
});
|
||||
}
|
||||
|
||||
static new(bot, message) {
|
||||
return new TextMessage(bot.botName, bot.botAvatar, bot.currentTopic, Date.now(), message);
|
||||
}
|
||||
}
|
||||
|
||||
export default TextMessage;
|
Reference in New Issue
Block a user