Skip to content

Commit

Permalink
Fix: error when sound files are not present
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebarkmin committed Sep 8, 2022
1 parent e8573ed commit c385545
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
7 changes: 7 additions & 0 deletions .changeset/hip-coats-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@bitflow/shell": patch
---

Fix: Error when attempting to play a sound file which is not available. This
bug has existed because new Audio(url).play() returns a promise, therefore the
error, which was thrown was not caught. Now we are catching the error.
20 changes: 5 additions & 15 deletions packages/shell/src/TaskShell/TaskShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,49 +237,39 @@ export const TaskShell = <
if (result) {
if (result.state === "correct") {
if (soundUrls) {
try {
new Audio(soundUrls.correct).play();
} catch (e) {}
new Audio(soundUrls.correct).play().catch(() => {});
}
const nudge = t("correctNudges", {
index: Math.floor(Math.random() * 2),
}) as string;
customDispatch(correctResultStateAction({ nudge }));
} else if (result.state === "wrong" && result.allowRetry) {
if (soundUrls) {
try {
new Audio(soundUrls.wrong).play();
} catch (e) {}
new Audio(soundUrls.wrong).play().catch(() => {});
}
const nudge = t("wrongNudges", {
index: Math.floor(Math.random() * 3),
}) as string;
customDispatch(retryResultStateAction({ nudge }));
} else if (result.state === "wrong") {
if (soundUrls) {
try {
new Audio(soundUrls.wrong).play();
} catch (e) {}
new Audio(soundUrls.wrong).play().catch(() => {});
}
const nudge = t("wrongNudges", {
index: Math.floor(Math.random() * 3),
}) as string;
customDispatch(wrongResultStateAction({ nudge }));
} else if (result.state === "unknown") {
if (soundUrls) {
try {
new Audio(soundUrls.unknown).play();
} catch (e) {}
new Audio(soundUrls.unknown).play().catch(() => {});
}
const nudge = t("unknownNudges", {
index: Math.floor(Math.random() * 2),
}) as string;
customDispatch(unknownResultStateAction({ nudge }));
} else if (result.state === "manual") {
if (soundUrls) {
try {
new Audio(soundUrls.manual).play();
} catch (e) {}
new Audio(soundUrls.manual).play().catch(() => {});
}
const nudge = t("manualNudges", {
index: Math.floor(Math.random() * 2),
Expand Down

1 comment on commit c385545

@vercel
Copy link

@vercel vercel bot commented on c385545 Sep 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.