Merge pull request #1025 from nextcloud/websocket-background-fixes

Websocket background fixes
This commit is contained in:
Ivan Sein 2022-12-23 10:23:25 +01:00 коммит произвёл GitHub
Родитель 21ff39d4e2 9893102cf2
Коммит 946b7b48f2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 20 добавлений и 2 удалений

Просмотреть файл

@ -470,7 +470,12 @@
[[NCSettingsController sharedInstance] disconnectAllExternalSignalingControllers];
}
[self->_keepAliveBGTask stopBackgroundTask];
// Disconnect is dispatched to the main queue, so in theory it can happen that we stop the background task
// before the disconnect is run/completed. So we dispatch the stopBackgroundTask to main as well
// to be sure it's called after everything else is run.
dispatch_async(dispatch_get_main_queue(), ^{
[self->_keepAliveBGTask stopBackgroundTask];
});
}];
[[NSRunLoop mainRunLoop] addTimer:_keepAliveTimer forMode:NSRunLoopCommonModes];

Просмотреть файл

@ -137,7 +137,7 @@ static NSTimeInterval kWebSocketTimeoutInterval = 15;
_messageId = 1;
_messagesWithCompletionBlocks = [NSMutableArray new];
_helloResponseReceived = NO;
NSLog(@"Connecting to: %@", _serverUrl);
[NCUtils log:[NSString stringWithFormat:@"Connecting to: %@", _serverUrl]];
NSURL *url = [NSURL URLWithString:_serverUrl];
NSURLSession *wsSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:nil];
NSURLRequest *wsRequest = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:kWebSocketTimeoutInterval];
@ -157,6 +157,8 @@ static NSTimeInterval kWebSocketTimeoutInterval = 15;
return;
}
[NCUtils log:[NSString stringWithFormat:@"Reconnecting to: %@", _serverUrl]];
[self resetWebSocket];
// Execute completion blocks on all messages
@ -177,6 +179,8 @@ static NSTimeInterval kWebSocketTimeoutInterval = 15;
- (void)disconnect
{
[NCUtils log:[NSString stringWithFormat:@"Disconnecting from: %@", _serverUrl]];
dispatch_async(dispatch_get_main_queue(), ^{
[self invalidateReconnectionTimer];
[self resetWebSocket];
@ -352,6 +356,15 @@ static NSTimeInterval kWebSocketTimeoutInterval = 15;
- (void)joinRoom:(NSString *)roomId withSessionId:(NSString *)sessionId withCompletionBlock:(JoinRoomExternalSignalingCompletionBlock)block
{
if (_disconnected) {
[NCUtils log:[NSString stringWithFormat:@"Joining room %@, but the websocket is disconnected.", roomId]];
}
if (_webSocket == nil) {
[NCUtils log:[NSString stringWithFormat:@"Joining room %@, but the websocket is nil.", roomId]];
}
NSDictionary *messageDict = @{
@"type": @"room",
@"room": @{