Implemented proper resume

This commit is contained in:
Mario Danic 2018-10-25 01:22:26 +02:00
parent 3ec2480848
commit f0017a2a39
4 changed files with 17 additions and 15 deletions

View file

@ -1195,7 +1195,7 @@ public class CallController extends BaseController {
webSocketConnectionHelper = new WebSocketConnectionHelper();
webSocketClient = webSocketConnectionHelper.getExternalSignalingInstanceForServer(
externalSignalingServer.getExternalSignalingServer(),
conversationUser, externalSignalingServer.getExternalSignalingTicket());
conversationUser, externalSignalingServer.getExternalSignalingTicket(), false);
if (webSocketClient.isConnected()) {
joinRoomAndCall();

View file

@ -67,7 +67,7 @@ public class WebsocketConnectionsWorker extends Worker {
!TextUtils.isEmpty(externalSignalingServer.getExternalSignalingTicket())) {
webSocketConnectionHelper.getExternalSignalingInstanceForServer(
externalSignalingServer.getExternalSignalingServer(),
userEntity, externalSignalingServer.getExternalSignalingTicket());
userEntity, externalSignalingServer.getExternalSignalingTicket(), false);
}
} catch (IOException e) {
Log.e(TAG, "Failed to parse external signaling server");

View file

@ -71,19 +71,20 @@ public class MagicWebSocketInstance extends WebSocketListener {
private WebSocketConnectionHelper webSocketConnectionHelper;
private WebSocket webSocket;
private MagicMap magicMap;
private String connectionUrl;
private String currentRoomToken;
MagicWebSocketInstance(UserEntity conversationUser, String connectionUrl, String webSocketTicket) {
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
Request request = new Request.Builder().url(connectionUrl).build();
this.webSocket = okHttpClient.newWebSocket(request, this);
this.connectionUrl = connectionUrl;
this.conversationUser = conversationUser;
this.webSocketTicket = webSocketTicket;
this.webSocketConnectionHelper = new WebSocketConnectionHelper();
magicMap = new MagicMap();
restartWebSocket();
}
@Override
@ -99,6 +100,11 @@ public class MagicWebSocketInstance extends WebSocketListener {
}
}
private void restartWebSocket() {
Request request = new Request.Builder().url(connectionUrl).build();
this.webSocket = okHttpClient.newWebSocket(request, this);
}
@Override
public void onMessage(WebSocket webSocket, String text) {
Log.d(TAG, "Receiving : " + text);
@ -121,6 +127,7 @@ public class MagicWebSocketInstance extends WebSocketListener {
resumeId = "";
}
restartWebSocket();
break;
case "room":
JoinedRoomOverallWebSocketMessage joinedRoomOverallWebSocketMessage = LoganSquare.parse(text, JoinedRoomOverallWebSocketMessage.class);
@ -198,6 +205,7 @@ public class MagicWebSocketInstance extends WebSocketListener {
public void onFailure(WebSocket webSocket, Throwable t, Response response) {
Log.d(TAG, "Error : " + t.getMessage());
connected = false;
restartWebSocket();
}
public String getSessionId() {

View file

@ -57,7 +57,7 @@ public class WebSocketConnectionHelper {
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
}
private static String getExternalSignalingServerUrlFromSettingsUrl(String url) {
public static synchronized MagicWebSocketInstance getExternalSignalingInstanceForServer(String url, UserEntity userEntity, String webSocketTicket, boolean forceReconnect) {
String generatedURL = url.replace("https://", "wss://").replace("http://", "ws://");
if (generatedURL.endsWith("/")) {
@ -66,17 +66,10 @@ public class WebSocketConnectionHelper {
generatedURL += "/spreed";
}
return generatedURL;
}
public static synchronized MagicWebSocketInstance getExternalSignalingInstanceForServer(String url, UserEntity userEntity, String webSocketTicket) {
String connectionUrl = getExternalSignalingServerUrlFromSettingsUrl(url);
if (magicWebSocketInstanceMap.containsKey(userEntity.getUserId())) {
if (magicWebSocketInstanceMap.containsKey(userEntity.getUserId()) && !forceReconnect) {
return magicWebSocketInstanceMap.get(userEntity.getUserId());
} else {
MagicWebSocketInstance magicWebSocketInstance = new MagicWebSocketInstance(userEntity, connectionUrl, webSocketTicket);
MagicWebSocketInstance magicWebSocketInstance = new MagicWebSocketInstance(userEntity, generatedURL, webSocketTicket);
magicWebSocketInstanceMap.put(userEntity.getUserId(), magicWebSocketInstance);
return magicWebSocketInstance;
}
@ -104,6 +97,7 @@ public class WebSocketConnectionHelper {
HelloWebSocketMessage helloWebSocketMessage = new HelloWebSocketMessage();
helloWebSocketMessage.setVersion("1.0");
helloWebSocketMessage.setResumeid(resumeId);
helloOverallWebSocketMessage.setHelloWebSocketMessage(helloWebSocketMessage);
return helloOverallWebSocketMessage;
}