1

Calling createAnswer doesn't change signalingState, it still in have-remote-offer. What may be the possible reason for this.

    offerSdp = { "sdp": offerSdp, "type": "offer" };

    pc.setRemoteDescription(new RTCSessionDescription(offerSdp)).then(() => {
        pc.createAnswer().then(answer => {
            //state still have-remote-offer
            pc.setLocalDescription(new RTCSessionDescription(answer)).then(() => {
                deferred.resolve(answer.sdp)
            });
        });
    });
Shashidhara
  • 665
  • 6
  • 22

1 Answers1

1

createOffer/createAnswer just create an offer/answer respectively (aka "description") and return them to you, to pass around. They do not affect signalingState.

setLocalDescription and setRemoteDescription do:

enter image description here

If you check the state after those methods have resolved, then you should see the state you expect.

Note that, as the chart shows, only certain state transitions are allowed. For instance, setLocalDecription may only be called with an answer in have-remote-offer state. Calling it with an offer will error.

jib
  • 40,579
  • 17
  • 100
  • 158
  • But i get this error while `pc.setLocalDescription` : Failed to execute 'setLocalDescription' on 'RTCPeerConnection': Failed to set local offer sdp: Called in wrong state: kHaveRemoteOffer – Shashidhara Feb 02 '19 at 15:55
  • @Shashidhara See the chart. `setLocalDecription` may only be called with an answer in that state. In your question you mention `createOffer` but in your example you have `createAnswer`, which is it? Please improve your question to include what you're asking about so we may answer it satisfactorily, or ask a new question. – jib Feb 02 '19 at 16:01
  • Sorry for my mistake. It is createAnswer. Code in question is the actual code used in my application. – Shashidhara Feb 02 '19 at 16:18
  • As i checked.. the state is proper. Still I get the previously mentioned error in comment. – Shashidhara Feb 03 '19 at 02:42
  • @Shashidhara by any chance are you on Chrome and using `onnegotiationneeded`? If so, try Firefox. You might be hitting a Chrome bug. See [this answer](https://stackoverflow.com/a/53035315/918910). – jib Feb 03 '19 at 05:48