check if existing websocket is Connected

+ refactoring

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-07-14 17:26:44 +02:00
parent 832409a255
commit 12cfd70a8a
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B

View file

@ -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");