-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathApp.tsx
More file actions
52 lines (50 loc) · 1.51 KB
/
App.tsx
File metadata and controls
52 lines (50 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { useRef, useState } from "react"
import IncomingView from "src/IncomingView"
import JoinView from "src/JoinView"
import MeetingView from "src/MeetingView"
import OutgoingView from "src/OutgoingView"
import { useWebRTC } from "src/useWebRTC"
const App = () => {
const localClientId = useRef(Math.floor(100000 + Math.random() * 900000).toString())
const [remoteClientId, setRemoteClientId] = useState("")
const {
callState,
localStream,
remoteStream,
makeCall,
acceptCall,
endCall,
isMicEnabled,
isCameraEnabled,
isFrontCamera,
toggleMute,
toggleCamera,
toggleCameraMode,
} = useWebRTC(localClientId.current, setRemoteClientId)
return callState === "idle" ? (
<JoinView
localClientId={localClientId.current}
onCall={(remoteClientIdArg) => {
setRemoteClientId(remoteClientIdArg)
makeCall(remoteClientIdArg)
}}
/>
) : callState === "incoming" ? (
<IncomingView remoteClientId={remoteClientId} onAnswer={acceptCall} />
) : callState === "outgoing" ? (
<OutgoingView remoteClientId={remoteClientId} onCancel={() => null} />
) : callState === "connected" ? (
<MeetingView
localStream={localStream.current}
remoteStream={remoteStream.current}
onLeave={endCall}
isCameraOn={isCameraEnabled}
isMuted={!isMicEnabled}
onSwitchCamera={toggleCameraMode}
onToggleCamera={toggleCamera}
onToggleMic={toggleMute}
isFrontCamera={isFrontCamera}
/>
) : null
}
export default App