mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 23:32:41 +00:00
Refactor session for app killed state
This commit is contained in:
parent
74460ef658
commit
e0c37448c3
2 changed files with 62 additions and 44 deletions
|
@ -174,6 +174,8 @@ extern NSString *const AppDelegateUniversalLinkDidChangeNotification;
|
|||
|
||||
- (BOOL)presentCompleteSecurityForSession:(MXSession*)mxSession;
|
||||
|
||||
- (void)configureCallManagerIfRequiredForSession:(MXSession *)mxSession;
|
||||
|
||||
#pragma mark - Matrix Accounts handling
|
||||
|
||||
- (void)selectMatrixAccount:(void (^)(MXKAccount *selectedAccount))onSelection;
|
||||
|
|
|
@ -508,11 +508,11 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni
|
|||
[DecryptionFailureTracker sharedInstance].delegate = [Analytics sharedInstance];
|
||||
[[Analytics sharedInstance] start];
|
||||
|
||||
self.pushNotificationService = [PushNotificationService new];
|
||||
self.pushNotificationService.delegate = self;
|
||||
|
||||
self.localAuthenticationService = [[LocalAuthenticationService alloc] initWithPinCodePreferences:[PinCodePreferences shared]];
|
||||
|
||||
self.pushNotificationService = [[PushNotificationService alloc] initWithPushNotificationManager:PushNotificationManager.shared];
|
||||
self.pushNotificationService.delegate = self;
|
||||
|
||||
// Add matrix observers, and initialize matrix sessions if the app is not launched in background.
|
||||
[self initMatrixSessions];
|
||||
|
||||
|
@ -537,6 +537,8 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni
|
|||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
|
||||
[self.pushNotificationService applicationWillResignActive];
|
||||
|
||||
// Release MatrixKit error observer
|
||||
if (matrixKitErrorObserver)
|
||||
{
|
||||
|
@ -616,6 +618,8 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni
|
|||
|
||||
_isAppForeground = NO;
|
||||
|
||||
[self.pushNotificationService applicationDidEnterBackground];
|
||||
|
||||
// Analytics: Force to send the pending actions
|
||||
[[DecryptionFailureTracker sharedInstance] dispatch];
|
||||
[[Analytics sharedInstance] dispatch];
|
||||
|
@ -627,9 +631,6 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni
|
|||
|
||||
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
|
||||
|
||||
// Notify push notification service
|
||||
[self.pushNotificationService applicationWillEnterForeground];
|
||||
|
||||
// Force each session to refresh here their publicised groups by user dictionary.
|
||||
// When these publicised groups are retrieved for a user, they are cached and reused until the app is backgrounded and enters in the foreground again
|
||||
for (MXSession *session in mxSessionArray)
|
||||
|
@ -1843,44 +1844,7 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni
|
|||
// Store this new session
|
||||
[self addMatrixSession:mxSession];
|
||||
|
||||
// Set the VoIP call stack (if supported).
|
||||
id<MXCallStack> callStack;
|
||||
|
||||
#ifdef MX_CALL_STACK_OPENWEBRTC
|
||||
callStack = [[MXOpenWebRTCCallStack alloc] init];
|
||||
#endif
|
||||
#ifdef MX_CALL_STACK_ENDPOINT
|
||||
callStack = [[MXEndpointCallStack alloc] initWithMatrixId:mxSession.myUser.userId];
|
||||
#endif
|
||||
#ifdef CALL_STACK_JINGLE
|
||||
callStack = [[MXJingleCallStack alloc] init];
|
||||
#endif
|
||||
if (callStack)
|
||||
{
|
||||
[mxSession enableVoIPWithCallStack:callStack];
|
||||
|
||||
// Setup CallKit
|
||||
if ([MXCallKitAdapter callKitAvailable])
|
||||
{
|
||||
BOOL isCallKitEnabled = [MXKAppSettings standardAppSettings].isCallKitEnabled;
|
||||
[self enableCallKit:isCallKitEnabled forCallManager:mxSession.callManager];
|
||||
|
||||
// Register for changes performed by the user
|
||||
[[MXKAppSettings standardAppSettings] addObserver:self
|
||||
forKeyPath:@"enableCallKit"
|
||||
options:NSKeyValueObservingOptionNew
|
||||
context:NULL];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self enableCallKit:NO forCallManager:mxSession.callManager];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// When there is no call stack, display alerts on call invites
|
||||
[self enableNoVoIPOnMatrixSession:mxSession];
|
||||
}
|
||||
[self configureCallManagerIfRequiredForSession:mxSession];
|
||||
|
||||
[self.configuration setupSettingsFor:mxSession];
|
||||
}
|
||||
|
@ -2286,6 +2250,9 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni
|
|||
// Reset user pin code
|
||||
[PinCodePreferences.shared reset];
|
||||
|
||||
// Reset push notification manager
|
||||
[PushNotificationManager.shared reset];
|
||||
|
||||
#ifdef MX_CALL_STACK_ENDPOINT
|
||||
// Erase all created certificates and private keys by MXEndpointCallStack
|
||||
for (MXKAccount *account in MXKAccountManager.sharedManager.accounts)
|
||||
|
@ -2503,6 +2470,55 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni
|
|||
}
|
||||
}
|
||||
|
||||
- (void)configureCallManagerIfRequiredForSession:(MXSession *)mxSession
|
||||
{
|
||||
if (mxSession.callManager)
|
||||
{
|
||||
// already configured
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the VoIP call stack (if supported).
|
||||
id<MXCallStack> callStack;
|
||||
|
||||
#ifdef MX_CALL_STACK_OPENWEBRTC
|
||||
callStack = [[MXOpenWebRTCCallStack alloc] init];
|
||||
#endif
|
||||
#ifdef MX_CALL_STACK_ENDPOINT
|
||||
callStack = [[MXEndpointCallStack alloc] initWithMatrixId:mxSession.myUser.userId];
|
||||
#endif
|
||||
#ifdef CALL_STACK_JINGLE
|
||||
callStack = [[MXJingleCallStack alloc] init];
|
||||
#endif
|
||||
|
||||
if (callStack)
|
||||
{
|
||||
[mxSession enableVoIPWithCallStack:callStack];
|
||||
|
||||
// Setup CallKit
|
||||
if ([MXCallKitAdapter callKitAvailable])
|
||||
{
|
||||
BOOL isCallKitEnabled = [MXKAppSettings standardAppSettings].isCallKitEnabled;
|
||||
[self enableCallKit:isCallKitEnabled forCallManager:mxSession.callManager];
|
||||
|
||||
// Register for changes performed by the user
|
||||
[[MXKAppSettings standardAppSettings] addObserver:self
|
||||
forKeyPath:@"enableCallKit"
|
||||
options:NSKeyValueObservingOptionNew
|
||||
context:NULL];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self enableCallKit:NO forCallManager:mxSession.callManager];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// When there is no call stack, display alerts on call invites
|
||||
[self enableNoVoIPOnMatrixSession:mxSession];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)enableCallKit:(BOOL)enable forCallManager:(MXCallManager *)callManager
|
||||
{
|
||||
#ifdef CALL_STACK_JINGLE
|
||||
|
|
Loading…
Reference in a new issue