From 88d7029a5c148823c89fe6b3163519a63549a783 Mon Sep 17 00:00:00 2001 From: Andrew Gundersen Date: Thu, 11 Mar 2021 15:46:34 -0600 Subject: [PATCH] message playback anim --- src/background/audio.ts | 11 ++++- src/background/session.ts | 6 ++- src/components/inputItem/inputItem.vue | 33 +++++--------- src/components/messageItem.vue | 62 +++++++++++++++++++++++--- 4 files changed, 80 insertions(+), 32 deletions(-) diff --git a/src/background/audio.ts b/src/background/audio.ts index de1c688..5b0ef12 100644 --- a/src/background/audio.ts +++ b/src/background/audio.ts @@ -4,6 +4,8 @@ import { sendAudio } from './session' import { ipcMain } from "electron"; +import { backgroundMitt } from './emitter'; + const portAudio = require('naudiodon'); let ai: typeof portAudio.AudioIO | null = null; @@ -83,9 +85,14 @@ export function play(input: Buffer): void { const audio = bufSplit(input, 8192); - // call this fuction after last audio chunk has been written. + // Called on end of write. const callback = () => { - // TODO: clear portAudio writable buffer on write end. + + // We stop audio playback anim. + backgroundMitt.emit('ipc-renderer', { + endpoint: 'stop-playback-anim' + }); + } write(); diff --git a/src/background/session.ts b/src/background/session.ts index b68229c..5948978 100644 --- a/src/background/session.ts +++ b/src/background/session.ts @@ -55,14 +55,18 @@ const onMessage = (message: string): void => { // check to see if this is a Render Message. if (m.content) { + // If there is audio, play it. if (m.content.audio) { const audioBytes = Buffer.from(m.content.audio as string, 'hex'); + m.content.audio = true; play(audioBytes); + } else { + m.content.audio = false; } // if there is no unique id, add it. - if(!m.uid) m.uid = uuidv4(); + if(!m.uid) m.uid = uuidv4(); } backgroundMitt.emit('ipc-renderer', { diff --git a/src/components/inputItem/inputItem.vue b/src/components/inputItem/inputItem.vue index 7b14bb4..803b6a7 100644 --- a/src/components/inputItem/inputItem.vue +++ b/src/components/inputItem/inputItem.vue @@ -143,28 +143,22 @@ export default defineComponent({ .pause { opacity: 1; &::before { - -moz-animation: audio1 1.5s infinite ease-in-out; - -o-animation: audio1 1.5s infinite ease-in-out; - -webkit-animation: audio1 1.5s infinite ease-in-out; - animation: audio1 1.5s infinite ease-in-out; + -moz-animation: circle1 1.5s infinite ease-in-out; + -o-animation: circle1 1.5s infinite ease-in-out; + -webkit-animation: circle1 1.5s infinite ease-in-out; + animation: circle1 1.5s infinite ease-in-out; } &::after { - -moz-animation: audio2 2.2s infinite ease-in-out; - -o-animation: audio2 2.2s infinite ease-in-out; - -webkit-animation: audio2 2.2s infinite ease-in-out; - animation: audio2 2.2s infinite ease-in-out; + -moz-animation: circle2 2.2s infinite ease-in-out; + -o-animation: circle2 2.2s infinite ease-in-out; + -webkit-animation: circle2 2.2s infinite ease-in-out; + animation: circle2 2.2s infinite ease-in-out; } } } } -.animate-audio1 { - -moz-animation: audio1 1.5s infinite ease-in-out; - -o-animation: audio1 1.5s infinite ease-in-out; - -webkit-animation: audio1 1.5s infinite ease-in-out; - animation: audio1 1.5s infinite ease-in-out; -} -@keyframes audio1 { +@keyframes circle1 { 0%, 100% { box-shadow: 0 0 0 0.4em rgba(195, 195, 195, 0.4); @@ -179,13 +173,8 @@ export default defineComponent({ box-shadow: 0 0 0 0.25em rgba(195, 195, 195, 0.25); } } -.animate-audio2 { - -moz-animation: audio2 2.2s infinite ease-in-out; - -o-animation: audio2 2.2s infinite ease-in-out; - -webkit-animation: audio2 2.2s infinite ease-in-out; - animation: audio2 2.2s infinite ease-in-out; -} -@keyframes audio2 { + +@keyframes circle2 { 0%, 100% { box-shadow: 0 0 0 0.25em rgba(195, 195, 195, 0.15); diff --git a/src/components/messageItem.vue b/src/components/messageItem.vue index 22a9f14..78d43c5 100644 --- a/src/components/messageItem.vue +++ b/src/components/messageItem.vue @@ -50,7 +50,9 @@ -
+
{{ message.context[0] }}
@@ -65,7 +67,7 @@