I am
building a multi-party video call app using Cloudflare Calls SFU for WebRTC media routing and Socket.IO for signaling.
I ran into two issues:
1. `navigator.mediaDevices.getUserMedia` throws an OverconstrainedError on desktop Brave when using `facingMode: 'user'`.
2. When two users join the same room, `socket.io` exchanges `sessionId` and `trackName` arrays, but remote streams either get dropped in `pc.ontrack` or fail to re-render in React `<video>` elements.
#### 1. Backend Track Pulling Endpoint (`server.js`):
app.post('/api/session/:sessionId/pull', async (req, res) => { const { sessionId } = req.params;
const { tracks, sdp } = req.body; // tracks: [{ location: 'remote', sessionId, trackName, mid }]
headers: { 'Authorization': `Bearer ${API_TOKEN}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ sessionDescription: { type: 'offer', sdp }, tracks })
const data = await pullResp.json();
res.status(200).json(data);
#### 2. Frontend Track Pulling & Stream Binding (`RoomPage.tsx`):
const transceiver = pc.addTransceiver('video', { direction: 'recvonly' });
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);
const pullResp = await fetch(`/api/session/${currentSessionId}/pull`, {
tracks: [{ location: 'remote', sessionId: remoteSessionId, trackName, mid: transceiver.mid }],
sdp: pc.localDescription?.sdp
const data = await pullResp.json();
await pc.setRemoteDescription(new RTCSessionDescription({ type: 'answer', sdp: data.sessionDescription.sdp }));
1. What are the best practices for setting `getUserMedia` constraints to ensure desktop/Brave compatibility?
2. How should transceiver `mid` mappings be tracked when pulling remote tracks via Cloudflare Calls?
3. How can we ensure immutable state updates in React so incoming `RTCTrackEvent` streams properly trigger video element re-renders?
This is so humiliating i don't understand what I am doing wrong with AI doing WebRTC so anyone could help me here??