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
static func updateUser(id: Double, name: String, completionHandler: @escaping (_ userID: Double?, _ error: Error?) -> Void) { | |
let endpointUrl = URL(string: host + updateUserPath)! | |
var urlRequest = URLRequest(url: endpointUrl) | |
urlRequest.httpMethod = "PUT" | |
let userDict: [String: Any] = ["id": id, "name": name] | |
let userData = try! JSONSerialization.data(withJSONObject: userDict, options: []) | |
urlRequest.httpBody = userData | |
let task = URLSession.shared.dataTask(with: urlRequest) { (data, response, error) in |
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
static func addUser(name: String, completionHandler: @escaping (_ userID: Double?, _ error: Error?) -> Void) { | |
let endpointUrl = URL(string: host + addUserPath)! | |
var urlRequest = URLRequest(url: endpointUrl) | |
urlRequest.httpMethod = "POST" | |
let newUser: [String: Any] = ["name": name] | |
let jsonUser = try! JSONSerialization.data(withJSONObject: newUser, options: []) | |
urlRequest.httpBody = jsonUser | |
let task = URLSession.shared.dataTask(with: urlRequest) { (data, response, error) in |
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
static func deleteUser(id: Double, comletionHandler: @escaping (_ error: Error?) -> Void) { | |
let endpointUrl = URL(string: String(format: host + deleteUserPath, id))! | |
var urlRequest = URLRequest(url: endpointUrl) | |
urlRequest.httpMethod = "DELETE" | |
let task = URLSession.shared.dataTask(with: urlRequest) { (data, response, error) in | |
guard error == nil else { | |
print("error calling DELETE on \(deleteUserPath): \(error!)") | |
DispatchQueue.main.async { | |
comletionHandler(error) |
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
static func getUsers(completionHandler: @escaping (_ users: [User]?, _ error: Error?) -> Void) { | |
let endpointUrl = URL(string: host + listUsersPath)! | |
let urlRequest = URLRequest(url: endpointUrl) | |
let task = URLSession.shared.dataTask(with: urlRequest) { (data, response, error) in | |
guard error == nil else { | |
print("error calling GET on \(listUsersPath): \(error!)") | |
DispatchQueue.main.async { | |
completionHandler(nil, error) | |
} | |
return |
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
@IBAction func endCall(_ sender: Any) { | |
self.signalClient.deleteSdpAndCandidate(for: self.currentPerson) | |
self.webRTCClient.closePeerConnection() | |
self.webRTCClient.createPeerConnection() | |
self.hasLocalSdp = false | |
self.localCandidateCount = 0 | |
self.hasRemoteSdp = false | |
self.remoteCandidateCount = 0 | |
} |
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 answer(completion: @escaping (_ sdp: RTCSessionDescription) -> Void) { | |
let constrains = RTCMediaConstraints(mandatoryConstraints: self.mediaConstrains, | |
optionalConstraints: nil) | |
self.peerConnection!.answer(for: constrains) { (sdp, error) in | |
guard let sdp = sdp else { | |
return | |
} | |
self.peerConnection!.setLocalDescription(sdp, completionHandler: { (error) in | |
completion(sdp) |
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 listenSdp(from person: String) { | |
Firestore.firestore().collection(person).document("sdp") | |
.addSnapshotListener { documentSnapshot, error in | |
guard let document = documentSnapshot else { | |
print("Error fetching sdp: \(error!)") | |
return | |
} | |
guard let data = document.data() else { | |
print("Firestore sdp data was empty.") | |
return |
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 send(candidate rtcIceCandidate: RTCIceCandidate, to person: String) { | |
do { | |
let dataMessage = try self.encoder.encode(IceCandidate(from: rtcIceCandidate)) | |
let dict = try JSONSerialization.jsonObject(with: dataMessage, options: .allowFragments) as! [String: Any] | |
Firestore.firestore() | |
.collection(person) | |
.document("candidate") | |
.collection("candidates") | |
.addDocument(data: dict) { (err) in | |
if let err = err { |
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 |
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
private func createMediaSenders() { | |
let streamId = "stream" | |
// Audio | |
let audioTrack = self.createAudioTrack() | |
self.peerConnection!.add(audioTrack, streamIds: [streamId]) | |
// Video | |
let videoTrack = self.createVideoTrack() | |
self.localVideoTrack = videoTrack |
NewerOlder