mirror of https://github.com/oxen-io/session-ios
refactor for CallKit
parent
6f78d6dfbe
commit
bef20e2f9a
@ -0,0 +1,47 @@
|
||||
import CallKit
|
||||
import SessionUtilitiesKit
|
||||
|
||||
extension SessionCallManager {
|
||||
public func startCall(_ call: SessionCall, completion: (() -> Void)?) {
|
||||
guard case .offer = call.mode else { return }
|
||||
let handle = CXHandle(type: .generic, value: call.sessionID)
|
||||
let startCallAction = CXStartCallAction(call: call.uuid, handle: handle)
|
||||
|
||||
startCallAction.isVideo = false
|
||||
|
||||
let transaction = CXTransaction()
|
||||
transaction.addAction(startCallAction)
|
||||
|
||||
reportOutgoingCall(call)
|
||||
requestTransaction(transaction)
|
||||
completion?()
|
||||
}
|
||||
|
||||
public func endCall(_ call: SessionCall, completion: (() -> Void)?) {
|
||||
let endCallAction = CXEndCallAction(call: call.uuid)
|
||||
let transaction = CXTransaction()
|
||||
transaction.addAction(endCallAction)
|
||||
|
||||
requestTransaction(transaction)
|
||||
completion?()
|
||||
}
|
||||
|
||||
// Not currently in use
|
||||
public func setOnHoldStatus(for call: SessionCall) {
|
||||
let setHeldCallAction = CXSetHeldCallAction(call: call.uuid, onHold: true)
|
||||
let transaction = CXTransaction()
|
||||
transaction.addAction(setHeldCallAction)
|
||||
|
||||
requestTransaction(transaction)
|
||||
}
|
||||
|
||||
private func requestTransaction(_ transaction: CXTransaction) {
|
||||
callController.request(transaction) { error in
|
||||
if let error = error {
|
||||
SNLog("Error requesting transaction: \(error)")
|
||||
} else {
|
||||
SNLog("Requested transaction successfully")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
import CallKit
|
||||
|
||||
extension SessionCallManager: CXProviderDelegate {
|
||||
public func providerDidReset(_ provider: CXProvider) {
|
||||
AssertIsOnMainThread()
|
||||
currentCall?.endSessionCall()
|
||||
}
|
||||
|
||||
public func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
|
||||
AssertIsOnMainThread()
|
||||
guard let call = self.currentCall else { return action.fail() }
|
||||
call.startSessionCall(completion: nil)
|
||||
action.fulfill()
|
||||
}
|
||||
|
||||
public func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
|
||||
AssertIsOnMainThread()
|
||||
guard let _ = self.currentCall else { return action.fail() }
|
||||
let userDefaults = UserDefaults.standard
|
||||
if userDefaults[.hasSeenCallIPExposureWarning] {
|
||||
showCallVC()
|
||||
} else {
|
||||
showCallModal()
|
||||
}
|
||||
action.fulfill()
|
||||
}
|
||||
|
||||
public func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
|
||||
AssertIsOnMainThread()
|
||||
guard let call = self.currentCall else { return action.fail() }
|
||||
call.endSessionCall()
|
||||
reportCurrentCallEnded(reason: nil)
|
||||
action.fulfill()
|
||||
}
|
||||
|
||||
public func provider(_ provider: CXProvider, perform action: CXSetHeldCallAction) {
|
||||
// TODO: set on hold
|
||||
}
|
||||
|
||||
public func provider(_ provider: CXProvider, timedOutPerforming action: CXAction) {
|
||||
// TODO: handle timeout
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue