From 98cabbfc1106f99fbcfa8e3e2d12006062336549 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Fri, 26 Oct 2018 15:53:22 +0200 Subject: [PATCH] Fix nickname & fonts --- .../main}/assets/fonts/Nunito-Black.ttf | Bin .../main}/assets/fonts/Nunito-BlackItalic.ttf | Bin .../main}/assets/fonts/Nunito-Bold.ttf | Bin .../main}/assets/fonts/Nunito-BoldItalic.ttf | Bin .../main}/assets/fonts/Nunito-ExtraBold.ttf | Bin .../assets/fonts/Nunito-ExtraBoldItalic.ttf | Bin .../main}/assets/fonts/Nunito-ExtraLight.ttf | Bin .../assets/fonts/Nunito-ExtraLightItalic.ttf | Bin .../main}/assets/fonts/Nunito-Italic.ttf | Bin .../main}/assets/fonts/Nunito-Light.ttf | Bin .../main}/assets/fonts/Nunito-LightItalic.ttf | Bin .../main}/assets/fonts/Nunito-Regular.ttf | Bin .../main}/assets/fonts/Nunito-SemiBold.ttf | Bin .../assets/fonts/Nunito-SemiBoldItalic.ttf | Bin .../main}/assets/fonts/NunitoHeavy-Italic.ttf | Bin .../assets/fonts/NunitoHeavy-Regular.ttf | Bin .../talk/controllers/CallController.java | 52 ++++++++++++++---- .../json/signaling/DataChannelMessage.java | 2 +- .../webrtc/MagicPeerConnectionWrapper.java | 17 +++++- .../talk/webrtc/MagicWebSocketInstance.java | 28 ++++++++++ 20 files changed, 84 insertions(+), 15 deletions(-) rename app/{ => src/main}/assets/fonts/Nunito-Black.ttf (100%) rename app/{ => src/main}/assets/fonts/Nunito-BlackItalic.ttf (100%) rename app/{ => src/main}/assets/fonts/Nunito-Bold.ttf (100%) rename app/{ => src/main}/assets/fonts/Nunito-BoldItalic.ttf (100%) rename app/{ => src/main}/assets/fonts/Nunito-ExtraBold.ttf (100%) rename app/{ => src/main}/assets/fonts/Nunito-ExtraBoldItalic.ttf (100%) rename app/{ => src/main}/assets/fonts/Nunito-ExtraLight.ttf (100%) rename app/{ => src/main}/assets/fonts/Nunito-ExtraLightItalic.ttf (100%) rename app/{ => src/main}/assets/fonts/Nunito-Italic.ttf (100%) rename app/{ => src/main}/assets/fonts/Nunito-Light.ttf (100%) rename app/{ => src/main}/assets/fonts/Nunito-LightItalic.ttf (100%) rename app/{ => src/main}/assets/fonts/Nunito-Regular.ttf (100%) rename app/{ => src/main}/assets/fonts/Nunito-SemiBold.ttf (100%) rename app/{ => src/main}/assets/fonts/Nunito-SemiBoldItalic.ttf (100%) rename app/{ => src/main}/assets/fonts/NunitoHeavy-Italic.ttf (100%) rename app/{ => src/main}/assets/fonts/NunitoHeavy-Regular.ttf (100%) diff --git a/app/assets/fonts/Nunito-Black.ttf b/app/src/main/assets/fonts/Nunito-Black.ttf similarity index 100% rename from app/assets/fonts/Nunito-Black.ttf rename to app/src/main/assets/fonts/Nunito-Black.ttf diff --git a/app/assets/fonts/Nunito-BlackItalic.ttf b/app/src/main/assets/fonts/Nunito-BlackItalic.ttf similarity index 100% rename from app/assets/fonts/Nunito-BlackItalic.ttf rename to app/src/main/assets/fonts/Nunito-BlackItalic.ttf diff --git a/app/assets/fonts/Nunito-Bold.ttf b/app/src/main/assets/fonts/Nunito-Bold.ttf similarity index 100% rename from app/assets/fonts/Nunito-Bold.ttf rename to app/src/main/assets/fonts/Nunito-Bold.ttf diff --git a/app/assets/fonts/Nunito-BoldItalic.ttf b/app/src/main/assets/fonts/Nunito-BoldItalic.ttf similarity index 100% rename from app/assets/fonts/Nunito-BoldItalic.ttf rename to app/src/main/assets/fonts/Nunito-BoldItalic.ttf diff --git a/app/assets/fonts/Nunito-ExtraBold.ttf b/app/src/main/assets/fonts/Nunito-ExtraBold.ttf similarity index 100% rename from app/assets/fonts/Nunito-ExtraBold.ttf rename to app/src/main/assets/fonts/Nunito-ExtraBold.ttf diff --git a/app/assets/fonts/Nunito-ExtraBoldItalic.ttf b/app/src/main/assets/fonts/Nunito-ExtraBoldItalic.ttf similarity index 100% rename from app/assets/fonts/Nunito-ExtraBoldItalic.ttf rename to app/src/main/assets/fonts/Nunito-ExtraBoldItalic.ttf diff --git a/app/assets/fonts/Nunito-ExtraLight.ttf b/app/src/main/assets/fonts/Nunito-ExtraLight.ttf similarity index 100% rename from app/assets/fonts/Nunito-ExtraLight.ttf rename to app/src/main/assets/fonts/Nunito-ExtraLight.ttf diff --git a/app/assets/fonts/Nunito-ExtraLightItalic.ttf b/app/src/main/assets/fonts/Nunito-ExtraLightItalic.ttf similarity index 100% rename from app/assets/fonts/Nunito-ExtraLightItalic.ttf rename to app/src/main/assets/fonts/Nunito-ExtraLightItalic.ttf diff --git a/app/assets/fonts/Nunito-Italic.ttf b/app/src/main/assets/fonts/Nunito-Italic.ttf similarity index 100% rename from app/assets/fonts/Nunito-Italic.ttf rename to app/src/main/assets/fonts/Nunito-Italic.ttf diff --git a/app/assets/fonts/Nunito-Light.ttf b/app/src/main/assets/fonts/Nunito-Light.ttf similarity index 100% rename from app/assets/fonts/Nunito-Light.ttf rename to app/src/main/assets/fonts/Nunito-Light.ttf diff --git a/app/assets/fonts/Nunito-LightItalic.ttf b/app/src/main/assets/fonts/Nunito-LightItalic.ttf similarity index 100% rename from app/assets/fonts/Nunito-LightItalic.ttf rename to app/src/main/assets/fonts/Nunito-LightItalic.ttf diff --git a/app/assets/fonts/Nunito-Regular.ttf b/app/src/main/assets/fonts/Nunito-Regular.ttf similarity index 100% rename from app/assets/fonts/Nunito-Regular.ttf rename to app/src/main/assets/fonts/Nunito-Regular.ttf diff --git a/app/assets/fonts/Nunito-SemiBold.ttf b/app/src/main/assets/fonts/Nunito-SemiBold.ttf similarity index 100% rename from app/assets/fonts/Nunito-SemiBold.ttf rename to app/src/main/assets/fonts/Nunito-SemiBold.ttf diff --git a/app/assets/fonts/Nunito-SemiBoldItalic.ttf b/app/src/main/assets/fonts/Nunito-SemiBoldItalic.ttf similarity index 100% rename from app/assets/fonts/Nunito-SemiBoldItalic.ttf rename to app/src/main/assets/fonts/Nunito-SemiBoldItalic.ttf diff --git a/app/assets/fonts/NunitoHeavy-Italic.ttf b/app/src/main/assets/fonts/NunitoHeavy-Italic.ttf similarity index 100% rename from app/assets/fonts/NunitoHeavy-Italic.ttf rename to app/src/main/assets/fonts/NunitoHeavy-Italic.ttf diff --git a/app/assets/fonts/NunitoHeavy-Regular.ttf b/app/src/main/assets/fonts/NunitoHeavy-Regular.ttf similarity index 100% rename from app/assets/fonts/NunitoHeavy-Regular.ttf rename to app/src/main/assets/fonts/NunitoHeavy-Regular.ttf diff --git a/app/src/main/java/com/nextcloud/talk/controllers/CallController.java b/app/src/main/java/com/nextcloud/talk/controllers/CallController.java index 79b58a564..086d999db 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/CallController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/CallController.java @@ -132,6 +132,7 @@ import butterknife.OnClick; import butterknife.OnLongClick; import eu.davidea.flipview.FlipView; import io.reactivex.Observer; +import io.reactivex.Scheduler; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; @@ -247,6 +248,7 @@ public class CallController extends BaseController { private MagicWebSocketInstance webSocketClient; private WebSocketConnectionHelper webSocketConnectionHelper; private boolean hasMCU; + private boolean hasExternalSignalingServer; public CallController(Bundle args) { super(args); @@ -921,11 +923,27 @@ public class CallController extends BaseController { if (signalingSettingsOverall != null && signalingSettingsOverall.getOcs() != null && signalingSettingsOverall.getOcs().getSettings() != null) { + externalSignalingServer = new ExternalSignalingServer(); + if (!TextUtils.isEmpty(signalingSettingsOverall.getOcs().getSettings().getExternalSignalingServer()) && !TextUtils.isEmpty(signalingSettingsOverall.getOcs().getSettings().getExternalSignalingTicket())) { externalSignalingServer = new ExternalSignalingServer(); externalSignalingServer.setExternalSignalingServer(signalingSettingsOverall.getOcs().getSettings().getExternalSignalingServer()); externalSignalingServer.setExternalSignalingTicket(signalingSettingsOverall.getOcs().getSettings().getExternalSignalingTicket()); + hasExternalSignalingServer = true; + } else { + hasExternalSignalingServer = false; + } + + if (!conversationUser.getUserId().equals("?")) { + try { + userUtils.createOrUpdateUser(null, null, null, null, null, null, null, + conversationUser.getId(), null, null, LoganSquare.serialize(externalSignalingServer)) + .subscribeOn(Schedulers.newThread()) + .subscribe(); + } catch (IOException exception) { + Log.e(TAG, "Failed to serialize external signaling server"); + } } if (signalingSettingsOverall.getOcs().getSettings().getStunServers() != null) { @@ -1004,7 +1022,7 @@ public class CallController extends BaseController { .getCapabilities().getSpreedCapability() .getFeatures().contains("no-ping")); - if (externalSignalingServer == null) { + if (!hasExternalSignalingServer) { joinRoomAndCall(); } else { setupAndInitiateWebSocketsConnection(); @@ -1057,7 +1075,7 @@ public class CallController extends BaseController { } private void callOrJoinRoomViaWebSocket() { - if (externalSignalingServer == null) { + if (!hasExternalSignalingServer) { performCall(); } else { webSocketClient.joinRoomWithRoomTokenAndSession(roomToken, callSession); @@ -1132,7 +1150,7 @@ public class CallController extends BaseController { NotificationUtils.cancelExistingNotifications(getApplicationContext(), conversationUser); - if (externalSignalingServer == null) { + if (!hasExternalSignalingServer) { ncApi.pullSignalingMessages(credentials, ApiUtils.getUrlForSignaling(baseUrl, urlToken)) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) @@ -1379,7 +1397,7 @@ public class CallController extends BaseController { @Override public void onNext(GenericOverall genericOverall) { - if (externalSignalingServer != null) { + if (hasExternalSignalingServer) { webSocketClient.joinRoomWithRoomTokenAndSession("", ""); } @@ -1480,7 +1498,7 @@ public class CallController extends BaseController { } for (String sessionId : newSessions) { - if (externalSignalingServer != null && webSocketClient.hasMCU()) { + if (hasExternalSignalingServer && webSocketClient.hasMCU()) { if (!sessionId.equals(webSocketClient.getSessionId())) { alwaysGetPeerConnectionWrapperForSessionId(sessionId, false); @@ -1619,7 +1637,7 @@ public class CallController extends BaseController { } } else if (peerConnectionEvent.getPeerConnectionEventType().equals(PeerConnectionEvent .PeerConnectionEventType.NICK_CHANGE)) { - gotNick(peerConnectionEvent.getSessionId(), peerConnectionEvent.getNick()); + gotNick(peerConnectionEvent.getSessionId(), peerConnectionEvent.getNick(), true); } else if (peerConnectionEvent.getPeerConnectionEventType().equals(PeerConnectionEvent .PeerConnectionEventType.VIDEO_CHANGE) && !isVoiceOnlyCall) { gotAudioOrVideoChange(true, peerConnectionEvent.getSessionId(), @@ -1667,7 +1685,7 @@ public class CallController extends BaseController { ncMessageWrapper.setSignalingMessage(ncSignalingMessage); - if (externalSignalingServer == null) { + if (!hasExternalSignalingServer) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("{") .append("\"fn\":\"") @@ -1836,7 +1854,12 @@ public class CallController extends BaseController { surfaceViewRenderer.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT); surfaceViewRenderer.setOnClickListener(videoOnClickListener); remoteRenderersLayout.addView(relativeLayout); - gotNick(session, getPeerConnectionWrapperForSessionId(session).getNick()); + if (hasExternalSignalingServer) { + gotNick(session, webSocketClient.getDisplayNameForSession(session), false); + } else { + gotNick(session, getPeerConnectionWrapperForSessionId(session).getNick(), false); + } + setupAvatarForSession(session); callControls.setZ(100.0f); @@ -1844,11 +1867,18 @@ public class CallController extends BaseController { } } - private void gotNick(String sessionId, String nick) { - RelativeLayout relativeLayout = remoteRenderersLayout.findViewWithTag(sessionId); + private void gotNick(String sessionOrUserId, String nick, boolean isFromAnEvent) { + if (isFromAnEvent && hasExternalSignalingServer) { + // get session based on userId + sessionOrUserId = webSocketClient.getSessionForUserId(sessionOrUserId); + } + if (relativeLayout != null) { + RelativeLayout relativeLayout = remoteRenderersLayout.findViewWithTag(sessionOrUserId); TextView textView = relativeLayout.findViewById(R.id.peer_nick_text_view); - textView.setText(nick); + if (!textView.getText().equals(nick)) { + textView.setText(nick); + } } } diff --git a/app/src/main/java/com/nextcloud/talk/models/json/signaling/DataChannelMessage.java b/app/src/main/java/com/nextcloud/talk/models/json/signaling/DataChannelMessage.java index 394b0fc27..ca1e88c19 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/signaling/DataChannelMessage.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/signaling/DataChannelMessage.java @@ -32,7 +32,7 @@ public class DataChannelMessage { String type; @JsonField(name = "payload") - String payload; + Object payload; public DataChannelMessage(String type) { this.type = type; diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/MagicPeerConnectionWrapper.java b/app/src/main/java/com/nextcloud/talk/webrtc/MagicPeerConnectionWrapper.java index 08101c8c7..69902f387 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/MagicPeerConnectionWrapper.java +++ b/app/src/main/java/com/nextcloud/talk/webrtc/MagicPeerConnectionWrapper.java @@ -233,10 +233,21 @@ public class MagicPeerConnectionWrapper { try { DataChannelMessage dataChannelMessage = LoganSquare.parse(strData, DataChannelMessage.class); + String internalNick; if ("nickChanged".equals(dataChannelMessage.getType())) { - nick = dataChannelMessage.getPayload(); - EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType - .NICK_CHANGE, sessionId, nick, null)); + if (dataChannelMessage.getPayload() instanceof String) { + internalNick = (String) dataChannelMessage.getPayload(); + if (!internalNick.equals(nick)) { + setNick(nick); + EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType + .NICK_CHANGE, sessionId, getNick(), null)); + } + } else { + HashMap payloadHashMap = (HashMap) dataChannelMessage.getPayload(); + EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType + .NICK_CHANGE, payloadHashMap.get("userid"), payloadHashMap.get("name"), null)); + } + } else if ("audioOn".equals(dataChannelMessage.getType())) { remoteAudioOn = true; EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java b/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java index abf954bea..14529ee5f 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java +++ b/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java @@ -37,10 +37,13 @@ import com.nextcloud.talk.models.json.websocket.HelloResponseOverallWebSocketMes import com.nextcloud.talk.models.json.websocket.JoinedRoomOverallWebSocketMessage; import com.nextcloud.talk.utils.MagicMap; +import com.nextcloud.talk.R; + import org.greenrobot.eventbus.EventBus; import java.io.IOException; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.inject.Inject; @@ -78,6 +81,9 @@ public class MagicWebSocketInstance extends WebSocketListener { private boolean isPermanentlyClosed = false; private int restartCount = 0; + private HashMap displayNameHashMap; + private HashMap userIdSesssionHashMap; + MagicWebSocketInstance(UserEntity conversationUser, String connectionUrl, String webSocketTicket) { NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); @@ -85,6 +91,7 @@ public class MagicWebSocketInstance extends WebSocketListener { this.conversationUser = conversationUser; this.webSocketTicket = webSocketTicket; this.webSocketConnectionHelper = new WebSocketConnectionHelper(); + this.displayNameHashMap = new HashMap<>(); magicMap = new MagicMap(); restartWebSocket(); @@ -166,6 +173,15 @@ public class MagicWebSocketInstance extends WebSocketListener { } } } + } else if (eventOverallWebSocketMessage.getEventMap().get("type").equals("join")) { + List> joinEventMap = (List>) eventOverallWebSocketMessage.getEventMap().get("join"); + HashMap internalHashMap; + for (int i = 0; i < joinEventMap.size(); i++) { + internalHashMap = joinEventMap.get(i); + HashMap userMap = (HashMap) internalHashMap.get("user"); + displayNameHashMap.put((String) internalHashMap.get("sessionid"), (String) userMap.get("displayname")); + userIdSesssionHashMap.put((String) internalHashMap.get("userid"), (String) internalHashMap.get("sessionid")); + } } break; case "participants": @@ -291,4 +307,16 @@ public class MagicWebSocketInstance extends WebSocketListener { boolean isPermanentlyClosed() { return isPermanentlyClosed; } + + public String getDisplayNameForSession(String session) { + if (displayNameHashMap.containsKey(session)) { + return displayNameHashMap.get(session); + } + + return NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_nick_guest); + } + + public String getSessionForUserId(String userId) { + return userIdSesssionHashMap.get(userId); + } }