webRTC on iOS: Can't send SDP answer, RTCPeerConnection.setRemoteDescription() failed

2,311 views
Skip to first unread message

Sasha Yakovlev

unread,
Jun 16, 2016, 10:16:34 AM6/16/16
to discuss-webrtc

I'm using libjingle_peerconnection installed with cocoapods. When I receive SDP offer through signaling server from my caller, I'm trying to set this as a remote description, which triggers RTCSessionDescriptionDelegate peerConnection:didSetSessionDescriptionWithError:with error: 

Error Domain=RTCSDPError Code=-1 "(null)" UserInfo={error=Failed to set remote answer sdp: Called in wrong state: STATE_INIT}

My code is:

- (void)transportChanell:(TransportChannel *)channel didReceivedSignalWithSessionDescription:(NSString *)sessionDescription withType:(NSString *)type {
    RTCSessionDescription *remoteDesc = [[RTCSessionDescription alloc] initWithType:@"answer" sdp:sessionDescription];
    [_peerConnection setRemoteDescriptionWithDelegate:self sessionDescription:remoteDesc];
}

I've investigated the problem quite a lot and found in webRTC source code the place, as I suppose, this error comes from BadRemoteSdp(type, BadStateErrMsg(state()), err_desc); and all possible states of WebRtcSession are:

    STATE_INIT = 0,
    STATE_SENTOFFER,         // Sent offer, waiting for answer.
    STATE_RECEIVEDOFFER,     // Received an offer. Need to send answer.
    STATE_SENTPRANSWER,      // Sent provisional answer. Need to send answer.
    STATE_RECEIVEDPRANSWER,  // Received provisional answer, waiting for answer.
    STATE_INPROGRESS,        // Offer/answer exchange completed.
    STATE_CLOSED,            // Close() was called.

Any suggestions, please, what could I missed in caller or callee side?

Taylor Brandstetter

unread,
Jun 16, 2016, 12:53:25 PM6/16/16
to discuss...@googlegroups.com
You said you're receiving an SDP offer, but you initialize the session description as an answer:
    RTCSessionDescription *remoteDesc = [[RTCSessionDescription alloc] initWithType:@"answer" sdp:sessionDescription];

--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/5fd2b6b8-98d9-4f58-a23d-d4001b5e51fb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ray Wang

unread,
Jun 16, 2016, 10:10:02 PM6/16/16
to discuss-webrtc
Read through these diagram:


在 2016年6月16日星期四 UTC+8下午10:16:34,Sasha Yakovlev写道:
Message has been deleted

Sasha Yakovlev

unread,
Jun 18, 2016, 5:25:43 AM6/18/16
to discuss-webrtc

Thanks for help, it seems I overcame an error and continue executing next steps and new problem occured on callee side. I'm working with this tutorial https://tech.appear.in/2015/05/25/Getting-started-with-WebRTC-on-iOS/ and want to build simple version of videochat, where caller makes call and streams himself to callee. Check my picture, please: 

 
1. I initialized session description as offer and set it as remoteDescription
2. My delegate is called, my peerConnection is in haveRemoteOffer state, so I create answer
3. I set this answer as localDescription and then nothing happened, my delegate is called again but I have wrong "stable" state and nothing happened and nothing of my if / else statements executed. 

In which step I've done a mistake? And I've noticed some ambiguity in this tutorial about this states in if / else, maybe it's wrong code? What state should I have after my step 3 to send answer then through signaling channel? 

Sasha Yakovlev

unread,
Jun 18, 2016, 5:30:07 AM6/18/16
to discuss-webrtc

Am I right that after step 3 I should have RTCSignalingHaveRemotePrAnswer state? And then I should send this SDP answer throught the signalling channel to my caller? 


Is this right version of code?

Ray Wang

unread,
Jun 24, 2016, 1:56:58 AM6/24/16
to discuss-webrtc, kid...@gmail.com
Hi, Sasha, the tutorial you're referring is not clear and has some mistakes.
You can take a look at my demo application for iOS here: 


在 2016年6月18日星期六 UTC+8下午5:30:07,Sasha Yakovlev写道:

dpimagine

unread,
Jul 13, 2016, 3:28:36 AM7/13/16
to discuss-webrtc
did you fix  this issue? I meet this issue too.


在 2016年6月16日星期四 UTC+8下午10:16:34,Sasha Yakovlev写道:

I'm using libjingle_peerconnection installed with cocoapods. When I receive SDP offer through signaling server from my caller, I'm trying to set this as a remote description, which triggers RTCSessionDescriptionDelegate peerConnection:didSetSessionDescriptionWithError:with error: 

Sasha Yakovlev

unread,
Jul 20, 2016, 4:19:14 AM7/20/16
to discuss-webrtc
I've fixed it, it was the wrong order in sending and receiveng messages from signaling server. This sample code was very helpful for me, you can check this implementation, it works. https://github.com/ISBX/apprtc-ios

houseoftechno...@gmail.com

unread,
Jan 5, 2018, 4:04:23 AM1/5/18
to discuss-webrtc
hello Ray Wang 
i am very thankful to you 
that you shared your work 
but there is a problem that in this app webrtc peers doesnot connect if you have mobile data connection instead of wifi connection
can you please help for that ? 
Reply all
Reply to author
Forward
0 new messages