simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 Savoir-faire Linux Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU Affero General Public License as |
| 6 | * published by the Free Software Foundation; either version 3 of the |
| 7 | * License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU Affero General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Affero General Public |
| 15 | * License along with this program. If not, see |
| 16 | * <https://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | import { createContext, useState } from 'react'; |
| 19 | |
| 20 | import { SetState, WithChildren } from '../utils/utils'; |
| 21 | |
| 22 | interface ICallContext { |
| 23 | micOn: boolean; |
| 24 | setMicOn: SetState<boolean>; |
| 25 | camOn: boolean; |
| 26 | setCamOn: SetState<boolean>; |
| 27 | } |
| 28 | |
| 29 | const defaultCallContext: ICallContext = { |
| 30 | micOn: false, |
| 31 | setMicOn: () => {}, |
| 32 | camOn: false, |
| 33 | setCamOn: () => {}, |
| 34 | }; |
| 35 | |
| 36 | export const CallContext = createContext<ICallContext>(defaultCallContext); |
| 37 | |
| 38 | type CallProviderProps = WithChildren & { |
| 39 | micOn?: boolean; |
| 40 | camOn?: boolean; |
| 41 | }; |
| 42 | |
| 43 | export default ({ |
| 44 | children, |
| 45 | micOn: _micOn = defaultCallContext.micOn, |
| 46 | camOn: _camOn = defaultCallContext.camOn, |
| 47 | }: CallProviderProps) => { |
| 48 | const [micOn, setMicOn] = useState(_micOn); |
| 49 | const [camOn, setCamOn] = useState(_camOn); |
| 50 | |
| 51 | return ( |
| 52 | <CallContext.Provider |
| 53 | value={{ |
| 54 | micOn, |
| 55 | setMicOn, |
| 56 | camOn, |
| 57 | setCamOn, |
| 58 | }} |
| 59 | > |
| 60 | {children} |
| 61 | </CallContext.Provider> |
| 62 | ); |
| 63 | }; |