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(); webSocketConnectionHelper = new WebSocketConnectionHelper();
webSocketClient = webSocketConnectionHelper.getExternalSignalingInstanceForServer( webSocketClient = webSocketConnectionHelper.getExternalSignalingInstanceForServer(
externalSignalingServer.getExternalSignalingServer(), externalSignalingServer.getExternalSignalingServer(),
conversationUser, externalSignalingServer.getExternalSignalingTicket()); conversationUser, externalSignalingServer.getExternalSignalingTicket(), false);
if (webSocketClient.isConnected()) { if (webSocketClient.isConnected()) {
joinRoomAndCall(); joinRoomAndCall();

View file

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

View file

@ -71,19 +71,20 @@ public class MagicWebSocketInstance extends WebSocketListener {
private WebSocketConnectionHelper webSocketConnectionHelper; private WebSocketConnectionHelper webSocketConnectionHelper;
private WebSocket webSocket; private WebSocket webSocket;
private MagicMap magicMap; private MagicMap magicMap;
private String connectionUrl;
private String currentRoomToken; private String currentRoomToken;
MagicWebSocketInstance(UserEntity conversationUser, String connectionUrl, String webSocketTicket) { MagicWebSocketInstance(UserEntity conversationUser, String connectionUrl, String webSocketTicket) {
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); 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.conversationUser = conversationUser;
this.webSocketTicket = webSocketTicket; this.webSocketTicket = webSocketTicket;
this.webSocketConnectionHelper = new WebSocketConnectionHelper(); this.webSocketConnectionHelper = new WebSocketConnectionHelper();
magicMap = new MagicMap(); magicMap = new MagicMap();
restartWebSocket();
} }
@Override @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 @Override
public void onMessage(WebSocket webSocket, String text) { public void onMessage(WebSocket webSocket, String text) {
Log.d(TAG, "Receiving : " + text); Log.d(TAG, "Receiving : " + text);
@ -121,6 +127,7 @@ public class MagicWebSocketInstance extends WebSocketListener {
resumeId = ""; resumeId = "";
} }
restartWebSocket();
break; break;
case "room": case "room":
JoinedRoomOverallWebSocketMessage joinedRoomOverallWebSocketMessage = LoganSquare.parse(text, JoinedRoomOverallWebSocketMessage.class); 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) { public void onFailure(WebSocket webSocket, Throwable t, Response response) {
Log.d(TAG, "Error : " + t.getMessage()); Log.d(TAG, "Error : " + t.getMessage());
connected = false; connected = false;
restartWebSocket();
} }
public String getSessionId() { public String getSessionId() {

View file

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