blob: 5ec77202dc1ed316d0f28f5e4cd9e075cf64e613 [file] [log] [blame]
simone35acc22022-12-02 16:51:12 -05001/*
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 */
simondaae9102022-12-02 16:51:31 -050018import { RemoteVideoOverlay } from '../components/VideoOverlay';
idillon255682e2023-02-06 13:25:26 -050019import { createOptionalContext } from '../hooks/createOptionalContext';
simondaae9102022-12-02 16:51:31 -050020import { useUrlParams } from '../hooks/useUrlParams';
simondaae9102022-12-02 16:51:31 -050021import { ConversationRouteParams } from '../router';
idillonc45a43d2023-02-10 18:12:10 -050022import { ICallManager, useCallManager } from '../services/CallManager';
idillon255682e2023-02-06 13:25:26 -050023import { WithChildren } from '../utils/utils';
simone35acc22022-12-02 16:51:12 -050024
idillon255682e2023-02-06 13:25:26 -050025const optionalCallManagerContext = createOptionalContext<ICallManager>('CallManagerContext');
26export const useCallManagerContext = optionalCallManagerContext.useOptionalContext;
simone35acc22022-12-02 16:51:12 -050027
28export default ({ children }: WithChildren) => {
simon5c677962022-12-02 16:51:54 -050029 const { urlParams } = useUrlParams<ConversationRouteParams>();
idillon255682e2023-02-06 13:25:26 -050030 const callManager = useCallManager();
simone35acc22022-12-02 16:51:12 -050031
idillon255682e2023-02-06 13:25:26 -050032 const { callData } = callManager;
simone35acc22022-12-02 16:51:12 -050033
34 return (
idillon255682e2023-02-06 13:25:26 -050035 <optionalCallManagerContext.Context.Provider value={callManager}>
36 {callData && callData.conversationId !== urlParams.conversationId && (
37 <RemoteVideoOverlay callConversationId={callData.conversationId} />
38 )}
39 {children}
40 </optionalCallManagerContext.Context.Provider>
simone35acc22022-12-02 16:51:12 -050041 );
42};