WebRTC setLocalDescription from answer resets signalingState

Viewed 78

I am attempting a simple example of two users connected with webrtc using a data channel. The problem I am having is after the offer step. The second client that joins my socket.io room, I have send an offer and sets its local description.

const offer = await peerConnection.createOffer();
await peerConnection.setLocalDescription(offer)

//send offer to signal server to forward to peer
socket.emit("webrtc_offer", {
  roomId: roomId,
  sdp: peerConnection.localDescription,
});

Then when I receive the offer I try this...

  if (!offerSender) {
    await peerConnection.setRemoteDescription(offer);
    const answer = await peerConnection.createAnswer();
    
    //This sets the signalingState to stable instead of have-local-pranswer
    await peerConnection.setLocalDescription(answer);
    console.log("sending answer to peer");
    socket.emit("webrtc_answer", {
      roomId: roomId,
      sdp: peerConnection.localDescription,
    });
  }

Once I try to set the local description from the answer I create, my signalState is reset to Stable instead of have-local-pranswer. Could someone explain why that is? This then breaks the next step of trying to respond to the answer to finish the connection.

0 Answers
Related