iOS上的webRTC:无法发送SDP答案,RTCPeerConnection.setRemoteDescription()失败

时间:2016-06-16 11:49:48

标签: ios webrtc sdp libjingle

我正在使用cocoapods安装libjingle_peerconnection。当我通过来自我的呼叫者的信令服务器收到SDP提议时,我试图将其设置为远程描述,触发RTCSessionDescriptionDelegate peerConnection:didSetSessionDescriptionWithError: 有错误:

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

我的代码是:

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

我已经对这个问题进行了大量调查,并在webRTC源代码中找到了这个地方,正如我想的那样,这个错误来自BadRemoteSdp(type, BadStateErrMsg(state()), err_desc);WebRtcSession的所有可能状态都是:

    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.

请问有什么建议,我可以在来电或被叫方方面错过什么?

2 个答案:

答案 0 :(得分:2)

根据错误消息,该优惠似乎被标记为“答案”。它失败了,因为它希望你处于STATE_SENTOFFER状态。

如果您已创建优惠并将其发送给另一方,则可能忘记先调用setLocalDescription。如果您未向失败的客户发送要约,则应更改另一方以发送要约而非回复。

答案 1 :(得分:0)

这可以帮助任何来自Google的人

我自己遇到了这个问题,结果我匆匆从我写的要约中复制粘贴了一些代码。因此,我正在使用类型1而不是RTCSessionDescription来初始化RTCSdpTypeAnswer

确保在分配RTCSdpTypeOffer时使用的类型正确!