gpt4 book ai didi

ios - RTCICEConnectionFailed swift

转载 作者:搜寻专家 更新时间:2023-11-01 06:50:45 25 4
gpt4 key购买 nike

我正在尝试使用 WebRTC 实现音频通话。我拥有的 pod 是:

pod 'Starscream', '~> 2.0.4'
pod 'libjingle_peerconnection'

当我尝试发送收到的 SDP 作为答复时,它失败了。我在这里提供选定的代码行,因为它太长了。

  1. 连接套接字

    self.socket?.connect()
  2. 当套接字获得连接状态时,初始化WebRTC

    func initalizeWebRTC() -> Void {
    print("----------------initalizeWebRTC----------------")

    RTCPeerConnectionFactory.initializeSSL()
    self.webRtcClient = RTCPeerConnectionFactory.init()
    let stunServer = self.defaultStunServer()
    let defaultConstraint = self.createDefaultConstraint()
    self.peerConnection = self.webRtcClient?.peerConnection(withICEServers: [stunServer], constraints: defaultConstraint, delegate: self)

    self.localVideoView.delegate = self
    self.remoteVideoView.delegate = self
    // webrtc initalized local rendering of video on
    self.addLocalMediaStrem()

    }
  3. 这是我的配置

    func defaultStunServer() -> RTCICEServer {
    print("----------------defaultStunServer----------------")
    let url = URL.init(string: stunServer);
    let iceServer = RTCICEServer.init(uri: url, username: "", password: "")
    return iceServer!
    }

    func createAudioVideoConstraints() -> RTCMediaConstraints{
    print("----------------createAudioVideoConstraints----------------")
    let audioOffer : RTCPair = RTCPair(key: "OfferToReceiveAudio", value: "true")
    let videoOffer : RTCPair = RTCPair(key: "OfferToReceiveVideo", value: "false")
    let dtlsSrtpKeyAgreement : RTCPair = RTCPair(key: "DtlsSrtpKeyAgreement", value: "true")

    let connectConstraints : RTCMediaConstraints = RTCMediaConstraints.init(mandatoryConstraints: [audioOffer,videoOffer], optionalConstraints: [dtlsSrtpKeyAgreement])

    return connectConstraints
    }

    func createDefaultConstraint() -> RTCMediaConstraints {
    print("----------------createDefaultConstraint----------------")
    let dtlsSrtpKeyAgreement : RTCPair = RTCPair(key: "DtlsSrtpKeyAgreement", value: "true")
    let connectConstraints : RTCMediaConstraints = RTCMediaConstraints.init(mandatoryConstraints: nil, optionalConstraints: [dtlsSrtpKeyAgreement])

    return connectConstraints
    }
  4. 使用 WebRTC 创建报价

    self.peerConnection?.createOffer(with: self, constraints: constraint)
  5. 向套接字写入数据

    let offerDict =  ["id":"joinRoomPresenter","name":fileName,"roomName":fileName,"isFrontCamera":"false","isMicroPhone":"false","isPhoneAudio":"false","isChat":"false","isOneToOneSession":"false","accessToken":"9289010e-d2d5-42e8-a95c-212f06aa9238","userId":"3459","fileName":fileName,"portalId":voiceCallID,"personName":fileName,"photoURL":"","sdpOffer":sdp.description] as [String : Any]
    socket?.write(string: offerDict.json)
  6. 成功后,我从 socket 收到了 sip 作为消息。

["sdpAnswer": v=0

o=- 544328641767753251 2 IN IP4 104.248.181.233

s=VideoRoom 2623889018315199

t=0 0

a=group:BUNDLE audio

a=msid-semantic: WMS janus

m=audio 9 UDP/TLS/RTP/SAVPF 111

c=IN IP4 104.248.181.233

a=recvonly

a=mid:audio

a=rtcp-mux

a=ice-ufrag:SJ8U

a=ice-pwd:72CaTpbKHUzwWj7rX64cGn

a=ice-options:trickle

a=fingerprint:sha-256 13:2A:57:AA:FC:AE:2B:44:86:1A:FD:FD:77:4A:11:BD:78:60:A3:4E:D1:98:3C:43:1C:71:82:C7:88:EE:01:CC

a=setup:active

a=rtpmap:111 opus/48000/2

a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level

a=msid:janus janusa0

a=ssrc:1319411670 cname:janus

a=ssrc:1319411670 msid:janus janusa0

a=ssrc:1319411670 mslabel:janus

a=ssrc:1319411670 label:janusa0

a=candidate:1 1 udp 2013266431 104.248.181.233 57307 typ host

a=candidate:2 1 udp 2013266430 10.46.0.9 56250 typ host

a=end-of-candidates

, "id": joinRoomPresenterResponse, "response": accepted]

  1. 我发送相同的 sdp 作为答复

    self.peerConnection?.setRemoteDescriptionWith(self, sessionDescription: rtcSessionDesc!)
  2. 我将 iceGathering 状态更改为 2(收集)。但几秒钟后,iceConnection 状态更改为 4(失败)

我哪里错了?

最佳答案

对于初学者来说,libjingle 已经很老了(2016 年)。我会尝试使用 GoogleWebRTC pod,它会不断从他们的存储库中更新。

在套接字发送中你有 "isMicroPhone":"false","isPhoneAudio":"false"如果是声音,那不应该是真的吗?

我会尝试 Google 的主要示例应用程序,然后从那里开始。有时很难通过 webrtc 连接正确执行所有步骤。

关于ios - RTCICEConnectionFailed swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57460077/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com