nice touchups and fixing audio playing issues

This commit is contained in:
Arjun Patel
2022-01-21 19:21:11 -08:00
parent 6f652b3353
commit 643383cf57
4 changed files with 45 additions and 12 deletions
+30 -4
View File
@@ -139,14 +139,38 @@ export default function KeyboardContextProvider({ children }) {
// manage audio queue
useEffect(() => {
// every time queue changes,
// setPlayerSrc as the next item if there is any
// setPlayerSrc as the next item if there is any to play it
if (audioQueue && audioQueue.length > 0) {
toast("Adding Message to Queue");
setPlayerSrc(audioQueue[0]);
// todo: edge case, if it's the same link again, then still play it somehow
if (playerSrc == audioQueue[0]) {
// play empty one and then add the next audio file
setPlayerSrc("");
setTimeout(() => {
setPlayerSrc(audioQueue[0]);
}, 1000);
} else {
setPlayerSrc(audioQueue[0]);
}
}
if (!audioQueue || audioQueue.length == 0) {
setPlayerSrc(null);
}
}, [audioQueue]);
// show toast when recording
useEffect(() => {
if (isRecordingAnnouncement || isRecording) {
toast.loading("Recording...");
} else {
toast.dismiss();
}
}, [isRecording, isRecordingAnnouncement]);
const value: KeyboardContextInterface = {
selectedTeammate,
selectTeamMember,
@@ -267,7 +291,8 @@ export default function KeyboardContextProvider({ children }) {
recorder
.start()
.then(() => {
toast.success("started recording");
// toast.success("started recording");
console.log("recording started");
})
.catch((e) =>
toast.error("there was a problem in starting your recording")
@@ -502,7 +527,8 @@ export default function KeyboardContextProvider({ children }) {
function handleResetView() {
setSelectedTeamMember(null);
setShowModalType(ShowModalType.na);
setPlayerSrc(null);
setAudioQueue([]);
}
// IMPORTANT: shortcut handlers need to be updated as the function has to have the fresh state