RTCPeerConnection setting offer sdp does not match the previously generated SDP for this type

116 views
Skip to first unread message

Shushant Arora

unread,
Apr 3, 2020, 3:11:59 AM4/3/20
to discuss-webrtc
Hi

I have received answer sdp by negotiating offer sdp from peer in different process, Now I Pass answer sdp and offer sdp to separate process and invoke below flow.


var offer_ssdp_string = 'actual offer string'
var answer_sdp_string = 'actual answer string' 
 peerConnection = new RTCPeerConnection(servers);
peerConnection.setLocalDescription(new RTCSessionDescription({ "type": "offer", "sdp": offer_sdp }))
peerConnection.setRemoteDescription(new RTCSessionDescription({ "type": "answer", "sdp": answer_sdp }))


I am getting below errors
 (Uncaught (in promise) DOMException: The SDP does not match the previously generated SDP for this type)
Failed to create session description: InvalidStateError: Failed to execute 'setRemoteDescription' on 'RTCPeerConnection': Failed to set remote answer sdp: Called in wrong state: kStable.

When I recreate offer in another process and then set answer sdp I get error as "Failed to create session description: InvalidAccessError: Failed to execute 'setRemoteDescription' on 'RTCPeerConnection': Failed to set remote answer sdp: The order of m-lines in answer doesn't match order in offer. Rejecting answer.."

peerConnection.createOffer(function(offer) {
     peerConnection.setLocalDescription(offer);
      peerConnection.setRemoteDescription({ "type": "answer", "sdp": answer_sdp })
       
    },
    function(error) {
      trace('setStatus(\'CreateOffer failed!\');')
    });  


Whats the issue in this code flow?

Thanks

Jehanzaib Younis

unread,
Mar 29, 2022, 2:59:08 AMMar 29
to discuss-webrtc
Hi there,
Did you find out the solution for "Failed to execute 'setRemoteDescription' on 'RTCPeerConnection': Failed to set remote answer sdp: The order of m-lines in answer doesn't match order in offer. Rejecting answer" ?

Thank you

Message has been deleted

Martynas Padarauskas

unread,
Apr 22, 2022, 4:10:04 PMApr 22
to discuss-webrtc
Hey, 
  • I believe the first error is because you can't break the flow of a new RTCPeerConnections (create offer -> set local -> set remote -> create answer -> set local -> set remote). If you create offer on one side, answer on the other and only then set the local/remote descriptions it should break by design. 
  • Now the second error is a bit more interesting. In my experience this happens if your offer/answer m-lines differ meaning you have more audio/video track devices than you had previously. For further reading try keywords: unified-plan, plan-b. In my case I just stopped using addTracks() and moved to the newer addTransceiver API which fixed the m-lines issue, since know I always have two tracks whether it is chrome, safari, firefox, an old connection, a new connection, doesn't matter.
see if this helps. 
Reply all
Reply to author
Forward
0 new messages