forked from snxraven/LinkUp-P2P-Chat
Adding proper support for audio messages via bot
This commit is contained in:
@ -1,22 +1,26 @@
|
||||
import Message from "./Message.js";
|
||||
import b4a from "b4a";
|
||||
|
||||
class AudioMessage extends Message {
|
||||
constructor(peerName, peerAvatar, topic, timestamp, audioUrl, audioType) {
|
||||
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
|
||||
audioType: this.audioType,
|
||||
audio: this.audioData // Include audio data in JSON
|
||||
});
|
||||
}
|
||||
|
||||
static new(bot, audioUrl, audioType) {
|
||||
return new AudioMessage(bot.botName, bot.botAvatar, bot.currentTopic, Date.now(), audioUrl, audioType);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user