2

I have a problem when I can't create an answer but the connection state is already have-remote-offer.

Code:

pc.ontrack = function(evt) {

  // signaling state is have-remote-offer
  logEvent('REMOTE', 'signalingstate', pc.signalingState);

  pc.createAnswer() // error here
    .then((answer) => {
       localConnection.setLocalDescription(answer);
       logEvent('REMOTE', 'signalingstate', pc.signalingState);

       socket.emit('session_description', JSON.stringify({ desc: answer.toJSON() }));
  });
};

Error:

Uncaught (in promise) DOMException: Peer Connection cannot create an answer in a state other than have-remote-offer or have-local-pranswer

Any ideas?

Joseph D.
  • 11,804
  • 3
  • 34
  • 67

1 Answers1

4

calling createAnswer from ontrack is not going to work typically. You'll want to call it from the setRemoteDescription .then()

Philipp Hancke
  • 15,855
  • 2
  • 23
  • 31