56 lines
1.9 KiB
JavaScript
56 lines
1.9 KiB
JavaScript
import Message from "./Message.js";
|
|
import b4a from "b4a";
|
|
|
|
class AudioMessage extends Message {
|
|
/**
|
|
* @description Creates a new Audio message.
|
|
* @since 1.0
|
|
* @author MiTask
|
|
* @constructor
|
|
* @param {String} peerName Peer username
|
|
* @param {String} peerAvatar Peer avatar URL
|
|
* @param {String} topic Chat room topic string
|
|
* @param {Number} timestamp UNIX Timestamp
|
|
* @param {String} audioUrl URL to the audio file
|
|
* @param {String} audioType Type of the audio file
|
|
* @param {String} audioData Audio file data in base64 String format
|
|
*/
|
|
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
|
|
}
|
|
|
|
/**
|
|
* @since 1.0
|
|
* @author MiTask
|
|
* @returns {String} JSON String with all of the information about the message
|
|
*/
|
|
toJsonString() {
|
|
return JSON.stringify({
|
|
...this.toJson(),
|
|
audioUrl: this.audioUrl,
|
|
audioType: this.audioType,
|
|
audio: this.audioData // Include audio data in JSON
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @description Creates a new audio message instance.
|
|
* @since 1.0
|
|
* @author MiTask
|
|
* @param {Client} bot Bot Client class
|
|
* @param {String} audioUrl URL to the audio file
|
|
* @param {String} audioType Type of the audio file
|
|
* @param {Buffer} audioBuffer Audio file data
|
|
* @returns {AudioMessage} AudioMessage instance.
|
|
*/
|
|
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;
|