forked from snxraven/LinkUp-P2P-Chat
30 lines
1018 B
JavaScript
30 lines
1018 B
JavaScript
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;
|