Initial commit again
This commit is contained in:
27
message/AudioMessage.js
Normal file
27
message/AudioMessage.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import Message from "./Message.js";
|
||||
import b4a from "b4a";
|
||||
|
||||
class AudioMessage extends Message {
|
||||
constructor(peerName, peerAvatar, topic, timestamp, audioUrl, audioType, audioData) {
|
||||
super("audio", peerName, peerAvatar, topic, timestamp);
|
||||
this.audioUrl = audioUrl;
|
||||
this.audioType = audioType;
|
||||
this.audioData = audioData; // Add audio data property
|
||||
}
|
||||
|
||||
toJsonString() {
|
||||
return JSON.stringify({
|
||||
...this.toJson(),
|
||||
audioUrl: this.audioUrl,
|
||||
audioType: this.audioType,
|
||||
audio: this.audioData // Include audio data in JSON
|
||||
});
|
||||
}
|
||||
|
||||
static new(bot, audioUrl, audioType, audioBuffer) {
|
||||
const audioData = b4a.toString(audioBuffer, 'base64'); // Convert audio buffer to base64
|
||||
return new AudioMessage(bot.botName, bot.botAvatar, bot.currentTopic, Date.now(), audioUrl, audioType, audioData);
|
||||
}
|
||||
}
|
||||
|
||||
export default AudioMessage;
|
29
message/FileMessage.js
Normal file
29
message/FileMessage.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import Message from "./Message.js";
|
||||
import b4a from "b4a";
|
||||
|
||||
class FileMessage extends Message {
|
||||
constructor(peerName, peerAvatar, topic, timestamp, fileName, fileUrl, fileType, fileData) {
|
||||
super("file", peerName, peerAvatar, topic, timestamp);
|
||||
this.fileName = fileName;
|
||||
this.fileUrl = fileUrl;
|
||||
this.fileType = fileType;
|
||||
this.fileData = fileData; // Add file data property
|
||||
}
|
||||
|
||||
toJsonString() {
|
||||
return JSON.stringify({
|
||||
...this.toJson(),
|
||||
fileName: this.fileName,
|
||||
fileUrl: this.fileUrl,
|
||||
fileType: this.fileType,
|
||||
file: this.fileData // Include file data in JSON
|
||||
});
|
||||
}
|
||||
|
||||
static new(bot, fileName, fileUrl, fileType, fileBuffer) {
|
||||
const fileData = b4a.toString(fileBuffer, 'base64'); // Convert file buffer to base64
|
||||
return new FileMessage(bot.botName, bot.botAvatar, bot.currentTopic, Date.now(), fileName, fileUrl, fileType, fileData);
|
||||
}
|
||||
}
|
||||
|
||||
export default FileMessage;
|
20
message/IconMessage.js
Normal file
20
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, timestamp) {
|
||||
super("icon", peerName, peerAvatar, null, 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
message/Message.js
Normal file
21
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
message/TextMessage.js
Normal file
21
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