mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-21 12:39:58 +01:00
Some progress
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
de538437d1
commit
456cc4e85f
@ -50,8 +50,6 @@ import com.nextcloud.talk.api.models.json.signaling.SignalingOverall;
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
import com.nextcloud.talk.events.SessionDescriptionSendEvent;
|
||||
import com.nextcloud.talk.persistence.entities.UserEntity;
|
||||
import com.nextcloud.talk.webrtc.MagicPeerConnectionObserver;
|
||||
import com.nextcloud.talk.webrtc.MagicSdpObserver;
|
||||
import com.nextcloud.talk.webrtc.PeerConnectionWrapper;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
@ -271,16 +269,14 @@ public class CallActivity extends AppCompatActivity {
|
||||
|
||||
//create sdpConstraints
|
||||
sdpConstraints = new MediaConstraints();
|
||||
sdpConstraints.mandatory.add(new MediaConstraints.KeyValuePair("offerToReceiveAudio", "true"));
|
||||
sdpConstraints.mandatory.add(new MediaConstraints.KeyValuePair("offerToReceiveVideo", "true"));
|
||||
sdpConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true"));
|
||||
sdpConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "true"));
|
||||
sdpConstraints.optional.add(new MediaConstraints.KeyValuePair("internalSctpDataChannels", "true"));
|
||||
sdpConstraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true"));
|
||||
|
||||
PeerConnection localPeer = alwaysGetPeerConnectionWrapperForSessionId(callSession, true).
|
||||
getPeerConnection();
|
||||
|
||||
|
||||
|
||||
//creating local mediastream
|
||||
MediaStream stream = peerConnectionFactory.createLocalMediaStream("NCMS");
|
||||
stream.addTrack(localAudioTrack);
|
||||
@ -423,18 +419,18 @@ public class CallActivity extends AppCompatActivity {
|
||||
PeerConnectionWrapper peerConnectionWrapper = alwaysGetPeerConnectionWrapperForSessionId
|
||||
(ncSignalingMessage.getFrom(), ncSignalingMessage.getFrom().equals(callSession));
|
||||
|
||||
Log.d("MARIO_RECEIVING", ncSignalingMessage.getType());
|
||||
switch (ncSignalingMessage.getType()) {
|
||||
case "offer":
|
||||
case "answer":
|
||||
peerConnectionWrapper.setNick(ncSignalingMessage.getPayload().getNick());
|
||||
peerConnectionWrapper.getPeerConnection().setRemoteDescription(new MagicSdpObserver(),
|
||||
peerConnectionWrapper.getPeerConnection().setRemoteDescription(peerConnectionWrapper.getMagicSdpObserver(),
|
||||
new SessionDescription(SessionDescription.Type.fromCanonicalForm(ncSignalingMessage.getType()),
|
||||
ncSignalingMessage
|
||||
.getPayload().getSdp()));
|
||||
if (ncSignalingMessage.getType().equals("offer")) {
|
||||
|
||||
/*if (ncSignalingMessage.getType().equals("offer")) {
|
||||
peerConnectionWrapper.sendMessage(true);
|
||||
}
|
||||
}*/
|
||||
break;
|
||||
case "candidate":
|
||||
NCIceCandidate ncIceCandidate = ncSignalingMessage.getPayload().getIceCandidate();
|
||||
@ -483,10 +479,10 @@ 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.sendMessage(false);
|
||||
connectionWrapper.getPeerConnection().createOffer(connectionWrapper.getMagicSdpObserver(), sdpConstraints);
|
||||
} else {
|
||||
Log.d(TAG, "Waiting for offer");
|
||||
}
|
||||
@ -508,39 +504,9 @@ public class CallActivity extends AppCompatActivity {
|
||||
if ((peerConnectionWrapper = getPeerConnectionWrapperForSessionId(sessionId)) != null) {
|
||||
return peerConnectionWrapper;
|
||||
} else {
|
||||
MagicPeerConnectionObserver magicPeerConnectionObserver;
|
||||
if (isLocalPeer) {
|
||||
magicPeerConnectionObserver = new MagicPeerConnectionObserver() {
|
||||
@Override
|
||||
public void onIceCandidate(IceCandidate iceCandidate) {
|
||||
super.onIceCandidate(iceCandidate);
|
||||
onIceCandidateReceived(true, iceCandidate);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
magicPeerConnectionObserver = new MagicPeerConnectionObserver() {
|
||||
|
||||
@Override
|
||||
public void onIceCandidate(IceCandidate iceCandidate) {
|
||||
super.onIceCandidate(iceCandidate);
|
||||
onIceCandidateReceived(false, iceCandidate);
|
||||
}
|
||||
|
||||
public void onAddStream(MediaStream mediaStream) {
|
||||
super.onAddStream(mediaStream);
|
||||
gotRemoteStream(mediaStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIceGatheringChange(PeerConnection.IceGatheringState iceGatheringState) {
|
||||
super.onIceGatheringChange(iceGatheringState);
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
peerConnectionWrapper = new PeerConnectionWrapper(peerConnectionFactory,
|
||||
iceServers, sdpConstraints, magicPeerConnectionObserver, sessionId, isLocalPeer, callSession);
|
||||
iceServers, sdpConstraints, sessionId, isLocalPeer, callSession);
|
||||
peerConnectionWrapperList.add(peerConnectionWrapper);
|
||||
return peerConnectionWrapper;
|
||||
}
|
||||
@ -670,7 +636,7 @@ public class CallActivity extends AppCompatActivity {
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.BACKGROUND)
|
||||
public void onMessageEvent(SessionDescriptionSendEvent sessionDescriptionSend) {
|
||||
Log.d("MARIO SENDING", sessionDescriptionSend.getType());
|
||||
Log.d("MARIO", "SENDING " + sessionDescriptionSend.getType());
|
||||
String credentials = ApiHelper.getCredentials(userEntity.getUsername(), userEntity.getToken());
|
||||
NCMessageWrapper ncMessageWrapper = new NCMessageWrapper();
|
||||
ncMessageWrapper.setEv("message");
|
||||
|
@ -23,12 +23,15 @@ package com.nextcloud.talk.webrtc;
|
||||
import android.util.Log;
|
||||
|
||||
import com.nextcloud.talk.api.models.json.signaling.DataChannelMessage;
|
||||
import com.nextcloud.talk.api.models.json.signaling.NCIceCandidate;
|
||||
import com.nextcloud.talk.events.MediaStreamEvent;
|
||||
import com.nextcloud.talk.events.SessionDescriptionSendEvent;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.webrtc.DataChannel;
|
||||
import org.webrtc.IceCandidate;
|
||||
import org.webrtc.MediaConstraints;
|
||||
import org.webrtc.MediaStream;
|
||||
import org.webrtc.PeerConnection;
|
||||
import org.webrtc.PeerConnectionFactory;
|
||||
import org.webrtc.SessionDescription;
|
||||
@ -38,6 +41,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PeerConnectionWrapper {
|
||||
private static String TAG = "PeerConnectionWrapper";
|
||||
private static PeerConnection peerConnection;
|
||||
private String sessionId;
|
||||
private String callToken;
|
||||
@ -46,14 +50,39 @@ public class PeerConnectionWrapper {
|
||||
private MediaConstraints mediaConstraints;
|
||||
private DataChannel dataChannel;
|
||||
private MagicSdpObserver magicSdpObserver;
|
||||
|
||||
private MagicPeerConnectionObserver magicPeerConnectionObserver;
|
||||
List<IceCandidate> iceCandidates = new ArrayList<>();
|
||||
|
||||
public PeerConnectionWrapper(PeerConnectionFactory peerConnectionFactory,
|
||||
List<PeerConnection.IceServer> iceServerList,
|
||||
MediaConstraints mediaConstraints,
|
||||
MagicPeerConnectionObserver magicPeerConnectionObserver,
|
||||
String sessionId, boolean isLocalPeer, String callToken) {
|
||||
|
||||
magicPeerConnectionObserver = new MagicPeerConnectionObserver() {
|
||||
@Override
|
||||
public void onAddStream(MediaStream mediaStream) {
|
||||
Log.d("MARIO", "MEDIA STREAM");
|
||||
EventBus.getDefault().post(new MediaStreamEvent(mediaStream));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSignalingChange(PeerConnection.SignalingState signalingState) {
|
||||
Log.d("MARIO", signalingState.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIceCandidate(IceCandidate iceCandidate) {
|
||||
NCIceCandidate ncIceCandidate = new NCIceCandidate();
|
||||
ncIceCandidate.setCandidate(iceCandidate.sdp);
|
||||
ncIceCandidate.setSdpMLineIndex(iceCandidate.sdpMLineIndex);
|
||||
ncIceCandidate.setSdpMid(iceCandidate.sdpMid);
|
||||
EventBus.getDefault().post(new SessionDescriptionSendEvent(null, sessionId, "candidate",
|
||||
ncIceCandidate));
|
||||
Log.d("MARIO", "SENDING REMOTE CANDIDATE");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
peerConnection = peerConnectionFactory.createPeerConnection(iceServerList, mediaConstraints,
|
||||
magicPeerConnectionObserver);
|
||||
this.sessionId = sessionId;
|
||||
@ -63,6 +92,17 @@ public class PeerConnectionWrapper {
|
||||
boolean isInitiator = this.sessionId.compareTo(callToken) < 0;
|
||||
|
||||
magicSdpObserver = new MagicSdpObserver() {
|
||||
@Override
|
||||
public void onCreateFailure(String s) {
|
||||
Log.d(TAG, s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetFailure(String s) {
|
||||
Log.d(TAG, s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateSuccess(SessionDescription sessionDescription) {
|
||||
super.onCreateSuccess(sessionDescription);
|
||||
peerConnection.setLocalDescription(magicSdpObserver, sessionDescription);
|
||||
@ -80,6 +120,7 @@ public class PeerConnectionWrapper {
|
||||
} else {
|
||||
// We've just set remote description, so drain remote
|
||||
// and send local ICE candidates.
|
||||
Log.d("MARIO", "DRAINING CANDIDATES");
|
||||
drainIceCandidates();
|
||||
}
|
||||
} else {
|
||||
@ -88,12 +129,15 @@ public class PeerConnectionWrapper {
|
||||
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));
|
||||
drainIceCandidates();
|
||||
} else {
|
||||
// We've just set remote SDP - do nothing for now -
|
||||
// answer will be created soon.
|
||||
Log.d("MARIO", "CREATING ANSWER");
|
||||
peerConnection.createAnswer(magicSdpObserver, mediaConstraints);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -110,6 +154,10 @@ public class PeerConnectionWrapper {
|
||||
iceCandidates = new ArrayList<>();
|
||||
}
|
||||
|
||||
public MagicSdpObserver getMagicSdpObserver() {
|
||||
return magicSdpObserver;
|
||||
}
|
||||
|
||||
public void addCandidate(IceCandidate iceCandidate) {
|
||||
if (peerConnection.getRemoteDescription() != null) {
|
||||
// queue
|
||||
@ -121,7 +169,6 @@ public class PeerConnectionWrapper {
|
||||
|
||||
public void sendMessage(boolean isAnswer) {
|
||||
|
||||
Log.d("MARIO", "PREPARING " + isAnswer);
|
||||
if (!isAnswer) {
|
||||
peerConnection.createOffer(magicSdpObserver, mediaConstraints);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user