Unify audio playback under App component
This commit is contained in:
parent
8b30fc17cd
commit
2cd4160422
19 changed files with 290 additions and 80 deletions
|
@ -175,7 +175,8 @@ const globalContents: Contents = {
|
|||
export const GlobalAudioContext = React.createContext<Contents>(globalContents);
|
||||
|
||||
export type GlobalAudioProps = {
|
||||
conversationId: string;
|
||||
conversationId: string | undefined;
|
||||
isPaused: boolean;
|
||||
children?: React.ReactNode | React.ReactChildren;
|
||||
};
|
||||
|
||||
|
@ -185,6 +186,7 @@ export type GlobalAudioProps = {
|
|||
*/
|
||||
export const GlobalAudioProvider: React.FC<GlobalAudioProps> = ({
|
||||
conversationId,
|
||||
isPaused,
|
||||
children,
|
||||
}) => {
|
||||
// When moving between conversations - stop audio
|
||||
|
@ -194,6 +196,13 @@ export const GlobalAudioProvider: React.FC<GlobalAudioProps> = ({
|
|||
};
|
||||
}, [conversationId]);
|
||||
|
||||
// Pause when requested by parent
|
||||
React.useEffect(() => {
|
||||
if (isPaused) {
|
||||
globalContents.audio.pause();
|
||||
}
|
||||
}, [isPaused]);
|
||||
|
||||
return (
|
||||
<GlobalAudioContext.Provider value={globalContents}>
|
||||
{children}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue