diff --git a/Linphone/Core/CoreContext.swift b/Linphone/Core/CoreContext.swift index 61ea05a5a..f146b8767 100644 --- a/Linphone/Core/CoreContext.swift +++ b/Linphone/Core/CoreContext.swift @@ -23,6 +23,7 @@ import linphonesw import Combine import UniformTypeIdentifiers +import Network final class CoreContext: ObservableObject { @@ -39,6 +40,8 @@ final class CoreContext: ObservableObject { private var mIterateSuscription: AnyCancellable? private var mCoreSuscriptions = Set() + let monitor = NWPathMonitor() + private init() { do { try initialiseCore() @@ -130,7 +133,7 @@ final class CoreContext: ObservableObject { if cbVal.status == Config.ConfiguringState.Successful { ToastViewModel.shared.toastMessage = "Successful" ToastViewModel.shared.displayToast = true - } + } /* else { ToastViewModel.shared.toastMessage = "Failed" @@ -157,6 +160,21 @@ final class CoreContext: ObservableObject { self.loggedIn = false ToastViewModel.shared.toastMessage = "Registration failed" ToastViewModel.shared.displayToast = true + + self.monitor.pathUpdateHandler = { path in + if path.status == .satisfied { + if cbVal.state != .Ok && cbVal.state != .Progress { + let params = cbVal.account.params + let clonedParams = params?.clone() + clonedParams?.registerEnabled = false + cbVal.account.params = clonedParams + + cbVal.core.removeAccount(account: cbVal.account) + cbVal.core.clearAccounts() + cbVal.core.clearAllAuthInfo() + } + } + } } }) @@ -188,7 +206,7 @@ final class CoreContext: ObservableObject { DispatchQueue.main.async { ToastViewModel.shared.toastMessage = "Success_send_logs" - ToastViewModel.shared.displayToast = true + ToastViewModel.shared.displayToast = true } } }) diff --git a/Linphone/Localizable.xcstrings b/Linphone/Localizable.xcstrings index 7b82fa2c6..865f0fc3e 100644 --- a/Linphone/Localizable.xcstrings +++ b/Linphone/Localizable.xcstrings @@ -364,6 +364,9 @@ }, "Log out" : { + }, + "Logout" : { + }, "Logs cleared" : { diff --git a/Linphone/TelecomManager/TelecomManager.swift b/Linphone/TelecomManager/TelecomManager.swift index 98a65005c..93a80e1d3 100644 --- a/Linphone/TelecomManager/TelecomManager.swift +++ b/Linphone/TelecomManager/TelecomManager.swift @@ -341,7 +341,7 @@ class TelecomManager: ObservableObject { let oldRemoteVideo = self.remoteVideo self.remoteVideo = (core.videoActivationPolicy?.automaticallyAccept ?? false) && (call.remoteParams?.videoEnabled ?? false) - if oldRemoteVideo != self.remoteVideo && self.remoteVideo { + if self.remoteVideo && self.remoteVideo != oldRemoteVideo { do { try AVAudioSession.sharedInstance().overrideOutputAudioPort(.speaker) } catch _ { diff --git a/Linphone/UI/Main/Fragments/SideMenu.swift b/Linphone/UI/Main/Fragments/SideMenu.swift index e9fdc8d70..95b838a10 100644 --- a/Linphone/UI/Main/Fragments/SideMenu.swift +++ b/Linphone/UI/Main/Fragments/SideMenu.swift @@ -71,16 +71,15 @@ struct SideMenu: View { clearLogs() self.menuClose() } - /* Text("Logout") .frame(height: 40) .frame(maxWidth: .infinity, alignment: .leading) .background(Color.white) .onTapGesture { print("Logout") + logout() self.menuClose() } - */ } .frame(width: self.width - safeAreaInsets.leading) .background(Color.white) @@ -110,4 +109,26 @@ struct SideMenu: View { } } } + + func logout() { + coreContext.doOnCoreQueue { core in + if core.defaultAccount != nil { + let authInfo = core.defaultAccount!.findAuthInfo() + if authInfo != nil { + Log.info("$TAG Found auth info for account, removing it") + core.removeAuthInfo(info: authInfo!) + } else { + Log.warn("$TAG Failed to find matching auth info for account") + } + + core.removeAccount(account: core.defaultAccount!) + Log.info("$TAG Account has been removed") + + DispatchQueue.main.async { + coreContext.defaultAccount = nil + coreContext.loggedIn = false + } + } + } + } } diff --git a/Linphone/UI/Main/Fragments/ToastView.swift b/Linphone/UI/Main/Fragments/ToastView.swift index ed77961b6..567be383a 100644 --- a/Linphone/UI/Main/Fragments/ToastView.swift +++ b/Linphone/UI/Main/Fragments/ToastView.swift @@ -31,7 +31,6 @@ struct ToastView: View { .resizable() .renderingMode(.template) .frame(width: 25, height: 25, alignment: .leading) - .padding(.all, 10) .foregroundStyle(toastViewModel.toastMessage.contains("Success") ? Color.greenSuccess500 : Color.redDanger500) switch toastViewModel.toastMessage { @@ -130,7 +129,8 @@ struct ToastView: View { toastViewModel.displayToast = false } } - } } + } + } Spacer() }