Skip to content

Instantly share code, notes, and snippets.

@quangtqag
Created May 11, 2019 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quangtqag/b528203b1d0bb8e011a1a6908336e120 to your computer and use it in GitHub Desktop.
Save quangtqag/b528203b1d0bb8e011a1a6908336e120 to your computer and use it in GitHub Desktop.
func offer(completion: @escaping (_ sdp: RTCSessionDescription) -> Void) {
let constrains = RTCMediaConstraints(
mandatoryConstraints: self.mediaConstrains,
optionalConstraints: nil)
self.peerConnection!.offer(for: constrains) { (sdp, error) in
guard let sdp = sdp else {
return
}
self.peerConnection!.setLocalDescription(sdp, completionHandler: { (error) in
completion(sdp)
})
}
}
func send(sdp rtcSdp: RTCSessionDescription, to person: String) {
do {
let dataMessage = try self.encoder.encode(SessionDescription(from: rtcSdp))
let dict = try JSONSerialization.jsonObject(with: dataMessage, options: .allowFragments) as! [String: Any]
Firestore.firestore().collection(person).document("sdp").setData(dict) { (err) in
if let err = err {
print("Error send sdp: \(err)")
} else {
print("Sdp sent!")
}
}
}
catch {
debugPrint("Warning: Could not encode sdp: \(error)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment