audio playback

This commit is contained in:
Andrew Gundersen 2021-03-06 10:53:04 -06:00
commit e8bb64e56a
3 changed files with 44 additions and 9 deletions

View file

@ -32,6 +32,7 @@ let socket: WebSocket;
let success = false;
let auth = false;
const authSession = async (_event, payload: string | UserCreds | null): Promise<string> => {
return new Promise((resolve, reject) => {
@ -60,6 +61,17 @@ const authSession = async (_event, payload: string | UserCreds | null): Promise<
});
};
// function parseHexString(str: string) {
// var result = [];
// while (str.length >= 8) {
// result.push(parseInt(str.substring(0, 8), 16));
// str = str.substring(8, str.length);
// }
// return result;
// }
const receiveMessage = (message: string): void => {
while (!auth) {
@ -67,12 +79,16 @@ const receiveMessage = (message: string): void => {
return;
}
// Parse the message.
const parsed: RenderMessage = JSON.parse(message);
console.log('message received', parsed.content.text);
// If there is audio, play it.
if (parsed.content.audio) {
console.log('audio received');
play(parsed.content.audio);
const audioBytes = Buffer.from(parsed.content.audio, 'hex');
play(audioBytes);
}
backgroundMitt.emit('ipc-renderer', {
endpoint: 'render-message',
message: parsed