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

View file

@ -892,7 +892,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
chatMessage.setLinkPreviewAllowed(isLinkPreviewAllowed);
// 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")) {
conversationUser.setUserId(chatMessage.getActorId());
setSenderId();

View file

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

@ -20,8 +20,8 @@
package com.nextcloud.talk.utils;
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.R;
import com.nextcloud.talk.application.NextcloudTalkApplication;
@ -209,6 +209,9 @@ public class ApiUtils {
}
public static String getCredentials(String username, String token) {
if (TextUtils.isEmpty(username) && TextUtils.isEmpty(token)) {
return null;
}
return Credentials.basic(username, token);
}

View file

@ -44,7 +44,7 @@ public class WebSocketConnectionHelper {
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://");
if (generatedURL.endsWith("/")) {
@ -53,10 +53,16 @@ public class WebSocketConnectionHelper {
generatedURL += "/spreed";
}
long userId = isGuest ? -1 : userEntity.getId();
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;
} else {
if (userId == -1) {
deleteExternalSignalingInstanceForUserEntity(userId);
}
magicWebSocketInstance = new MagicWebSocketInstance(userEntity, generatedURL, webSocketTicket);
magicWebSocketInstanceMap.put(userEntity.getId(), magicWebSocketInstance);
return magicWebSocketInstance;