From 0e994d50c51fab8ef9e557b3e92677565275d3d3 Mon Sep 17 00:00:00 2001 From: Ivan Sein Date: Thu, 31 Jan 2019 14:18:11 +0100 Subject: [PATCH] Rejoin room when websocket connection was lost. Signed-off-by: Ivan Sein --- VideoCalls/NCExternalSignalingController.m | 7 +++++++ VideoCalls/NCRoomsManager.h | 1 + VideoCalls/NCRoomsManager.m | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/VideoCalls/NCExternalSignalingController.m b/VideoCalls/NCExternalSignalingController.m index c09f7a66..d5d6c901 100644 --- a/VideoCalls/NCExternalSignalingController.m +++ b/VideoCalls/NCExternalSignalingController.m @@ -10,6 +10,7 @@ #import "SRWebSocket.h" #import "NCAPIController.h" +#import "NCRoomsManager.h" #import "NCSettingsController.h" static NSTimeInterval kInitialReconnectInterval = 1; @@ -215,6 +216,11 @@ NSString * const NCESReceivedParticipantListMessageNotification = @"NCESReceived [self sendMessage:message]; } _pendingMessages = [NSMutableArray new]; + + // Re-join if user was in a room + if (_currentRoom && _sessionId) { + [[NCRoomsManager sharedInstance] rejoinRoom:_currentRoom]; + } } - (void)errorResponseReceived:(NSDictionary *)errorDict @@ -242,6 +248,7 @@ NSString * const NCESReceivedParticipantListMessageNotification = @"NCESReceived - (void)leaveRoom:(NSString *)roomId { if ([_currentRoom isEqualToString:roomId]) { + _currentRoom = nil; [self joinRoom:@"" withSessionId:@""]; } } diff --git a/VideoCalls/NCRoomsManager.h b/VideoCalls/NCRoomsManager.h index 6fc2bbeb..214933f4 100644 --- a/VideoCalls/NCRoomsManager.h +++ b/VideoCalls/NCRoomsManager.h @@ -27,6 +27,7 @@ extern NSString * const NCRoomsManagerDidStartCallNotification; // Room - (void)updateRooms; - (void)updateRoom:(NSString *)token; +- (void)rejoinRoom:(NSString *)token; // Chat - (void)startChatInRoom:(NCRoom *)room; - (void)sendChatMessage:(NSString *)message toRoom:(NCRoom *)room; diff --git a/VideoCalls/NCRoomsManager.m b/VideoCalls/NCRoomsManager.m index b500869a..58774db1 100644 --- a/VideoCalls/NCRoomsManager.m +++ b/VideoCalls/NCRoomsManager.m @@ -109,6 +109,26 @@ NSString * const NCRoomsManagerDidReceiveChatMessagesNotification = @"ChatMess } } +- (void)rejoinRoom:(NSString *)token +{ + NCRoomController *roomController = [_activeRooms objectForKey:token]; + if (roomController) { + _joiningRoom = [token copy]; + _joinRoomTask = [[NCAPIController sharedInstance] joinRoom:token withCompletionBlock:^(NSString *sessionId, NSError *error) { + if (!error) { + roomController.userSessionId = sessionId; + roomController.inChat = YES; + if ([[NCExternalSignalingController sharedInstance] isEnabled]) { + [[NCExternalSignalingController sharedInstance] joinRoom:token withSessionId:sessionId]; + } + } else { + NSLog(@"Could not re-join room. Error: %@", error.description); + } + _joiningRoom = nil; + }]; + } +} + - (void)leaveRoom:(NSString *)token { // Check if leaving the room we are joining