From 12cfd70a8acb11b6f94cc2b2be21233f483c85ee Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 14 Jul 2023 17:26:44 +0200 Subject: [PATCH] check if existing websocket is Connected + refactoring Signed-off-by: Marcel Hibbe --- .../webrtc/WebSocketConnectionHelper.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketConnectionHelper.java b/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketConnectionHelper.java index 43f4ef64a..762a9e577 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketConnectionHelper.java +++ b/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketConnectionHelper.java @@ -82,19 +82,19 @@ public class WebSocketConnectionHelper { long userId = isGuest ? -1 : user.getId(); - WebSocketInstance webSocketInstance; - if (userId != -1 && webSocketInstanceMap.containsKey(user.getId()) && (webSocketInstance = webSocketInstanceMap.get(user.getId())) != null) { - Log.d(TAG, "webSocketInstanceMap already contained webSocketInstance for userId " + user.getId()); - return webSocketInstance; - } else { - if (userId == -1) { - deleteExternalSignalingInstanceForUserEntity(userId); - } - webSocketInstance = new WebSocketInstance(user, generatedURL, webSocketTicket); - Log.d(TAG, "created new webSocketInstance for userId " + user.getId()); - webSocketInstanceMap.put(user.getId(), webSocketInstance); + WebSocketInstance webSocketInstance = webSocketInstanceMap.get(user.getId()); + + if (userId != -1 && webSocketInstance != null && webSocketInstance.isConnected()) { return webSocketInstance; } + + if (userId == -1) { + deleteExternalSignalingInstanceForUserEntity(userId); + } + + webSocketInstance = new WebSocketInstance(user, generatedURL, webSocketTicket); + webSocketInstanceMap.put(user.getId(), webSocketInstance); + return webSocketInstance; } public static synchronized void deleteExternalSignalingInstanceForUserEntity(long id) { @@ -108,7 +108,7 @@ public class WebSocketConnectionHelper { } HelloOverallWebSocketMessage getAssembledHelloModel(User user, String ticket) { - int apiVersion = ApiUtils.getSignalingApiVersion(user, new int[] {ApiUtils.APIv3, 2, 1}); + int apiVersion = ApiUtils.getSignalingApiVersion(user, new int[]{ApiUtils.APIv3, 2, 1}); HelloOverallWebSocketMessage helloOverallWebSocketMessage = new HelloOverallWebSocketMessage(); helloOverallWebSocketMessage.setType("hello");