Created
May 11, 2019 01:28
-
-
Save quangtqag/b528203b1d0bb8e011a1a6908336e120 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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