From 3b447ee7d569ce78cd87c63124ba0a8527408619 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Wed, 15 Nov 2017 18:14:06 +0100 Subject: [PATCH] Restructuring Signed-off-by: Mario Danic --- .../talk/activities/CallActivity.java | 54 ++++++++++--------- .../java/com/nextcloud/talk/api/NcApi.java | 5 +- .../events/SessionDescriptionSendEvent.java | 6 ++- .../talk/webrtc/PeerConnectionWrapper.java | 33 ++++-------- 4 files changed, 47 insertions(+), 51 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java index 933ef1c85..ba54a47f3 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java @@ -301,7 +301,7 @@ public class CallActivity extends AppCompatActivity { @Override public void onNext(GenericOverall genericOverall) { callSession = callOverall.getOcs().getData().getSessionId(); - localPeer = alwaysGetPeerConnectionWrapperForSessionId(callSession, true). + localPeer = alwaysGetPeerConnectionWrapperForSessionId(callSession, true). getPeerConnection(); //creating local mediastream @@ -437,7 +437,7 @@ public class CallActivity extends AppCompatActivity { case "candidate": NCIceCandidate ncIceCandidate = ncSignalingMessage.getPayload().getIceCandidate(); IceCandidate iceCandidate = new IceCandidate(ncIceCandidate.getSdpMid(), - ncIceCandidate.getSdpMLineIndex(), ncIceCandidate.getCandidate()); + ncIceCandidate.getSdpMLineIndex(), ncIceCandidate.getCandidate()); peerConnectionWrapper.addCandidate(iceCandidate); break; case "endOfCandidates": @@ -485,7 +485,7 @@ public class CallActivity extends AppCompatActivity { for (String sessionId : newSessions) { if (getPeerConnectionWrapperForSessionId(sessionId) == null) { - if (sessionId.compareTo(callSession) < 0 ) { + if (sessionId.compareTo(callSession) < 0) { PeerConnectionWrapper connectionWrapper = alwaysGetPeerConnectionWrapperForSessionId(sessionId, false); connectionWrapper.getPeerConnection().createAnswer(connectionWrapper.getMagicSdpObserver(), sdpConstraints); @@ -632,7 +632,7 @@ public class CallActivity extends AppCompatActivity { } @Subscribe(threadMode = ThreadMode.BACKGROUND) - public void onMessageEvent(SessionDescriptionSendEvent sessionDescriptionSend) throws IOException { + public void onMessageEvent(SessionDescriptionSendEvent sessionDescriptionSend) { Log.d("MARIO_123", "SENDING " + sessionDescriptionSend.getType()); String credentials = ApiHelper.getCredentials(userEntity.getUsername(), userEntity.getToken()); NCMessageWrapper ncMessageWrapper = new NCMessageWrapper(); @@ -656,35 +656,41 @@ public class CallActivity extends AppCompatActivity { ncSignalingMessage.setPayload(ncMessagePayload); ncMessageWrapper.setSignalingMessage(ncSignalingMessage); - List ncMessageWrappers = new ArrayList<>(); - ncMessageWrappers.add(ncMessageWrapper); + List awesomeJson = new ArrayList<>(); + try { + awesomeJson.add(LoganSquare.serialize(ncMessageWrapper)); - Log.d("MARIO_123", LoganSquare.serialize(ncMessageWrappers)); + Log.d("MARIO_JSON", LoganSquare.serialize(ncMessageWrapper)); + ncApi.sendSignalingMessages(credentials, ApiHelper.getUrlForSignaling(userEntity.getBaseUrl()), + awesomeJson) + .subscribeOn(Schedulers.newThread()) + .subscribe(new Observer() { + @Override + public void onSubscribe(Disposable d) { - ncApi.sendSignalingMessages(credentials, ApiHelper.getUrlForSignaling(userEntity.getBaseUrl()), - ncMessageWrappers) - .subscribeOn(Schedulers.newThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { + } - } + @Override + public void onNext(GenericOverall genericOverall) { - @Override - public void onNext(Integer integer) { + } - } + @Override + public void onError(Throwable e) { - @Override - public void onError(Throwable e) { + } - } + @Override + public void onComplete() { + + } + }); + + } catch (IOException exception) { + Log.d(TAG, exception.getLocalizedMessage()); + } - @Override - public void onComplete() { - } - }); } diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java index 9dd9b98a4..dee8ebc46 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -29,7 +29,6 @@ import com.nextcloud.talk.api.models.json.push.PushRegistrationOverall; import com.nextcloud.talk.api.models.json.rooms.RoomOverall; import com.nextcloud.talk.api.models.json.rooms.RoomsOverall; import com.nextcloud.talk.api.models.json.sharees.ShareesOverall; -import com.nextcloud.talk.api.models.json.signaling.NCMessageWrapper; import com.nextcloud.talk.api.models.json.signaling.SignalingOverall; import com.nextcloud.talk.api.models.json.userprofile.UserProfileOverall; @@ -168,8 +167,8 @@ public interface NcApi { Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /signaling */ @POST - Observable sendSignalingMessages(@Header("Authorization") String authorization, @Url String url, - @Body List ncMessageWrapper); + Observable sendSignalingMessages(@Header("Authorization") String authorization, @Url String url, + @Body List message); /* Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /signaling diff --git a/app/src/main/java/com/nextcloud/talk/events/SessionDescriptionSendEvent.java b/app/src/main/java/com/nextcloud/talk/events/SessionDescriptionSendEvent.java index e0c90c2c1..322ad91a5 100644 --- a/app/src/main/java/com/nextcloud/talk/events/SessionDescriptionSendEvent.java +++ b/app/src/main/java/com/nextcloud/talk/events/SessionDescriptionSendEvent.java @@ -30,10 +30,12 @@ import lombok.Data; @Data public class SessionDescriptionSendEvent { - @Nullable private final SessionDescription sessionDescription; + @Nullable + private final SessionDescription sessionDescription; private final String peerId; private final String type; - @Nullable private final NCIceCandidate ncIceCandidate; + @Nullable + private final NCIceCandidate ncIceCandidate; public SessionDescriptionSendEvent(@Nullable SessionDescription sessionDescription, String peerId, String type, @Nullable NCIceCandidate ncIceCandidate) { diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/PeerConnectionWrapper.java b/app/src/main/java/com/nextcloud/talk/webrtc/PeerConnectionWrapper.java index 0b668ddb3..6a668d799 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/PeerConnectionWrapper.java +++ b/app/src/main/java/com/nextcloud/talk/webrtc/PeerConnectionWrapper.java @@ -46,6 +46,9 @@ public class PeerConnectionWrapper { List iceCandidates = new ArrayList<>(); List iceServers; List candidatesToSend = new ArrayList<>(); + List sessionDescriptionsQueue = new ArrayList<>(); + List localCandidates = new ArrayList<>(); + List sessionDescriptionSendEvents = new ArrayList<>(); private String sessionId; private String callToken; private String nick; @@ -55,10 +58,7 @@ public class PeerConnectionWrapper { private MagicSdpObserver magicSdpObserver; private MagicPeerConnectionObserver magicPeerConnectionObserver; private boolean isInitiator; - List sessionDescriptionsQueue = new ArrayList<>(); - List localCandidates = new ArrayList<>(); - List sessionDescriptionSendEvents = new ArrayList<>(); public PeerConnectionWrapper(PeerConnectionFactory peerConnectionFactory, List iceServerList, MediaConstraints mediaConstraints, @@ -97,12 +97,11 @@ public class PeerConnectionWrapper { @Override public void onIceCandidate(IceCandidate iceCandidate) { - Log.d("MARIO_GENERT", "BLA"); - NCIceCandidate ncIceCandidate = new NCIceCandidate(); - ncIceCandidate.setSdpMid(iceCandidate.sdpMid); - ncIceCandidate.setSdpMLineIndex(iceCandidate.sdpMLineIndex); - ncIceCandidate.setCandidate(iceCandidate.sdp); - localCandidates.add(ncIceCandidate); + NCIceCandidate ncIceCandidate = new NCIceCandidate(); + ncIceCandidate.setSdpMid(iceCandidate.sdpMid); + ncIceCandidate.setSdpMLineIndex(iceCandidate.sdpMLineIndex); + ncIceCandidate.setCandidate(iceCandidate.sdp); + localCandidates.add(ncIceCandidate); } }; @@ -150,23 +149,15 @@ public class PeerConnectionWrapper { // For anwering peer connection we set remote SDP and then // create answer and set local SDP. if (peerConnection.getLocalDescription() != null) { - // We've just set our local SDP so time to send it, drain - // remote and send local ICE candidates. - Log.d("MARIO", "SENDING ANSWER FROM OBSERVER"); EventBus.getDefault().post(new SessionDescriptionSendEvent(peerConnection.getLocalDescription (), sessionId, "answer", null)); + // We've just set our local SDP so time to send it, drain + // remote and send local ICE candidates. } else { - peerConnection.createAnswer(new MagicSdpObserver() { - @Override - public void onCreateSuccess(SessionDescription sessionDescription) { - super.onCreateSuccess(sessionDescription); - peerConnection.setLocalDescription(magicSdpObserver, sessionDescription); - } - - }, mediaConstraints); + peerConnection.createAnswer(magicSdpObserver, mediaConstraints); // We've just set remote SDP - do nothing for now - // answer will be created soon. @@ -183,9 +174,7 @@ public class PeerConnectionWrapper { } - private void sendLocalCandidates() { - Log.d("MARIO", "SENDING LOCAL"); for (NCIceCandidate ncIceCandidate : localCandidates) { EventBus.getDefault().post(new SessionDescriptionSendEvent(null, sessionId, "candidate", ncIceCandidate));