Skip to content

Commit

Permalink
Feat: Add error text when audio not play
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMhv committed Dec 24, 2024
1 parent 2d848af commit 4df1534
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/components/Widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ export const TTSWidget: React.FC<TTSWidgetProps> = ({
const audioData = Buffer.concat(audioStreamData).toString("base64");

// Sequence of actions
await playAudio(config.NOTIFY_AUDIO_URL);
await playAudio(config.NOTIFY_AUDIO_URL).catch(() =>
setErrorText("Error when play audio")
);
setWidgetText(event.content);
setIsVisible(true);
await new Promise((resolve) =>
Expand Down Expand Up @@ -163,13 +165,23 @@ export const TTSWidget: React.FC<TTSWidgetProps> = ({

// Set up polling
useEffect(() => {
const intervalId = setInterval(fetchEvents, config.QUEUE_CHECK_INTERVAL);
return () => clearInterval(intervalId);
try {
const intervalId = setInterval(fetchEvents, config.QUEUE_CHECK_INTERVAL);
return () => clearInterval(intervalId);
} catch (error) {
console.error("Error set up polling:", error);
setErrorText("Error set up polling");
}
}, [fetchEvents]);

// Process queue when it changes
useEffect(() => {
processQueue();
try {
processQueue();
} catch (error) {
console.error("Error process queue:", error);
setErrorText("Error process queue");
}
}, [queue, processQueue]);

// Handle visibility animations
Expand Down

0 comments on commit 4df1534

Please sign in to comment.