simon | f929a36 | 2022-11-18 16:53:45 -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 | */ |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 18 | import { CallAction, CallBegin, WebSocketMessageType } from 'jami-web-common'; |
Misha Krieger-Raynauld | 20cf1c8 | 2022-11-23 20:26:50 -0500 | [diff] [blame] | 19 | import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react'; |
simon | accd802 | 2022-11-24 15:04:53 -0500 | [diff] [blame] | 20 | import { Navigate, useNavigate } from 'react-router-dom'; |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 21 | |
| 22 | import { useUrlParams } from '../hooks/useUrlParams'; |
| 23 | import { CallRouteParams } from '../router'; |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 24 | import { callTimeoutMs } from '../utils/constants'; |
simon | f9d78f2 | 2022-11-25 15:47:15 -0500 | [diff] [blame] | 25 | import { SetState, WithChildren } from '../utils/utils'; |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 26 | import { ConversationContext } from './ConversationProvider'; |
Misha Krieger-Raynauld | 20cf1c8 | 2022-11-23 20:26:50 -0500 | [diff] [blame] | 27 | import { WebRtcContext } from './WebRtcProvider'; |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 28 | import { WebSocketContext } from './WebSocketProvider'; |
| 29 | |
| 30 | export type CallRole = 'caller' | 'receiver'; |
| 31 | |
| 32 | export enum CallStatus { |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 33 | Default, |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 34 | Ringing, |
| 35 | Connecting, |
| 36 | InCall, |
| 37 | } |
| 38 | |
| 39 | export interface ICallContext { |
| 40 | mediaDevices: Record<MediaDeviceKind, MediaDeviceInfo[]>; |
| 41 | |
| 42 | localStream: MediaStream | undefined; |
| 43 | remoteStream: MediaStream | undefined; // TODO: should be an array of participants. find a way to map MediaStream id to contactid https://stackoverflow.com/a/68663155/6592293 |
| 44 | |
| 45 | isAudioOn: boolean; |
| 46 | setAudioStatus: (isOn: boolean) => void; |
| 47 | isVideoOn: boolean; |
| 48 | setVideoStatus: (isOn: boolean) => void; |
simon | f9d78f2 | 2022-11-25 15:47:15 -0500 | [diff] [blame] | 49 | isChatShown: boolean; |
| 50 | setIsChatShown: SetState<boolean>; |
simon | 2a5cf14 | 2022-11-25 15:47:35 -0500 | [diff] [blame] | 51 | isFullscreen: boolean; |
| 52 | setIsFullscreen: SetState<boolean>; |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 53 | callRole: CallRole; |
| 54 | callStatus: CallStatus; |
Gabriel Rochon | e382a30 | 2022-11-23 12:37:04 -0500 | [diff] [blame] | 55 | callStartTime: Date | undefined; |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 56 | |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 57 | acceptCall: (withVideoOn: boolean) => void; |
simon | accd802 | 2022-11-24 15:04:53 -0500 | [diff] [blame] | 58 | endCall: () => void; |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | const defaultCallContext: ICallContext = { |
| 62 | mediaDevices: { |
| 63 | audioinput: [], |
| 64 | audiooutput: [], |
| 65 | videoinput: [], |
| 66 | }, |
| 67 | |
| 68 | localStream: undefined, |
| 69 | remoteStream: undefined, |
| 70 | |
| 71 | isAudioOn: false, |
| 72 | setAudioStatus: () => {}, |
| 73 | isVideoOn: false, |
| 74 | setVideoStatus: () => {}, |
simon | f9d78f2 | 2022-11-25 15:47:15 -0500 | [diff] [blame] | 75 | isChatShown: false, |
| 76 | setIsChatShown: () => {}, |
simon | 2a5cf14 | 2022-11-25 15:47:35 -0500 | [diff] [blame] | 77 | isFullscreen: false, |
| 78 | setIsFullscreen: () => {}, |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 79 | callRole: 'caller', |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 80 | callStatus: CallStatus.Default, |
Gabriel Rochon | e382a30 | 2022-11-23 12:37:04 -0500 | [diff] [blame] | 81 | callStartTime: undefined, |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 82 | |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 83 | acceptCall: (_: boolean) => {}, |
simon | accd802 | 2022-11-24 15:04:53 -0500 | [diff] [blame] | 84 | endCall: () => {}, |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | export const CallContext = createContext<ICallContext>(defaultCallContext); |
| 88 | |
| 89 | export default ({ children }: WithChildren) => { |
| 90 | const { |
| 91 | queryParams: { role: callRole }, |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 92 | state: routeState, |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 93 | } = useUrlParams<CallRouteParams>(); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 94 | const webSocket = useContext(WebSocketContext); |
Misha Krieger-Raynauld | 20cf1c8 | 2022-11-23 20:26:50 -0500 | [diff] [blame] | 95 | const { webRtcConnection, remoteStreams, sendWebRtcOffer, isConnected } = useContext(WebRtcContext); |
| 96 | const { conversationId, conversation } = useContext(ConversationContext); |
simon | accd802 | 2022-11-24 15:04:53 -0500 | [diff] [blame] | 97 | const navigate = useNavigate(); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 98 | |
| 99 | const [mediaDevices, setMediaDevices] = useState<Record<MediaDeviceKind, MediaDeviceInfo[]>>( |
| 100 | defaultCallContext.mediaDevices |
| 101 | ); |
| 102 | const [localStream, setLocalStream] = useState<MediaStream>(); |
| 103 | |
| 104 | const [isAudioOn, setIsAudioOn] = useState(false); |
| 105 | const [isVideoOn, setIsVideoOn] = useState(false); |
simon | f9d78f2 | 2022-11-25 15:47:15 -0500 | [diff] [blame] | 106 | const [isChatShown, setIsChatShown] = useState(false); |
simon | 2a5cf14 | 2022-11-25 15:47:35 -0500 | [diff] [blame] | 107 | const [isFullscreen, setIsFullscreen] = useState(false); |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 108 | const [callStatus, setCallStatus] = useState(routeState?.callStatus); |
Gabriel Rochon | e382a30 | 2022-11-23 12:37:04 -0500 | [diff] [blame] | 109 | const [callStartTime, setCallStartTime] = useState<Date | undefined>(undefined); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 110 | |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 111 | // TODO: This logic will have to change to support multiple people in a call. Could we move this logic to the server? |
| 112 | // The client could make a single request with the conversationId, and the server would be tasked with sending |
| 113 | // all the individual requests to the members of the conversation. |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 114 | const contactUri = useMemo(() => conversation.getFirstMember().contact.getUri(), [conversation]); |
| 115 | |
| 116 | useEffect(() => { |
simon | feaa1db | 2022-11-26 20:13:18 -0500 | [diff] [blame] | 117 | if (!isConnected) { |
| 118 | return; |
| 119 | } |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 120 | |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 121 | try { |
simon | feaa1db | 2022-11-26 20:13:18 -0500 | [diff] [blame] | 122 | // TODO: Wait until status is `InCall` before getting devices |
| 123 | navigator.mediaDevices.enumerateDevices().then((devices) => { |
| 124 | const newMediaDevices: Record<MediaDeviceKind, MediaDeviceInfo[]> = { |
| 125 | audioinput: [], |
| 126 | audiooutput: [], |
| 127 | videoinput: [], |
| 128 | }; |
| 129 | |
| 130 | for (const device of devices) { |
| 131 | newMediaDevices[device.kind].push(device); |
| 132 | } |
| 133 | |
| 134 | setMediaDevices(newMediaDevices); |
| 135 | }); |
| 136 | } catch (e) { |
| 137 | console.error('Could not get media devices:', e); |
| 138 | } |
| 139 | |
| 140 | try { |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 141 | navigator.mediaDevices |
| 142 | .getUserMedia({ |
| 143 | audio: true, // TODO: Set both to false by default |
| 144 | video: true, |
| 145 | }) |
| 146 | .then((stream) => { |
| 147 | for (const track of stream.getTracks()) { |
| 148 | // TODO: Set default from isVideoOn and isMicOn values |
| 149 | track.enabled = false; |
| 150 | } |
| 151 | setLocalStream(stream); |
| 152 | }); |
| 153 | } catch (e) { |
| 154 | // TODO: Better handle user denial |
| 155 | console.error('Could not get media devices:', e); |
| 156 | } |
simon | feaa1db | 2022-11-26 20:13:18 -0500 | [diff] [blame] | 157 | }, [isConnected]); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 158 | |
| 159 | useEffect(() => { |
Misha Krieger-Raynauld | 20cf1c8 | 2022-11-23 20:26:50 -0500 | [diff] [blame] | 160 | if (localStream && webRtcConnection) { |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 161 | for (const track of localStream.getTracks()) { |
Misha Krieger-Raynauld | 20cf1c8 | 2022-11-23 20:26:50 -0500 | [diff] [blame] | 162 | webRtcConnection.addTrack(track, localStream); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 163 | } |
| 164 | } |
Misha Krieger-Raynauld | 20cf1c8 | 2022-11-23 20:26:50 -0500 | [diff] [blame] | 165 | }, [localStream, webRtcConnection]); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 166 | |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 167 | const setAudioStatus = useCallback( |
| 168 | (isOn: boolean) => { |
| 169 | if (!localStream) { |
| 170 | return; |
| 171 | } |
| 172 | |
| 173 | for (const track of localStream.getAudioTracks()) { |
| 174 | track.enabled = isOn; |
| 175 | } |
| 176 | |
| 177 | setIsAudioOn(isOn); |
| 178 | }, |
| 179 | [localStream] |
| 180 | ); |
| 181 | |
| 182 | const setVideoStatus = useCallback( |
| 183 | (isOn: boolean) => { |
| 184 | if (!localStream) { |
| 185 | return; |
| 186 | } |
| 187 | |
| 188 | for (const track of localStream.getVideoTracks()) { |
| 189 | track.enabled = isOn; |
| 190 | } |
| 191 | |
| 192 | setIsVideoOn(isOn); |
| 193 | }, |
| 194 | [localStream] |
| 195 | ); |
| 196 | |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 197 | useEffect(() => { |
| 198 | if (!webSocket) { |
| 199 | return; |
| 200 | } |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 201 | |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 202 | if (callRole === 'caller' && callStatus === CallStatus.Default) { |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 203 | const callBegin: CallBegin = { |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 204 | contactId: contactUri, |
| 205 | conversationId, |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 206 | withVideoOn: routeState?.isVideoOn ?? false, |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 207 | }; |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 208 | |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 209 | console.info('Sending CallBegin', callBegin); |
| 210 | webSocket.send(WebSocketMessageType.CallBegin, callBegin); |
| 211 | setCallStatus(CallStatus.Ringing); |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 212 | setIsVideoOn(routeState?.isVideoOn ?? false); |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 213 | } |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 214 | }, [webSocket, callRole, callStatus, contactUri, conversationId, routeState]); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 215 | |
| 216 | useEffect(() => { |
simon | 2a5cf14 | 2022-11-25 15:47:35 -0500 | [diff] [blame] | 217 | const onFullscreenChange = () => { |
| 218 | setIsFullscreen(document.fullscreenElement !== null); |
| 219 | }; |
| 220 | |
| 221 | document.addEventListener('fullscreenchange', onFullscreenChange); |
| 222 | return () => { |
| 223 | document.removeEventListener('fullscreenchange', onFullscreenChange); |
| 224 | }; |
| 225 | }, []); |
| 226 | |
| 227 | useEffect(() => { |
Misha Krieger-Raynauld | 20cf1c8 | 2022-11-23 20:26:50 -0500 | [diff] [blame] | 228 | if (!webSocket || !webRtcConnection) { |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 229 | return; |
| 230 | } |
| 231 | |
| 232 | if (callRole === 'caller' && callStatus === CallStatus.Ringing) { |
simon | accd802 | 2022-11-24 15:04:53 -0500 | [diff] [blame] | 233 | const callAcceptListener = (data: CallAction) => { |
| 234 | console.info('Received event on CallAccept', data); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 235 | setCallStatus(CallStatus.Connecting); |
| 236 | |
Misha Krieger-Raynauld | 20cf1c8 | 2022-11-23 20:26:50 -0500 | [diff] [blame] | 237 | webRtcConnection |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 238 | .createOffer({ |
| 239 | offerToReceiveAudio: true, |
| 240 | offerToReceiveVideo: true, |
| 241 | }) |
Misha Krieger-Raynauld | 20cf1c8 | 2022-11-23 20:26:50 -0500 | [diff] [blame] | 242 | .then((sdp) => { |
| 243 | sendWebRtcOffer(sdp); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 244 | }); |
| 245 | }; |
| 246 | |
| 247 | webSocket.bind(WebSocketMessageType.CallAccept, callAcceptListener); |
| 248 | |
| 249 | return () => { |
| 250 | webSocket.unbind(WebSocketMessageType.CallAccept, callAcceptListener); |
| 251 | }; |
| 252 | } |
Misha Krieger-Raynauld | 20cf1c8 | 2022-11-23 20:26:50 -0500 | [diff] [blame] | 253 | }, [callRole, webSocket, webRtcConnection, sendWebRtcOffer, callStatus]); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 254 | |
simon | accd802 | 2022-11-24 15:04:53 -0500 | [diff] [blame] | 255 | const quitCall = useCallback(() => { |
| 256 | if (!webRtcConnection) { |
| 257 | throw new Error('Could not quit call: webRtcConnection is not defined'); |
| 258 | } |
| 259 | |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 260 | const localTracks = localStream?.getTracks(); |
| 261 | if (localTracks) { |
| 262 | for (const track of localTracks) { |
| 263 | track.stop(); |
| 264 | } |
| 265 | } |
| 266 | |
simon | accd802 | 2022-11-24 15:04:53 -0500 | [diff] [blame] | 267 | webRtcConnection.close(); |
| 268 | navigate(`/conversation/${conversationId}`); |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 269 | }, [webRtcConnection, localStream, navigate, conversationId]); |
simon | accd802 | 2022-11-24 15:04:53 -0500 | [diff] [blame] | 270 | |
| 271 | useEffect(() => { |
| 272 | if (!webSocket) { |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | const callEndListener = (data: CallAction) => { |
| 277 | console.info('Received event on CallEnd', data); |
| 278 | quitCall(); |
| 279 | // TODO: write in chat that the call ended |
| 280 | }; |
| 281 | |
| 282 | webSocket.bind(WebSocketMessageType.CallEnd, callEndListener); |
| 283 | return () => { |
| 284 | webSocket.unbind(WebSocketMessageType.CallEnd, callEndListener); |
| 285 | }; |
| 286 | }, [webSocket, navigate, conversationId, quitCall]); |
| 287 | |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 288 | useEffect(() => { |
| 289 | if (callStatus === CallStatus.Connecting && isConnected) { |
| 290 | console.info('Changing call status to InCall'); |
| 291 | setCallStatus(CallStatus.InCall); |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 292 | setVideoStatus(isVideoOn); |
Gabriel Rochon | e382a30 | 2022-11-23 12:37:04 -0500 | [diff] [blame] | 293 | setCallStartTime(new Date()); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 294 | } |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 295 | }, [isConnected, callStatus, setVideoStatus, isVideoOn]); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 296 | |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 297 | const acceptCall = useCallback( |
| 298 | (withVideoOn: boolean) => { |
| 299 | if (!webSocket) { |
| 300 | throw new Error('Could not accept call'); |
| 301 | } |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 302 | |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 303 | const callAccept: CallAction = { |
| 304 | contactId: contactUri, |
| 305 | conversationId, |
| 306 | }; |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 307 | |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 308 | console.info('Sending CallAccept', callAccept); |
| 309 | webSocket.send(WebSocketMessageType.CallAccept, callAccept); |
| 310 | setIsVideoOn(withVideoOn); |
| 311 | setCallStatus(CallStatus.Connecting); |
| 312 | }, |
| 313 | [webSocket, contactUri, conversationId] |
| 314 | ); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 315 | |
simon | accd802 | 2022-11-24 15:04:53 -0500 | [diff] [blame] | 316 | const endCall = useCallback(() => { |
| 317 | if (!webSocket) { |
| 318 | throw new Error('Could not end call'); |
| 319 | } |
| 320 | |
| 321 | const callEnd: CallAction = { |
| 322 | contactId: contactUri, |
| 323 | conversationId, |
| 324 | }; |
| 325 | |
| 326 | console.info('Sending CallEnd', callEnd); |
| 327 | webSocket.send(WebSocketMessageType.CallEnd, callEnd); |
| 328 | quitCall(); |
| 329 | // TODO: write in chat that the call ended |
| 330 | }, [webSocket, contactUri, conversationId, quitCall]); |
| 331 | |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 332 | useEffect(() => { |
| 333 | const checkStatusTimeout = () => { |
| 334 | if (callStatus !== CallStatus.InCall) { |
| 335 | endCall(); |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 336 | } |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 337 | }; |
| 338 | const timeoutId = setTimeout(checkStatusTimeout, callTimeoutMs); |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 339 | |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 340 | return () => { |
| 341 | clearTimeout(timeoutId); |
| 342 | }; |
| 343 | }, [callStatus, endCall]); |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 344 | |
| 345 | if (!callRole || callStatus === undefined) { |
| 346 | console.error('Invalid route. Redirecting...'); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 347 | return <Navigate to={'/'} />; |
| 348 | } |
| 349 | |
| 350 | return ( |
| 351 | <CallContext.Provider |
| 352 | value={{ |
| 353 | mediaDevices, |
| 354 | localStream, |
| 355 | remoteStream: remoteStreams?.at(-1), |
| 356 | isAudioOn, |
| 357 | setAudioStatus, |
| 358 | isVideoOn, |
| 359 | setVideoStatus, |
simon | f9d78f2 | 2022-11-25 15:47:15 -0500 | [diff] [blame] | 360 | isChatShown, |
| 361 | setIsChatShown, |
simon | 2a5cf14 | 2022-11-25 15:47:35 -0500 | [diff] [blame] | 362 | isFullscreen, |
| 363 | setIsFullscreen, |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 364 | callRole, |
| 365 | callStatus, |
Gabriel Rochon | e382a30 | 2022-11-23 12:37:04 -0500 | [diff] [blame] | 366 | callStartTime, |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 367 | acceptCall, |
simon | accd802 | 2022-11-24 15:04:53 -0500 | [diff] [blame] | 368 | endCall, |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 369 | }} |
| 370 | > |
| 371 | {children} |
| 372 | </CallContext.Provider> |
| 373 | ); |
| 374 | }; |