simon | e35acc2 | 2022-12-02 16:51:12 -0500 | [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 | */ |
simon | daae910 | 2022-12-02 16:51:31 -0500 | [diff] [blame] | 18 | import { RemoteVideoOverlay } from '../components/VideoOverlay'; |
idillon | 255682e | 2023-02-06 13:25:26 -0500 | [diff] [blame] | 19 | import { createOptionalContext } from '../hooks/createOptionalContext'; |
simon | daae910 | 2022-12-02 16:51:31 -0500 | [diff] [blame] | 20 | import { useUrlParams } from '../hooks/useUrlParams'; |
simon | daae910 | 2022-12-02 16:51:31 -0500 | [diff] [blame] | 21 | import { ConversationRouteParams } from '../router'; |
idillon | c45a43d | 2023-02-10 18:12:10 -0500 | [diff] [blame] | 22 | import { ICallManager, useCallManager } from '../services/CallManager'; |
idillon | 255682e | 2023-02-06 13:25:26 -0500 | [diff] [blame] | 23 | import { WithChildren } from '../utils/utils'; |
simon | e35acc2 | 2022-12-02 16:51:12 -0500 | [diff] [blame] | 24 | |
idillon | 255682e | 2023-02-06 13:25:26 -0500 | [diff] [blame] | 25 | const optionalCallManagerContext = createOptionalContext<ICallManager>('CallManagerContext'); |
| 26 | export const useCallManagerContext = optionalCallManagerContext.useOptionalContext; |
simon | e35acc2 | 2022-12-02 16:51:12 -0500 | [diff] [blame] | 27 | |
| 28 | export default ({ children }: WithChildren) => { |
simon | 5c67796 | 2022-12-02 16:51:54 -0500 | [diff] [blame] | 29 | const { urlParams } = useUrlParams<ConversationRouteParams>(); |
idillon | 255682e | 2023-02-06 13:25:26 -0500 | [diff] [blame] | 30 | const callManager = useCallManager(); |
simon | e35acc2 | 2022-12-02 16:51:12 -0500 | [diff] [blame] | 31 | |
idillon | 255682e | 2023-02-06 13:25:26 -0500 | [diff] [blame] | 32 | const { callData } = callManager; |
simon | e35acc2 | 2022-12-02 16:51:12 -0500 | [diff] [blame] | 33 | |
| 34 | return ( |
idillon | 255682e | 2023-02-06 13:25:26 -0500 | [diff] [blame] | 35 | <optionalCallManagerContext.Context.Provider value={callManager}> |
| 36 | {callData && callData.conversationId !== urlParams.conversationId && ( |
| 37 | <RemoteVideoOverlay callConversationId={callData.conversationId} /> |
| 38 | )} |
| 39 | {children} |
| 40 | </optionalCallManagerContext.Context.Provider> |
simon | e35acc2 | 2022-12-02 16:51:12 -0500 | [diff] [blame] | 41 | ); |
| 42 | }; |