Signed-off-by: Mario Danic <mario@lovelyhq.com>

# Conflicts:
#	app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java
This commit is contained in:
Mario Danic 2019-02-21 10:43:41 +01:00
parent d81707b496
commit f5e7ad6a33
5 changed files with 24 additions and 12 deletions

View file

@ -220,11 +220,7 @@ public class CallController extends BaseController {
conversationPassword = args.getString(BundleKeys.KEY_CONVERSATION_PASSWORD, ""); conversationPassword = args.getString(BundleKeys.KEY_CONVERSATION_PASSWORD, "");
isVoiceOnlyCall = args.getBoolean(BundleKeys.KEY_CALL_VOICE_ONLY, false); isVoiceOnlyCall = args.getBoolean(BundleKeys.KEY_CALL_VOICE_ONLY, false);
if (conversationUser.getUserId().equals("?")) {
credentials = null;
} else {
credentials = ApiUtils.getCredentials(conversationUser.getUsername(), conversationUser.getToken()); credentials = ApiUtils.getCredentials(conversationUser.getUsername(), conversationUser.getToken());
}
baseUrl = args.getString(BundleKeys.KEY_MODIFIED_BASE_URL, ""); baseUrl = args.getString(BundleKeys.KEY_MODIFIED_BASE_URL, "");
@ -1158,7 +1154,8 @@ 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(),
TextUtils.isEmpty(credentials));
if (webSocketClient.isConnected()) { if (webSocketClient.isConnected()) {
joinRoomAndCall(); joinRoomAndCall();
@ -1336,6 +1333,11 @@ public class CallController extends BaseController {
localAudioTrack = null; localAudioTrack = null;
localVideoTrack = null; localVideoTrack = null;
if (TextUtils.isEmpty(credentials) && hasExternalSignalingServer) {
WebSocketConnectionHelper.deleteExternalSignalingInstanceForUserEntity(-1);
}
if (!dueToNetworkChange) { if (!dueToNetworkChange) {
hangupNetworkCalls(); hangupNetworkCalls();
} else { } else {

View file

@ -892,7 +892,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
chatMessage.setLinkPreviewAllowed(isLinkPreviewAllowed); chatMessage.setLinkPreviewAllowed(isLinkPreviewAllowed);
// if credentials are empty, we're acting as a guest // if credentials are empty, we're acting as a guest
if (TextUtils.isEmpty(credentials) && !TextUtils.isEmpty(myFirstMessage.toString())) { if (TextUtils.isEmpty(credentials) && myFirstMessage != null && !TextUtils.isEmpty(myFirstMessage.toString())) {
if (chatMessage.getActorType().equals("guests")) { if (chatMessage.getActorType().equals("guests")) {
conversationUser.setUserId(chatMessage.getActorId()); conversationUser.setUserId(chatMessage.getActorId());
setSenderId(); setSenderId();

View file

@ -70,7 +70,8 @@ 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

@ -20,8 +20,8 @@
package com.nextcloud.talk.utils; package com.nextcloud.talk.utils;
import android.net.Uri; import android.net.Uri;
import androidx.annotation.DimenRes;
import androidx.annotation.Nullable; import android.text.TextUtils;
import com.nextcloud.talk.BuildConfig; import com.nextcloud.talk.BuildConfig;
import com.nextcloud.talk.R; import com.nextcloud.talk.R;
import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.application.NextcloudTalkApplication;
@ -209,6 +209,9 @@ public class ApiUtils {
} }
public static String getCredentials(String username, String token) { public static String getCredentials(String username, String token) {
if (TextUtils.isEmpty(username) && TextUtils.isEmpty(token)) {
return null;
}
return Credentials.basic(username, token); return Credentials.basic(username, token);
} }

View file

@ -44,7 +44,7 @@ public class WebSocketConnectionHelper {
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
} }
public static synchronized MagicWebSocketInstance getExternalSignalingInstanceForServer(String url, UserEntity userEntity, String webSocketTicket) { public static synchronized MagicWebSocketInstance getExternalSignalingInstanceForServer(String url, UserEntity userEntity, String webSocketTicket, boolean isGuest) {
String generatedURL = url.replace("https://", "wss://").replace("http://", "ws://"); String generatedURL = url.replace("https://", "wss://").replace("http://", "ws://");
if (generatedURL.endsWith("/")) { if (generatedURL.endsWith("/")) {
@ -53,10 +53,16 @@ public class WebSocketConnectionHelper {
generatedURL += "/spreed"; generatedURL += "/spreed";
} }
long userId = isGuest ? -1 : userEntity.getId();
MagicWebSocketInstance magicWebSocketInstance; MagicWebSocketInstance magicWebSocketInstance;
if (magicWebSocketInstanceMap.containsKey(userEntity.getId()) && (magicWebSocketInstance = magicWebSocketInstanceMap.get(userEntity.getId())) != null && !magicWebSocketInstance.isPermanentlyClosed()) { if (userId != -1 && magicWebSocketInstanceMap.containsKey(userEntity.getId()) && (magicWebSocketInstance = magicWebSocketInstanceMap.get(userEntity.getId())) != null && !magicWebSocketInstance.isPermanentlyClosed()) {
return magicWebSocketInstance; return magicWebSocketInstance;
} else { } else {
if (userId == -1) {
deleteExternalSignalingInstanceForUserEntity(userId);
}
magicWebSocketInstance = new MagicWebSocketInstance(userEntity, generatedURL, webSocketTicket); magicWebSocketInstance = new MagicWebSocketInstance(userEntity, generatedURL, webSocketTicket);
magicWebSocketInstanceMap.put(userEntity.getId(), magicWebSocketInstance); magicWebSocketInstanceMap.put(userEntity.getId(), magicWebSocketInstance);
return magicWebSocketInstance; return magicWebSocketInstance;