Unify audio playback under App component

This commit is contained in:
Fedor Indutny 2021-06-29 12:58:29 -07:00 committed by GitHub
parent 8b30fc17cd
commit 2cd4160422
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 290 additions and 80 deletions

View file

@ -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}