Reputation: 1389
I am working with webRTC and wrtc on the server. My client side code is :
React.useEffect(() => {
(async () => {
pc = new RTCPeerConnection()
const offer = await pc.createOffer()
await pc.setLocalDescription(offer)
const { data } = await axios.post('http://localhost:3000/testing', { sdp: pc.localDescription })
await pc.setRemoteDescription(data.sdp)
})()
setInterval(() => {
console.log(pc.connectionState)
}, 2222);
}, []);
And the server side is :
server.post('/testing', async function (req, res) {
const { sdp } = req.body
const pc = new webrtc.RTCPeerConnection()
await pc.setRemoteDescription(sdp)
const answer = await pc.createAnswer()
await pc.setLocalDescription(answer)
res.status(200).json({ sdp: pc.localDescription })
})
pc.connectionState
indicates new
and apparently I am not connected. Where is my mistake?
Upvotes: 1
Views: 540
Reputation: 17285
You are not adding any tracks or a datachannel hence your SDP contains no m= sections, no ice candidates are gathered and nothing useful happens.
Upvotes: 1