Restructuring

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2017-11-15 18:14:06 +01:00
parent eb9d7ec0d7
commit 3b447ee7d5
4 changed files with 47 additions and 51 deletions

View File

@ -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<NCMessageWrapper> ncMessageWrappers = new ArrayList<>();
ncMessageWrappers.add(ncMessageWrapper);
List<String> 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<GenericOverall>() {
@Override
public void onSubscribe(Disposable d) {
ncApi.sendSignalingMessages(credentials, ApiHelper.getUrlForSignaling(userEntity.getBaseUrl()),
ncMessageWrappers)
.subscribeOn(Schedulers.newThread())
.subscribe(new Observer<Integer>() {
@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() {
}
});
}

View File

@ -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<Integer> sendSignalingMessages(@Header("Authorization") String authorization, @Url String url,
@Body List<NCMessageWrapper> ncMessageWrapper);
Observable<GenericOverall> sendSignalingMessages(@Header("Authorization") String authorization, @Url String url,
@Body List<String> message);
/*
Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /signaling

View File

@ -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) {

View File

@ -46,6 +46,9 @@ public class PeerConnectionWrapper {
List<IceCandidate> iceCandidates = new ArrayList<>();
List<PeerConnection.IceServer> iceServers;
List<IceCandidate> candidatesToSend = new ArrayList<>();
List<SessionDescription> sessionDescriptionsQueue = new ArrayList<>();
List<NCIceCandidate> localCandidates = new ArrayList<>();
List<SessionDescriptionSendEvent> 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<SessionDescription> sessionDescriptionsQueue = new ArrayList<>();
List<NCIceCandidate> localCandidates = new ArrayList<>();
List<SessionDescriptionSendEvent> sessionDescriptionSendEvents = new ArrayList<>();
public PeerConnectionWrapper(PeerConnectionFactory peerConnectionFactory,
List<PeerConnection.IceServer> 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));