【问题标题】:webRTC on iOS: Can't send SDP answer, RTCPeerConnection.setRemoteDescription() failediOS 上的 webRTC:无法发送 SDP 应答,RTCPeerConnection.setRemoteDescription() 失败
【发布时间】:2016-10-17 22:06:48
【问题描述】:

我正在使用与 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.

任何建议,拜托,我在呼叫者或被呼叫者方面错过了什么?

【问题讨论】:

    标签: ios webrtc sdp libjingle


    【解决方案1】:

    根据错误消息,报价似乎被标记为“答案”。它失败了,因为它期望您处于 STATE_SENTOFFER 状态。

    如果您已经创建了一个报价并将其发送给对方,您可能忘记了先调用 setLocalDescription。如果您没有从失败的客户端发送报价,则应将另一方更改为发送报价而不是答复。

    【讨论】:

    • 我希望我描述清楚:当我收到来自呼叫者的报价时,问题出在被呼叫者方面。如果我只想在被调用方看到调用者的流而不是将被调用者流回调用者,我该怎么办?被调用者是否也应该创建报价,或者我应该只对已经收到的报价发送一个答案(这就是我现在正在尝试的)。
    • 如果我忘记打电话给setLocalDescription — 我无法获得通过信令服务器发送它的 SDP 提议,我成功地做到了。但正如我已经说过的,我只在调用方生成报价,并希望从被调用方那里得到答案,这是失败的。我做错了,被调用方也应该先生成报价吗?
    【解决方案2】:

    如果这可以帮助任何从 Google 来到这里的人:

    我自己也遇到了这个问题,结果我匆忙复制粘贴了一些我写的提议者的代码。所以我用RTCSdpTypeAnswer而不是RTCSdpTypeOffer来初始化RTCSessionDescription

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-19
      • 2019-08-18
      • 2018-05-24
      • 2023-03-13
      相关资源
      最近更新 更多