Experimentations for extracting the core from the main thread

This commit is contained in:
QuentinArguillere
2023-09-12 16:55:20 +02:00
parent 6c7585aac8
commit 59d7747e86
14 changed files with 754 additions and 88 deletions

View File

@@ -7,7 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
577005D03F6821591475FBF9 /* Pods_CallKitTutorial.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 454830E9C41DBBF20AF2BD05 /* Pods_CallKitTutorial.framework */; };
62F26DACEAE3A1D31676DFC8 /* Pods_CallKitTutorial.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C6E14A45B7F8F19111223509 /* Pods_CallKitTutorial.framework */; };
6608A96624E197D5006E6C68 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6608A96524E197D5006E6C68 /* AppDelegate.swift */; };
6608A96824E197D5006E6C68 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6608A96724E197D5006E6C68 /* SceneDelegate.swift */; };
6608A96A24E197D5006E6C68 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6608A96924E197D5006E6C68 /* ContentView.swift */; };
@@ -19,8 +19,6 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
018936DA8FE1500B9E181610 /* Pods-CallKitTutorial.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CallKitTutorial.debug.xcconfig"; path = "Target Support Files/Pods-CallKitTutorial/Pods-CallKitTutorial.debug.xcconfig"; sourceTree = "<group>"; };
454830E9C41DBBF20AF2BD05 /* Pods_CallKitTutorial.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_CallKitTutorial.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6608A96224E197D5006E6C68 /* CallKitTutorial.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CallKitTutorial.app; sourceTree = BUILT_PRODUCTS_DIR; };
6608A96524E197D5006E6C68 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
6608A96724E197D5006E6C68 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
@@ -32,7 +30,9 @@
6608A97924E19817006E6C68 /* CallKitTutorial.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CallKitTutorial.swift; sourceTree = "<group>"; };
6608A97B24E1981E006E6C68 /* CallKitProviderDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CallKitProviderDelegate.swift; sourceTree = "<group>"; };
6608A97D24E19852006E6C68 /* CallKitTutorial.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = CallKitTutorial.entitlements; sourceTree = "<group>"; };
C87B170DFD4D3072825B25EF /* Pods-CallKitTutorial.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CallKitTutorial.release.xcconfig"; path = "Target Support Files/Pods-CallKitTutorial/Pods-CallKitTutorial.release.xcconfig"; sourceTree = "<group>"; };
9D767CD0AA573757AD042365 /* Pods-CallKitTutorial.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CallKitTutorial.release.xcconfig"; path = "Target Support Files/Pods-CallKitTutorial/Pods-CallKitTutorial.release.xcconfig"; sourceTree = "<group>"; };
C6E14A45B7F8F19111223509 /* Pods_CallKitTutorial.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_CallKitTutorial.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D7FA91A3C73CAEE3300CB14C /* Pods-CallKitTutorial.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CallKitTutorial.debug.xcconfig"; path = "Target Support Files/Pods-CallKitTutorial/Pods-CallKitTutorial.debug.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -40,26 +40,18 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
577005D03F6821591475FBF9 /* Pods_CallKitTutorial.framework in Frameworks */,
62F26DACEAE3A1D31676DFC8 /* Pods_CallKitTutorial.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
319770E3ECD19EBD7557F82B /* Frameworks */ = {
isa = PBXGroup;
children = (
454830E9C41DBBF20AF2BD05 /* Pods_CallKitTutorial.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
38284A71627D413A7ACC2F07 /* Pods */ = {
isa = PBXGroup;
children = (
018936DA8FE1500B9E181610 /* Pods-CallKitTutorial.debug.xcconfig */,
C87B170DFD4D3072825B25EF /* Pods-CallKitTutorial.release.xcconfig */,
D7FA91A3C73CAEE3300CB14C /* Pods-CallKitTutorial.debug.xcconfig */,
9D767CD0AA573757AD042365 /* Pods-CallKitTutorial.release.xcconfig */,
);
path = Pods;
sourceTree = "<group>";
@@ -70,7 +62,7 @@
6608A96424E197D5006E6C68 /* CallKitTutorial */,
6608A96324E197D5006E6C68 /* Products */,
38284A71627D413A7ACC2F07 /* Pods */,
319770E3ECD19EBD7557F82B /* Frameworks */,
D50E07CDAF0ACCEEEE7C2683 /* Frameworks */,
);
sourceTree = "<group>";
};
@@ -107,6 +99,14 @@
path = "Preview Content";
sourceTree = "<group>";
};
D50E07CDAF0ACCEEEE7C2683 /* Frameworks */ = {
isa = PBXGroup;
children = (
C6E14A45B7F8F19111223509 /* Pods_CallKitTutorial.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -114,11 +114,11 @@
isa = PBXNativeTarget;
buildConfigurationList = 6608A97624E197D5006E6C68 /* Build configuration list for PBXNativeTarget "CallKitTutorial" */;
buildPhases = (
D642DC4C3C74BB17FF5A3E9F /* [CP] Check Pods Manifest.lock */,
6A2B822BFAB3B00C62638AFD /* [CP] Check Pods Manifest.lock */,
6608A95E24E197D5006E6C68 /* Sources */,
6608A95F24E197D5006E6C68 /* Frameworks */,
6608A96024E197D5006E6C68 /* Resources */,
640A5744B5ABBA6A3EDBFDB1 /* [CP] Embed Pods Frameworks */,
D7986480B43805FC6FF0C9E5 /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
@@ -176,24 +176,7 @@
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
640A5744B5ABBA6A3EDBFDB1 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-CallKitTutorial/Pods-CallKitTutorial-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-CallKitTutorial/Pods-CallKitTutorial-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-CallKitTutorial/Pods-CallKitTutorial-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
D642DC4C3C74BB17FF5A3E9F /* [CP] Check Pods Manifest.lock */ = {
6A2B822BFAB3B00C62638AFD /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
@@ -215,6 +198,23 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
D7986480B43805FC6FF0C9E5 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-CallKitTutorial/Pods-CallKitTutorial-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-CallKitTutorial/Pods-CallKitTutorial-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-CallKitTutorial/Pods-CallKitTutorial-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
@@ -360,7 +360,7 @@
};
6608A97724E197D5006E6C68 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 018936DA8FE1500B9E181610 /* Pods-CallKitTutorial.debug.xcconfig */;
baseConfigurationReference = D7FA91A3C73CAEE3300CB14C /* Pods-CallKitTutorial.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = CallKitTutorial/CallKitTutorial.entitlements;
@@ -383,7 +383,7 @@
};
6608A97824E197D5006E6C68 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = C87B170DFD4D3072825B25EF /* Pods-CallKitTutorial.release.xcconfig */;
baseConfigurationReference = 9D767CD0AA573757AD042365 /* Pods-CallKitTutorial.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = CallKitTutorial/CallKitTutorial.entitlements;

View File

@@ -23,7 +23,7 @@ class CallKitProviderDelegate : NSObject
init(context: CallKitExampleContext)
{
tutorialContext = context
let providerConfiguration = CXProviderConfiguration(localizedName: Bundle.main.infoDictionary!["CFBundleName"] as! String)
let providerConfiguration = CXProviderConfiguration()
providerConfiguration.supportsVideo = true
providerConfiguration.supportedHandleTypes = [.generic]
@@ -38,6 +38,7 @@ class CallKitProviderDelegate : NSObject
func incomingCall()
{
NSLog("Callkit incomingCall -- Is main thread ? \(Thread.isMainThread ? "yes" : "no") ")
incomingCallUUID = UUID()
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type:.generic, value: tutorialContext.incomingCallName)
@@ -47,6 +48,7 @@ class CallKitProviderDelegate : NSObject
func stopCall()
{
NSLog("Callkit stopCall -- Is main thread ? \(Thread.isMainThread ? "yes" : "no") ")
let endCallAction = CXEndCallAction(call: incomingCallUUID)
let transaction = CXTransaction(action: endCallAction)
@@ -61,6 +63,7 @@ class CallKitProviderDelegate : NSObject
extension CallKitProviderDelegate: CXProviderDelegate {
func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
NSLog("Callkit CXEndCallAction -- Is main thread ? \(Thread.isMainThread ? "yes" : "no") ")
do {
if (tutorialContext.mCall?.state != .End && tutorialContext.mCall?.state != .Released) {
try tutorialContext.mCall?.terminate()
@@ -73,6 +76,7 @@ extension CallKitProviderDelegate: CXProviderDelegate {
}
func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
NSLog("Callkit CXAnswerCallAction -- Is main thread ? \(Thread.isMainThread ? "yes" : "no") ")
do {
// The audio stream is going to start shortly: the AVAudioSession must be configured now.
// It is worth to note that an application does not have permission to configure the
@@ -102,13 +106,18 @@ extension CallKitProviderDelegate: CXProviderDelegate {
func providerDidReset(_ provider: CXProvider) {}
func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
NSLog("Callkit didActivateaudiosession -- Is main thread ? \(Thread.isMainThread ? "yes" : "no") ")
// The linphone Core must be notified that CallKit has activated the AVAudioSession
// in order to start streaming audio.
tutorialContext.mCore.activateAudioSession(actived: true)
tutorialContext.postOnCoreQueue {
self.tutorialContext.mCore.activateAudioSession(actived: true)
}
}
func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
// The linphone Core must be notified that CallKit has deactivated the AVAudioSession.
tutorialContext.mCore.activateAudioSession(actived: false)
tutorialContext.postOnCoreQueue {
self.tutorialContext.mCore.activateAudioSession(actived: false)
}
}
}

View File

@@ -9,19 +9,22 @@
import linphonesw
import AVFoundation
class CallKitExampleContext : ObservableObject
{
private let queue = DispatchQueue(label:"core.queue")
var mCore: Core!
@Published var coreVersion: String = Core.getVersion
var mAccount: Account?
var mCoreDelegate : CoreDelegate!
@Published var username : String = "user"
@Published var passwd : String = "pwd"
@Published var domain : String = "sip.example.org"
var mIterateTimer : Timer!
@Published var coreVersion: String = Core.getVersion
@Published var username : String = "quentindev"
@Published var passwd : String = "dev"
@Published var domain : String = "sip.linphone.org"
@Published var loggedIn: Bool = false
@Published var transportType : String = "TLS"
@Published var callMsg : String = ""
@Published var isCallIncoming : Bool = false
@Published var isCallRunning : Bool = false
@@ -35,6 +38,18 @@ class CallKitExampleContext : ObservableObject
var mProviderDelegate : CallKitProviderDelegate!
var mCallAlreadyStopped : Bool = false;
func postOnCoreQueue(lambda : @escaping ()->()) {
queue.async {
lambda()
}
}
func postOnMainQueue(lambda : @escaping()->()) {
DispatchQueue.main.async {
lambda()
}
}
init()
{
LoggingService.Instance.logLevel = LogLevel.Debug
@@ -46,26 +61,28 @@ class CallKitExampleContext : ObservableObject
// We also need to enable "Push Notitifications" and "Background Mode - Voice Over IP"
let configDir = factory.getConfigDir(context: nil)
try? mCore = factory.createCore(configPath: "\(configDir)/MyConfig", factoryConfigPath: "", systemContext: nil)
mProviderDelegate = CallKitProviderDelegate(context: self)
// enabling push notifications management in the core
mCore.callkitEnabled = true
mCore.pushNotificationEnabled = true
try? mCore.start()
mCore.autoIterateEnabled = false
mCoreDelegate = CoreDelegateStub( onCallStateChanged: { (core: Core, call: Call, state: Call.State, message: String) in
self.callMsg = message
if (state == .PushIncomingReceived){
// We're being called by someone (and app is in background)
self.mCall = call
self.isCallIncoming = true
self.mProviderDelegate.incomingCall()
self.isCallIncoming = true
self.callMsg = message
} else if (state == .IncomingReceived) {
// If app is in foreground, it's likely that we will receive the SIP invite before the Push notification
if (!self.isCallIncoming) {
self.mCall = call
self.isCallIncoming = true
self.mProviderDelegate.incomingCall()
self.isCallIncoming = true
self.callMsg = message
}
self.remoteAddress = call.remoteAddress!.asStringUriOnly()
} else if (state == .Connected) {
@@ -91,51 +108,70 @@ class CallKitExampleContext : ObservableObject
self.loggedIn = false
}
})
mIterateTimer = Timer.scheduledTimer(withTimeInterval: 0.02, repeats: true) { [weak self] timer in
self?.postOnCoreQueue {
self?.mCore.iterate()
}
}
mProviderDelegate = CallKitProviderDelegate(context: self)
mCore.addDelegate(delegate: mCoreDelegate)
postOnCoreQueue {
try? self.mCore.start()
}
}
func login() {
do {
var transport : TransportType
if (transportType == "TLS") { transport = TransportType.Tls }
else if (transportType == "TCP") { transport = TransportType.Tcp }
else { transport = TransportType.Udp }
let authInfo = try Factory.Instance.createAuthInfo(username: username, userid: "", passwd: passwd, ha1: "", realm: "", domain: domain)
let accountParams = try mCore.createAccountParams()
let identity = try Factory.Instance.createAddress(addr: String("sip:" + username + "@" + domain))
try! accountParams.setIdentityaddress(newValue: identity)
let address = try Factory.Instance.createAddress(addr: String("sip:" + domain))
try address.setTransport(newValue: transport)
try accountParams.setServeraddress(newValue: address)
accountParams.registerEnabled = true
// Enable push notifications on this account
accountParams.pushNotificationAllowed = true
// We're in a sandbox application, so we must set the provider to "apns.dev" since it will be "apns" by default, which is used only for production apps
accountParams.pushNotificationConfig?.provider = "apns.dev"
mAccount = try mCore.createAccount(params: accountParams)
mCore.addAuthInfo(info: authInfo)
try mCore.addAccount(account: mAccount!)
mCore.defaultAccount = mAccount
} catch { NSLog(error.localizedDescription) }
postOnCoreQueue {
do {
var transport : TransportType
if (self.transportType == "TLS") { transport = TransportType.Tls }
else if (self.transportType == "TCP") { transport = TransportType.Tcp }
else { transport = TransportType.Udp }
let authInfo = try Factory.Instance.createAuthInfo(username: self.username, userid: "", passwd: self.passwd, ha1: "", realm: "", domain: self.domain)
let accountParams = try self.mCore.createAccountParams()
let identity = try Factory.Instance.createAddress(addr: String("sip:" + self.username + "@" + self.domain))
try! accountParams.setIdentityaddress(newValue: identity)
let address = try Factory.Instance.createAddress(addr: String("sip:" + self.domain))
try address.setTransport(newValue: transport)
try accountParams.setServeraddress(newValue: address)
accountParams.registerEnabled = true
// Enable push notifications on this account
accountParams.pushNotificationAllowed = true
// We're in a sandbox application, so we must set the provider to "apns.dev" since it will be "apns" by default, which is used only for production apps
accountParams.pushNotificationConfig?.provider = "apns.dev"
self.mAccount = try self.mCore.createAccount(params: accountParams)
self.mCore.addAuthInfo(info: authInfo)
try self.mCore.addAccount(account: self.mAccount!)
self.mCore.defaultAccount = self.mAccount
} catch { NSLog(error.localizedDescription) }
}
}
func unregister()
{
if let account = mCore.defaultAccount {
let params = account.params
let clonedParams = params?.clone()
clonedParams?.registerEnabled = false
account.params = clonedParams
postOnCoreQueue {
if let account = self.mCore.defaultAccount {
let params = account.params
let clonedParams = params?.clone()
clonedParams?.registerEnabled = false
account.params = clonedParams
}
}
}
func delete() {
if let account = mCore.defaultAccount {
mCore.removeAccount(account: account)
mCore.clearAccounts()
mCore.clearAllAuthInfo()
postOnCoreQueue {
if let account = self.mCore.defaultAccount {
self.mCore.removeAccount(account: account)
self.mCore.clearAccounts()
self.mCore.clearAllAuthInfo()
}
}
}
}

View File

@@ -1,11 +1,11 @@
# Uncomment the next line to define a global platform for your project
platform :ios, '11.0'
platform :ios, '13.0'
source "https://gitlab.linphone.org/BC/public/podspec.git"
source "https://github.com/CocoaPods/Specs.git"
def basic_pods
if ENV['PODFILE_PATH'].nil?
pod 'linphone-sdk', '~> 5.0.48'
pod 'linphone-sdk', '~> 5.3.0-alpha'
else
pod 'linphone-sdk', :path => ENV['PODFILE_PATH'] # local sdk
end