Suggestions from CD3 revised call back publishers
This commit is contained in:
@@ -17,8 +17,8 @@ class CallKitExampleContext : ObservableObject
|
||||
@Published var factory = Factory.Instance
|
||||
|
||||
@Published var coreVersion: String = Core.getVersion
|
||||
@Published var username : String = "quentindev"
|
||||
@Published var passwd : String = "dev"
|
||||
@Published var username : String = "cd1"
|
||||
@Published var passwd : String = "cd1"
|
||||
@Published var domain : String = "sip.linphone.org"
|
||||
@Published var loggedIn: Bool = false
|
||||
@Published var transportType : String = "TLS"
|
||||
@@ -33,10 +33,6 @@ class CallKitExampleContext : ObservableObject
|
||||
var icancellables = Set<AnyCancellable>()
|
||||
|
||||
|
||||
/* Async */
|
||||
let linphoneAsyncHelper = LinphoneAsyncHelper()
|
||||
|
||||
|
||||
/*------------ Callkit tutorial related variables ---------------*/
|
||||
let incomingCallName = "Incoming call example"
|
||||
var mCall : Call?
|
||||
@@ -45,48 +41,49 @@ class CallKitExampleContext : ObservableObject
|
||||
|
||||
|
||||
func addRegistrationStateCallBack(core:Core) {
|
||||
core.createAccountRegistrationStateChangedPublisher()
|
||||
.postOnMainQueue { result in
|
||||
NSLog("New registration state is \(result.state) for user id \( String(describing: result.account.params?.identityAddress?.asString()))\n")
|
||||
if (result.state == .Ok) {
|
||||
|
||||
core.accountStatePublisher
|
||||
.postOnMainQueue { (publishedValue:(core: Core, account: Account, state: RegistrationState, message: String)) in
|
||||
NSLog("New registration state is \(publishedValue.state) for user id \( String(describing: publishedValue.account.params?.identityAddress?.asString()))\n")
|
||||
if (publishedValue.state == .Ok) {
|
||||
self.loggedIn = true
|
||||
// Since core has "Push Enabled", the reception and setting of the push notification token is done automatically
|
||||
// It should have been set and used when we log in, you can check here or in the liblinphone logs
|
||||
NSLog("Account registered Push voip token: \(result.account.params?.pushNotificationConfig?.voipToken)")
|
||||
} else if (result.state == .Cleared) {
|
||||
NSLog("Account registered Push voip token: \(String(describing: publishedValue.account.params?.pushNotificationConfig?.voipToken))")
|
||||
} else if (publishedValue.state == .Cleared) {
|
||||
self.loggedIn = false
|
||||
}
|
||||
}
|
||||
.postOnCoreQueue{ result in
|
||||
.postOnCoreQueue{ (accountStatePublisher:(core: Core, account: Account, state: RegistrationState, message: String)) in
|
||||
// optional something on core queue if needed
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func addCallStateChangedCallBack(core:Core) {
|
||||
core.createOnCallStateChangedPublisher()
|
||||
.postOnMainQueue { result in
|
||||
self.callMsg = result.message
|
||||
if (result.state == .PushIncomingReceived){
|
||||
core.callStatePublisher
|
||||
.postOnMainQueue { (publishedValue:(core: Core, call: Call, state: Call.State, message: String)) in
|
||||
self.callMsg = publishedValue.message
|
||||
if (publishedValue.state == .PushIncomingReceived){
|
||||
// We're being called by someone (and app is in background)
|
||||
self.mCall = result.call
|
||||
self.mCall = publishedValue.call
|
||||
self.mProviderDelegate.incomingCall()
|
||||
self.isCallIncoming = true
|
||||
self.callMsg = result.message
|
||||
} else if (result.state == .IncomingReceived) {
|
||||
self.callMsg = publishedValue.message
|
||||
} else if (publishedValue.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 = result.call
|
||||
self.mCall = publishedValue.call
|
||||
self.mProviderDelegate.incomingCall()
|
||||
|
||||
self.isCallIncoming = true
|
||||
self.callMsg = result.message
|
||||
self.callMsg = publishedValue.message
|
||||
}
|
||||
self.remoteAddress = result.call.remoteAddress!.asStringUriOnly()
|
||||
} else if (result.state == .Connected) {
|
||||
self.remoteAddress = publishedValue.call.remoteAddress!.asStringUriOnly()
|
||||
} else if (publishedValue.state == .Connected) {
|
||||
self.isCallIncoming = false
|
||||
self.isCallRunning = true
|
||||
} else if (result.state == .Released || result.state == .End || result.state == .Error) {
|
||||
} else if (publishedValue.state == .Released || publishedValue.state == .End || publishedValue.state == .Error) {
|
||||
// Call has been terminated by any side
|
||||
|
||||
// Report to CallKit that the call is over, if the terminate action was initiated by other end of the call
|
||||
@@ -96,7 +93,7 @@ class CallKitExampleContext : ObservableObject
|
||||
self.remoteAddress = "Nobody yet"
|
||||
}
|
||||
}
|
||||
.postOnCoreQueue{ result in
|
||||
.postOnCoreQueue{ (callStatePublisher:(core: Core, call: Call, state: Call.State, message: String)) in
|
||||
// optional something on core queue if needed
|
||||
}
|
||||
}
|
||||
@@ -115,7 +112,7 @@ class CallKitExampleContext : ObservableObject
|
||||
self.addRegistrationStateCallBack(core: core)
|
||||
self.addCallStateChangedCallBack(core: core)
|
||||
try? core.start()
|
||||
LinphoneAsyncHelper.postOnMainQueue {
|
||||
DispatchQueue.main.async {
|
||||
self.mCore = core // @Publisher assignment can be done on main queue only
|
||||
}
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user