Prompt
I'm building a React app with WebRTC calls; what API should I use?
Latest observation
Nov 2, 2026
OpenAI APIWeb search: off
For a React app with WebRTC calls, the core browser API you want is the WebRTC API — specifically:
RTCPeerConnection: establishes the peer-to-peer connectiongetUserMedia(): gets camera/microphone accessMediaStream/MediaStreamTrack: handles audio/video tracksRTCDataChannel: for real-time data, chat, file transfer, etc.
Typical architecture
You usually combine WebRTC with a backend for signaling:
- WebRTC handles the media connection
- Your server handles signaling (exchange of SDP offers/answers and ICE candidates)
Common signaling options:
- WebSocket
- Socket.IO
- Supabase Realtime
- Firebase Realtime Database / Firestore
- Any custom HTTP + WebSocket backend
In React
You’ll typically:
- use
useRef()to store the video elements and peer connection - use
useEffect()to set up/tear down media and peer connections - manage streams in state only if needed; keep actual
MediaStreamobjects in refs most of the time
Minimal example APIs
const stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true });
const pc = new RTCPeerConnection();
stream.getTracks().forEach(track => pc.addTrack(track, stream));
If you want a library
Instead of working directly with raw WebRTC, you can use:
- simple-peer (simpler wrapper around WebRTC)
- PeerJS
- mediasoup or LiveKit for more advanced multi-party/production setups
If you want, I can show you:
- a basic React + WebRTC example, or
- the best signaling approach for your app.