LinkUp-P2P-Chat/chatBot/includes/message/AudioMessage.js
2024-06-15 03:03:43 -04:00

28 lines
947 B
JavaScript

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;