seperate CallKit uuid from session call id

pull/560/head
ryanzhao 4 years ago
parent bd938897ad
commit 02d0499618

@ -6,7 +6,8 @@ import CallKit
public final class SessionCall: NSObject, WebRTCSessionDelegate { public final class SessionCall: NSObject, WebRTCSessionDelegate {
// MARK: Metadata Properties // MARK: Metadata Properties
let uuid: UUID let uuid: String
let callID: UUID // This is for CallKit
let sessionID: String let sessionID: String
let mode: Mode let mode: Mode
let webRTCSession: WebRTCSession let webRTCSession: WebRTCSession
@ -137,7 +138,8 @@ public final class SessionCall: NSObject, WebRTCSessionDelegate {
// MARK: Initialization // MARK: Initialization
init(for sessionID: String, uuid: String, mode: Mode, outgoing: Bool = false) { init(for sessionID: String, uuid: String, mode: Mode, outgoing: Bool = false) {
self.sessionID = sessionID self.sessionID = sessionID
self.uuid = UUID(uuidString: uuid)! self.uuid = uuid
self.callID = UUID()
self.mode = mode self.mode = mode
self.webRTCSession = WebRTCSession.current ?? WebRTCSession(for: sessionID, with: uuid) self.webRTCSession = WebRTCSession.current ?? WebRTCSession(for: sessionID, with: uuid)
self.isOutgoing = outgoing self.isOutgoing = outgoing

@ -6,7 +6,7 @@ extension SessionCallManager {
guard case .offer = call.mode else { return } guard case .offer = call.mode else { return }
guard !call.hasConnected else { return } guard !call.hasConnected else { return }
let handle = CXHandle(type: .generic, value: call.sessionID) 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 startCallAction.isVideo = false
@ -18,7 +18,7 @@ extension SessionCallManager {
} }
public func answerCall(_ call: SessionCall, completion: ((Error?) -> Void)?) { public func answerCall(_ call: SessionCall, completion: ((Error?) -> Void)?) {
let answerCallAction = CXAnswerCallAction(call: call.uuid) let answerCallAction = CXAnswerCallAction(call: call.callID)
let transaction = CXTransaction() let transaction = CXTransaction()
transaction.addAction(answerCallAction) transaction.addAction(answerCallAction)
@ -26,7 +26,7 @@ extension SessionCallManager {
} }
public func endCall(_ call: SessionCall, completion: ((Error?) -> Void)?) { public func endCall(_ call: SessionCall, completion: ((Error?) -> Void)?) {
let endCallAction = CXEndCallAction(call: call.uuid) let endCallAction = CXEndCallAction(call: call.callID)
let transaction = CXTransaction() let transaction = CXTransaction()
transaction.addAction(endCallAction) transaction.addAction(endCallAction)
@ -35,7 +35,7 @@ extension SessionCallManager {
// Not currently in use // Not currently in use
public func setOnHoldStatus(for call: SessionCall) { 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() let transaction = CXTransaction()
transaction.addAction(setHeldCallAction) transaction.addAction(setHeldCallAction)

@ -63,10 +63,10 @@ public final class SessionCallManager: NSObject {
AssertIsOnMainThread() AssertIsOnMainThread()
call.stateDidChange = { call.stateDidChange = {
if call.hasStartedConnecting { if call.hasStartedConnecting {
self.provider.reportOutgoingCall(with: call.uuid, startedConnectingAt: call.connectingDate) self.provider.reportOutgoingCall(with: call.callID, startedConnectingAt: call.connectingDate)
} }
if call.hasConnected { 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 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. // Construct a CXCallUpdate describing the incoming call, including the caller.
let update = CXCallUpdate() let update = CXCallUpdate()
update.localizedCallerName = callerName 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.hasVideo = false
update.supportsGrouping = false update.supportsGrouping = false
update.supportsUngrouping = false update.supportsUngrouping = false
@ -93,7 +93,7 @@ public final class SessionCallManager: NSObject {
disableUnsupportedFeatures(callUpdate: update) disableUnsupportedFeatures(callUpdate: update)
// Report the incoming call to the system // 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 { guard error == nil else {
self.currentCall = nil self.currentCall = nil
completion(error) completion(error)
@ -107,7 +107,7 @@ public final class SessionCallManager: NSObject {
public func reportCurrentCallEnded(reason: CXCallEndedReason?) { public func reportCurrentCallEnded(reason: CXCallEndedReason?) {
guard let call = currentCall else { return } guard let call = currentCall else { return }
if let reason = reason { 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 { if reason == .unanswered {
call.updateCallMessage(mode: .unanswered) call.updateCallMessage(mode: .unanswered)
} else { } else {

@ -57,7 +57,7 @@ extension AppDelegate {
// Offer messages // Offer messages
MessageReceiver.handleOfferCallMessage = { message in MessageReceiver.handleOfferCallMessage = { message in
DispatchQueue.main.async { 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]) let sdp = RTCSessionDescription(type: .offer, sdp: message.sdps![0])
call.didReceiveRemoteSDP(sdp: sdp) call.didReceiveRemoteSDP(sdp: sdp)
} }
@ -65,7 +65,7 @@ extension AppDelegate {
// Answer messages // Answer messages
MessageReceiver.handleAnswerCallMessage = { message in MessageReceiver.handleAnswerCallMessage = { message in
DispatchQueue.main.async { 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() AppEnvironment.shared.callManager.invalidateTimeoutTimer()
call.hasStartedConnecting = true call.hasStartedConnecting = true
let sdp = RTCSessionDescription(type: .answer, sdp: message.sdps![0]) let sdp = RTCSessionDescription(type: .answer, sdp: message.sdps![0])

@ -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. /// remote peer, maintain and monitor the connection, and close the connection once it's no longer needed.
internal lazy var peerConnection: RTCPeerConnection = { internal lazy var peerConnection: RTCPeerConnection = {
let configuration = RTCConfiguration() 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 configuration.sdpSemantics = .unifiedPlan
let constraints = RTCMediaConstraints(mandatoryConstraints: [:], optionalConstraints: [:]) let constraints = RTCMediaConstraints(mandatoryConstraints: [:], optionalConstraints: [:])
return factory.peerConnection(with: configuration, constraints: constraints, delegate: self) return factory.peerConnection(with: configuration, constraints: constraints, delegate: self)

Loading…
Cancel
Save