Prompt
How do I set up 1:1 video calls in a web app?
Latest observation
Nov 2, 2026
OpenAI APIWeb search: off
To set up 1:1 video calls in a web app, you typically use WebRTC for the media connection and a signaling server to help two browsers find each other and exchange connection info.
High-level pieces
-
Frontend app
- Gets camera/mic access
- Creates the WebRTC connection
- Shows local and remote video
-
Signaling server
- Not part of WebRTC itself
- Usually uses WebSocket, Socket.IO, or similar
- Exchanges:
- SDP offer/answer
- ICE candidates
- Call state events (join, accept, hang up)
-
STUN/TURN servers
- STUN helps peers discover their public network addresses
- TURN relays media if direct peer-to-peer fails, which is important for real-world reliability
Typical call flow
1. Get media
Use getUserMedia() to access camera and microphone.
const localStream = await navigator.mediaDevices.getUserMedia({
video: true,
audio: true
});
localVideo.srcObject = localStream;
2. Create RTCPeerConnection
Configure STUN/TURN servers.
const pc = new RTCPeerConnection({
iceServers: [
{ urls: "stun:stun.l.google.com:19302" },
// For production:
// { urls: "turn:turn.example.com:3478", username: "user", credential: "pass" }
]
});
3. Add local tracks
localStream.getTracks().forEach(track => pc.addTrack(track, localStream));
4. Exchange signaling data
You need a server to send messages between the two users:
- Caller creates an offer
- Callee receives it and creates an answer
- Both sides exchange ICE candidates
5. Attach remote stream
pc.ontrack = (event) => {
remoteVideo.srcObject = event.streams[0];
};
Minimal example structure
Caller side
const localStream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true });
localVideo.srcObject = localStream;
const pc = new RTCPeerConnection({
iceServers: [{ urls: "stun:stun.l.google.com:19302" }]
});
localStream.getTracks().forEach(track => pc.addTrack(track, localStream));
pc.ontrack = (e) => {
remoteVideo.srcObject = e.streams[0];
};
pc.onicecandidate = (e) => {
if (e.candidate) signalingSocket.send(JSON.stringify({
type: "ice-candidate",
candidate: e.candidate
}));
};
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);
signalingSocket.send(JSON.stringify({
type: "offer",
sdp: offer
}));
Callee side
const localStream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true });
localVideo.srcObject = localStream;
const pc = new RTCPeerConnection({
iceServers: [{ urls: "stun:stun.l.google.com:19302" }]
});
localStream.getTracks().forEach(track => pc.addTrack(track, localStream));
pc.ontrack = (e) => {
remoteVideo.srcObject = e.streams[0];
};
pc.onicecandidate = (e) => {
if (e.candidate) signalingSocket.send(JSON.stringify({
type: "ice-candidate",
candidate: e.candidate
}));
};
signalingSocket.onmessage = async (msg) => {
const data = JSON.parse(msg.data);
if (data.type === "offer") {
await pc.setRemoteDescription(data.sdp);
const answer = await pc.createAnswer();
await pc.setLocalDescription(answer);
signalingSocket.send(JSON.stringify({
type: "answer",
sdp: answer
}));
}
if (data.type === "ice-candidate") {
await pc.addIceCandidate(data.candidate);
}
};
Signaling server example idea
Using WebSocket/Socket.IO, you can route messages by room or user ID:
- User A joins room
call-123 - User B joins room
call-123 - Server forwards
offer,answer, andice-candidatemessages between them
This server does not handle video itself; only coordination.
Important production considerations
1. Use TURN for reliability
Many users are behind NATs/firewalls. Without TURN, some calls won’t connect.
2. Secure everything
- Use HTTPS
- Use WSS for signaling
- Authenticate users before allowing calls
3. Handle lifecycle
- Mute/unmute
- Camera on/off
- Hang up
- Reconnect if network changes
- Clean up tracks and peer connections
4. Mobile/browser quirks
- Safari and mobile browsers can behave differently
- Test autoplay policies and permissions
5. Scaling
For pure 1:1 calls, WebRTC peer-to-peer is usually enough. If you later need group calls or recording, you may want an SFU.
Recommended stack
A common setup:
- Frontend: React/Vue/Next.js
- Signaling: Node.js + Socket.IO
- Media: WebRTC
- NAT traversal: STUN + TURN (e.g. coturn)
Best way to start
- Build a simple two-page demo
- Add WebSocket signaling
- Connect two tabs/devices
- Add TURN server
- Add call UI and cleanup logic
If you want, I can give you:
- a complete working example with frontend + Node.js signaling server, or
- a React version of a 1:1 video call app.