seperate CallKit uuid from session call id

This commit is contained in:
ryanzhao 2021-11-12 09:17:06 +11:00
parent bd938897ad
commit 02d0499618
5 changed files with 17 additions and 14 deletions

View file

@ -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

View file

@ -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)

View file

@ -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 {

View file

@ -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])

View file

@ -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)