我正在尝试使用swift中的WebRTC框架编写本机iOS应用程序。我遇到了一个问题,因为看起来RTCSessionDescriptonDelegate已被弃用,我不能再真正遵循这个tutorial。
我想我已经走得很远但是阻碍我的主要原因是我不明白如何创建一个sdp参数。 RTCSessionDescription(类型:.offer,sdp:)
如果有人可以提供建议我会非常感激。
答案 0 :(得分:0)
Swift 3.0
这是我创建SDP的解决方案。
let constraints: RTCMediaConstraints? = defaultPeerConnectionConstraints()
peerConnection: RTCPeerCo = factory?.peerConnection(withICEServers: iceServers, constraints: constraints, delegate: self)
let localStream: RTCMediaStream? = createLocalMediaStream() //get Media stream(video/audio)
peerConnection?.add(localStream)
//create offer for other opponent
if isInitiator {
peerConnection?.createOffer(with: self, constraints: defaultOfferConstraints())
print("create Offer")
}
在ICE服务器上
func defaultICEServer() -> [RTCICEServer] {
var iceServers = [RTCICEServer]()
let defaultSTUNServerURL = URL(string: Config.defaultSTUNServerUrl)
let defaultTURNServerURL = URL(string: Config.defaultTURNServerUrl)
let stunServ = RTCICEServer(uri: defaultSTUNServerURL, username: "", password: "")
let turnServ = RTCICEServer(uri: defaultTURNServerURL, username: "admin", password: "admin")
iceServers.append(stunServ!)
iceServers.append(turnServ!)
return iceServers
}
和
func defaultPeerConnectionConstraints() -> RTCMediaConstraints {
let optionalConstraints: [Any] = [RTCPair(key: "DtlsSrtpKeyAgreement", value: "true")]
let constraints = RTCMediaConstraints(mandatoryConstraints: nil, optionalConstraints: optionalConstraints)
return constraints!
}
然后是呼叫代表
func peerConnection(_ peerConnection: RTCPeerConnection, didCreateSessionDescription sdp: RTCSessionDescription, error: Error?) {}
您可以使用sdp
发送其他用户。您应该将此sdp
设置为localDescription
以获得正确的工作。
peerConnection?.setLocalDescriptionWith(self, sessionDescription: sdp)
我希望,我可以帮助