From 02d049961891aea8a94d567252d21a906fcdbdea Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Fri, 12 Nov 2021 09:17:06 +1100 Subject: [PATCH] seperate CallKit uuid from session call id --- Session/Calls/Call Management/SessionCall.swift | 6 ++++-- .../SessionCallManager+CXCallController.swift | 8 ++++---- Session/Calls/Call Management/SessionCallManager.swift | 10 +++++----- Session/Meta/AppDelegate.swift | 4 ++-- SessionMessagingKit/Calls/WebRTCSession.swift | 3 ++- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Session/Calls/Call Management/SessionCall.swift b/Session/Calls/Call Management/SessionCall.swift index 8fdc34f97..fd089fe76 100644 --- a/Session/Calls/Call Management/SessionCall.swift +++ b/Session/Calls/Call Management/SessionCall.swift @@ -6,7 +6,8 @@ import CallKit public final class SessionCall: NSObject, WebRTCSessionDelegate { // MARK: Metadata Properties - let uuid: UUID + let uuid: String + let callID: UUID // This is for CallKit let sessionID: String let mode: Mode let webRTCSession: WebRTCSession @@ -137,7 +138,8 @@ public final class SessionCall: NSObject, WebRTCSessionDelegate { // MARK: Initialization init(for sessionID: String, uuid: String, mode: Mode, outgoing: Bool = false) { self.sessionID = sessionID - self.uuid = UUID(uuidString: uuid)! + self.uuid = uuid + self.callID = UUID() self.mode = mode self.webRTCSession = WebRTCSession.current ?? WebRTCSession(for: sessionID, with: uuid) self.isOutgoing = outgoing diff --git a/Session/Calls/Call Management/SessionCallManager+CXCallController.swift b/Session/Calls/Call Management/SessionCallManager+CXCallController.swift index 94a3e6b04..4b83f2295 100644 --- a/Session/Calls/Call Management/SessionCallManager+CXCallController.swift +++ b/Session/Calls/Call Management/SessionCallManager+CXCallController.swift @@ -6,7 +6,7 @@ extension SessionCallManager { guard case .offer = call.mode else { return } guard !call.hasConnected else { return } let handle = CXHandle(type: .generic, value: call.sessionID) - let startCallAction = CXStartCallAction(call: call.uuid, handle: handle) + let startCallAction = CXStartCallAction(call: call.callID, handle: handle) startCallAction.isVideo = false @@ -18,7 +18,7 @@ extension SessionCallManager { } public func answerCall(_ call: SessionCall, completion: ((Error?) -> Void)?) { - let answerCallAction = CXAnswerCallAction(call: call.uuid) + let answerCallAction = CXAnswerCallAction(call: call.callID) let transaction = CXTransaction() transaction.addAction(answerCallAction) @@ -26,7 +26,7 @@ extension SessionCallManager { } public func endCall(_ call: SessionCall, completion: ((Error?) -> Void)?) { - let endCallAction = CXEndCallAction(call: call.uuid) + let endCallAction = CXEndCallAction(call: call.callID) let transaction = CXTransaction() transaction.addAction(endCallAction) @@ -35,7 +35,7 @@ extension SessionCallManager { // Not currently in use public func setOnHoldStatus(for call: SessionCall) { - let setHeldCallAction = CXSetHeldCallAction(call: call.uuid, onHold: true) + let setHeldCallAction = CXSetHeldCallAction(call: call.callID, onHold: true) let transaction = CXTransaction() transaction.addAction(setHeldCallAction) diff --git a/Session/Calls/Call Management/SessionCallManager.swift b/Session/Calls/Call Management/SessionCallManager.swift index af6a19e3a..75006ab16 100644 --- a/Session/Calls/Call Management/SessionCallManager.swift +++ b/Session/Calls/Call Management/SessionCallManager.swift @@ -63,10 +63,10 @@ public final class SessionCallManager: NSObject { AssertIsOnMainThread() call.stateDidChange = { if call.hasStartedConnecting { - self.provider.reportOutgoingCall(with: call.uuid, startedConnectingAt: call.connectingDate) + self.provider.reportOutgoingCall(with: call.callID, startedConnectingAt: call.connectingDate) } if call.hasConnected { - self.provider.reportOutgoingCall(with: call.uuid, connectedAt: call.connectedDate) + self.provider.reportOutgoingCall(with: call.callID, connectedAt: call.connectedDate) } } callTimeOutTimer = Timer.scheduledTimer(withTimeInterval: 60, repeats: false) { _ in @@ -84,7 +84,7 @@ public final class SessionCallManager: NSObject { // Construct a CXCallUpdate describing the incoming call, including the caller. let update = CXCallUpdate() update.localizedCallerName = callerName - update.remoteHandle = CXHandle(type: .generic, value: call.uuid.uuidString) + update.remoteHandle = CXHandle(type: .generic, value: call.callID.uuidString) update.hasVideo = false update.supportsGrouping = false update.supportsUngrouping = false @@ -93,7 +93,7 @@ public final class SessionCallManager: NSObject { disableUnsupportedFeatures(callUpdate: update) // Report the incoming call to the system - self.provider.reportNewIncomingCall(with: call.uuid, update: update) { error in + self.provider.reportNewIncomingCall(with: call.callID, update: update) { error in guard error == nil else { self.currentCall = nil completion(error) @@ -107,7 +107,7 @@ public final class SessionCallManager: NSObject { public func reportCurrentCallEnded(reason: CXCallEndedReason?) { guard let call = currentCall else { return } if let reason = reason { - self.provider.reportCall(with: call.uuid, endedAt: nil, reason: reason) + self.provider.reportCall(with: call.callID, endedAt: nil, reason: reason) if reason == .unanswered { call.updateCallMessage(mode: .unanswered) } else { diff --git a/Session/Meta/AppDelegate.swift b/Session/Meta/AppDelegate.swift index 972b5e5a9..e7a7dd2f1 100644 --- a/Session/Meta/AppDelegate.swift +++ b/Session/Meta/AppDelegate.swift @@ -57,7 +57,7 @@ extension AppDelegate { // Offer messages MessageReceiver.handleOfferCallMessage = { message in DispatchQueue.main.async { - guard let call = AppEnvironment.shared.callManager.currentCall, message.uuid == call.uuid.uuidString else { return } + guard let call = AppEnvironment.shared.callManager.currentCall, message.uuid! == call.uuid else { return } let sdp = RTCSessionDescription(type: .offer, sdp: message.sdps![0]) call.didReceiveRemoteSDP(sdp: sdp) } @@ -65,7 +65,7 @@ extension AppDelegate { // Answer messages MessageReceiver.handleAnswerCallMessage = { message in DispatchQueue.main.async { - guard let call = AppEnvironment.shared.callManager.currentCall, message.uuid == call.uuid.uuidString else { return } + guard let call = AppEnvironment.shared.callManager.currentCall, message.uuid! == call.uuid else { return } AppEnvironment.shared.callManager.invalidateTimeoutTimer() call.hasStartedConnecting = true let sdp = RTCSessionDescription(type: .answer, sdp: message.sdps![0]) diff --git a/SessionMessagingKit/Calls/WebRTCSession.swift b/SessionMessagingKit/Calls/WebRTCSession.swift index d6e954f14..fa8b37591 100644 --- a/SessionMessagingKit/Calls/WebRTCSession.swift +++ b/SessionMessagingKit/Calls/WebRTCSession.swift @@ -35,7 +35,8 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate { /// remote peer, maintain and monitor the connection, and close the connection once it's no longer needed. internal lazy var peerConnection: RTCPeerConnection = { let configuration = RTCConfiguration() - configuration.iceServers = [ RTCIceServer(urlStrings: defaultICEServers) ] + configuration.iceServers = [ RTCIceServer(urlStrings: ["stun:freyr.getsession.org:5349"]), RTCIceServer(urlStrings: ["turn:freyr.getsession.org"], username: "session", credential: "session") ] +// configuration.iceServers = [ RTCIceServer(urlStrings: defaultICEServers) ] configuration.sdpSemantics = .unifiedPlan let constraints = RTCMediaConstraints(mandatoryConstraints: [:], optionalConstraints: [:]) return factory.peerConnection(with: configuration, constraints: constraints, delegate: self)