LinkUp-P2P-Chat/chatBot/includes/message/AudioMessage.js

28 lines
947 B
JavaScript
Raw Permalink Normal View History

2024-06-14 09:43:17 -04:00
import Message from "./Message.js";
import b4a from "b4a";
2024-06-14 09:43:17 -04:00
class AudioMessage extends Message {
constructor(peerName, peerAvatar, topic, timestamp, audioUrl, audioType, audioData) {
2024-06-14 09:43:17 -04:00
super("audio", peerName, peerAvatar, topic, timestamp);
this.audioUrl = audioUrl;
2024-06-14 09:43:17 -04:00
this.audioType = audioType;
this.audioData = audioData; // Add audio data property
2024-06-14 09:43:17 -04:00
}
toJsonString() {
return JSON.stringify({
...this.toJson(),
audioUrl: this.audioUrl,
audioType: this.audioType,
audio: this.audioData // Include audio data in JSON
2024-06-14 09:43:17 -04:00
});
}
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);
2024-06-14 09:43:17 -04:00
}
}
export default AudioMessage;