зеркало из https://github.com/nextcloud/talk-ios.git
Merge pull request #1014 from nextcloud/external-signaling-connection-enh
External signaling connection enhancements
This commit is contained in:
Коммит
f3daa6f45f
|
@ -53,6 +53,9 @@
|
|||
|
||||
@interface AppDelegate ()
|
||||
|
||||
@property (nonatomic, strong) NSTimer *keepAliveTimer;
|
||||
@property (nonatomic, strong) BGTaskHelper *keepAliveBGTask;
|
||||
|
||||
@end
|
||||
|
||||
@implementation AppDelegate
|
||||
|
@ -120,6 +123,7 @@
|
|||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
||||
|
||||
[self keepExternalSignalingConnectionAliveTemporarily];
|
||||
[self scheduleAppRefresh];
|
||||
}
|
||||
|
||||
|
@ -133,6 +137,9 @@
|
|||
- (void)applicationDidBecomeActive:(UIApplication *)application
|
||||
{
|
||||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
|
||||
[self checkForDisconnectedExternalSignalingConnection];
|
||||
|
||||
[[NCNotificationController sharedInstance] removeAllNotificationsForAccountId:[[NCDatabaseManager sharedInstance] activeAccount].accountId];
|
||||
}
|
||||
|
||||
|
@ -451,5 +458,30 @@
|
|||
});
|
||||
}
|
||||
|
||||
- (void)keepExternalSignalingConnectionAliveTemporarily
|
||||
{
|
||||
[_keepAliveTimer invalidate];
|
||||
|
||||
_keepAliveBGTask = [BGTaskHelper startBackgroundTaskWithName:@"NCWebSocketKeepAlive" expirationHandler:nil];
|
||||
_keepAliveTimer = [NSTimer scheduledTimerWithTimeInterval:20 repeats:NO block:^(NSTimer * _Nonnull timer) {
|
||||
// Stop the external signaling connections only if the app keeps in the background
|
||||
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
|
||||
[[NCSettingsController sharedInstance] disconnectAllExternalSignalingControllers];
|
||||
}
|
||||
|
||||
[self->_keepAliveBGTask stopBackgroundTask];
|
||||
}];
|
||||
|
||||
[[NSRunLoop mainRunLoop] addTimer:_keepAliveTimer forMode:NSRunLoopCommonModes];
|
||||
}
|
||||
|
||||
- (void)checkForDisconnectedExternalSignalingConnection
|
||||
{
|
||||
[_keepAliveTimer invalidate];
|
||||
[_keepAliveBGTask stopBackgroundTask];
|
||||
|
||||
[[NCSettingsController sharedInstance] connectDisconnectedExternalSignalingControllers];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
|
|
@ -43,6 +43,7 @@ typedef void (^JoinRoomExternalSignalingCompletionBlock)(NSError *error);
|
|||
|
||||
@property (nonatomic, strong) NSString *currentRoom;
|
||||
@property (nonatomic, strong) TalkAccount *account;
|
||||
@property (nonatomic, assign) BOOL disconnected;
|
||||
@property (nonatomic, weak) id<NCExternalSignalingControllerDelegate> delegate;
|
||||
|
||||
- (instancetype)initWithAccount:(TalkAccount *)account server:(NSString *)serverUrl andTicket:(NSString *)ticket;
|
||||
|
@ -55,6 +56,7 @@ typedef void (^JoinRoomExternalSignalingCompletionBlock)(NSError *error);
|
|||
- (void)requestOfferForSessionId:(NSString *)sessionId andRoomType:(NSString *)roomType;
|
||||
- (NSString *)getUserIdFromSessionId:(NSString *)sessionId;
|
||||
- (NSString *)getDisplayNameFromSessionId:(NSString *)sessionId;
|
||||
- (void)connect;
|
||||
- (void)disconnect;
|
||||
- (void)forceReconnect;
|
||||
|
||||
|
|
|
@ -126,7 +126,14 @@ static NSTimeInterval kWebSocketTimeoutInterval = 15;
|
|||
|
||||
- (void)connect
|
||||
{
|
||||
// Do not try to connect if the app is running in the background
|
||||
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
|
||||
[NCUtils log:@"Trying to create websocket connection while app is in the background"];
|
||||
return;
|
||||
}
|
||||
|
||||
[self invalidateReconnectionTimer];
|
||||
_disconnected = NO;
|
||||
_messageId = 1;
|
||||
_messagesWithCompletionBlocks = [NSMutableArray new];
|
||||
_helloResponseReceived = NO;
|
||||
|
@ -176,6 +183,7 @@ static NSTimeInterval kWebSocketTimeoutInterval = 15;
|
|||
[self->_webSocket cancel];
|
||||
self->_webSocket = nil;
|
||||
self->_helloResponseReceived = NO;
|
||||
self->_disconnected = YES;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -74,6 +74,8 @@ typedef enum NCPreferredFileSorting {
|
|||
- (void)getSignalingConfigurationWithCompletionBlock:(GetSignalingConfigCompletionBlock)block;
|
||||
- (void)setSignalingConfigurationForAccountId:(NSString *)accountId;
|
||||
- (NCExternalSignalingController *)externalSignalingControllerForAccountId:(NSString *)accountId;
|
||||
- (void)connectDisconnectedExternalSignalingControllers;
|
||||
- (void)disconnectAllExternalSignalingControllers;
|
||||
- (void)subscribeForPushNotificationsForAccountId:(NSString *)accountId withCompletionBlock:(SubscribeForPushNotificationsCompletionBlock)block;
|
||||
- (NSInteger)chatMaxLengthConfigCapability;
|
||||
- (BOOL)canCreateGroupAndPublicRooms;
|
||||
|
|
|
@ -419,6 +419,22 @@ NSString * const kDidReceiveCallsFromOldAccount = @"receivedCallsFromOldAccount"
|
|||
return [_externalSignalingControllers objectForKey:accountId];
|
||||
}
|
||||
|
||||
- (void)connectDisconnectedExternalSignalingControllers
|
||||
{
|
||||
for (NCExternalSignalingController *extSignalingController in self->_externalSignalingControllers.allValues) {
|
||||
if (extSignalingController.disconnected) {
|
||||
[extSignalingController connect];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)disconnectAllExternalSignalingControllers
|
||||
{
|
||||
for (NCExternalSignalingController *extSignalingController in self->_externalSignalingControllers.allValues) {
|
||||
[extSignalingController disconnect];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Server Capabilities
|
||||
|
||||
- (void)getCapabilitiesWithCompletionBlock:(GetCapabilitiesCompletionBlock)block;
|
||||
|
|
Загрузка…
Ссылка в новой задаче