mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-22 13:09:46 +01:00
Real fix for regular calls
This commit is contained in:
parent
498ae0dfc3
commit
f3ff2e247b
@ -30,6 +30,7 @@ import com.nextcloud.talk.application.NextcloudTalkApplication;
|
|||||||
import com.nextcloud.talk.events.MediaStreamEvent;
|
import com.nextcloud.talk.events.MediaStreamEvent;
|
||||||
import com.nextcloud.talk.events.PeerConnectionEvent;
|
import com.nextcloud.talk.events.PeerConnectionEvent;
|
||||||
import com.nextcloud.talk.events.SessionDescriptionSendEvent;
|
import com.nextcloud.talk.events.SessionDescriptionSendEvent;
|
||||||
|
import com.nextcloud.talk.events.WebSocketCommunicationEvent;
|
||||||
import com.nextcloud.talk.models.json.signaling.DataChannelMessage;
|
import com.nextcloud.talk.models.json.signaling.DataChannelMessage;
|
||||||
import com.nextcloud.talk.models.json.signaling.NCIceCandidate;
|
import com.nextcloud.talk.models.json.signaling.NCIceCandidate;
|
||||||
|
|
||||||
@ -50,13 +51,14 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
public class MagicPeerConnectionWrapper {
|
public class MagicPeerConnectionWrapper {
|
||||||
private static String TAG = "MagicPeerConnectionWrapper";
|
private static String TAG = "MagicPeerConnectionWrapper";
|
||||||
List<IceCandidate> iceCandidates = new ArrayList<>();
|
private List<IceCandidate> iceCandidates = new ArrayList<>();
|
||||||
private PeerConnection peerConnection;
|
private PeerConnection peerConnection;
|
||||||
private String sessionId;
|
private String sessionId;
|
||||||
private String nick;
|
private String nick;
|
||||||
private String userId;
|
|
||||||
private MediaConstraints mediaConstraints;
|
private MediaConstraints mediaConstraints;
|
||||||
private DataChannel magicDataChannel;
|
private DataChannel magicDataChannel;
|
||||||
private MagicSdpObserver magicSdpObserver;
|
private MagicSdpObserver magicSdpObserver;
|
||||||
@ -73,7 +75,7 @@ public class MagicPeerConnectionWrapper {
|
|||||||
public MagicPeerConnectionWrapper(PeerConnectionFactory peerConnectionFactory,
|
public MagicPeerConnectionWrapper(PeerConnectionFactory peerConnectionFactory,
|
||||||
List<PeerConnection.IceServer> iceServerList,
|
List<PeerConnection.IceServer> iceServerList,
|
||||||
MediaConstraints mediaConstraints,
|
MediaConstraints mediaConstraints,
|
||||||
String sessionId, String localSession, MediaStream mediaStream,
|
String sessionId, String localSession, @Nullable MediaStream mediaStream,
|
||||||
boolean isMCUPublisher, boolean hasMCU) {
|
boolean isMCUPublisher, boolean hasMCU) {
|
||||||
|
|
||||||
this.localMediaStream = mediaStream;
|
this.localMediaStream = mediaStream;
|
||||||
@ -83,21 +85,31 @@ public class MagicPeerConnectionWrapper {
|
|||||||
|
|
||||||
magicSdpObserver = new MagicSdpObserver();
|
magicSdpObserver = new MagicSdpObserver();
|
||||||
hasInitiated = sessionId.compareTo(localSession) < 0;
|
hasInitiated = sessionId.compareTo(localSession) < 0;
|
||||||
|
this.isMCUPublisher = isMCUPublisher;
|
||||||
|
|
||||||
peerConnection = peerConnectionFactory.createPeerConnection(iceServerList, mediaConstraints,
|
peerConnection = peerConnectionFactory.createPeerConnection(iceServerList, mediaConstraints,
|
||||||
new MagicPeerConnectionObserver());
|
new MagicPeerConnectionObserver());
|
||||||
|
|
||||||
this.isMCUPublisher = isMCUPublisher;
|
|
||||||
|
|
||||||
if (peerConnection != null) {
|
if (peerConnection != null) {
|
||||||
|
if (localSession != null && localMediaStream != null) {
|
||||||
peerConnection.addStream(localMediaStream);
|
peerConnection.addStream(localMediaStream);
|
||||||
|
}
|
||||||
|
|
||||||
if (hasInitiated) {
|
if (hasMCU || hasInitiated) {
|
||||||
DataChannel.Init init = new DataChannel.Init();
|
DataChannel.Init init = new DataChannel.Init();
|
||||||
init.negotiated = false;
|
init.negotiated = false;
|
||||||
magicDataChannel = peerConnection.createDataChannel("status", init);
|
magicDataChannel = peerConnection.createDataChannel("status", init);
|
||||||
magicDataChannel.registerObserver(new MagicDataChannelObserver());
|
magicDataChannel.registerObserver(new MagicDataChannelObserver());
|
||||||
|
if (isMCUPublisher) {
|
||||||
peerConnection.createOffer(magicSdpObserver, mediaConstraints);
|
peerConnection.createOffer(magicSdpObserver, mediaConstraints);
|
||||||
|
} else if (hasMCU) {
|
||||||
|
HashMap<String, String> hashMap = new HashMap<>();
|
||||||
|
hashMap.put("sessionId", sessionId);
|
||||||
|
EventBus.getDefault().post(new WebSocketCommunicationEvent("peerReadyForRequestingOffer", hashMap));
|
||||||
|
} else if (hasInitiated) {
|
||||||
|
peerConnection.createOffer(magicSdpObserver, mediaConstraints);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,7 +121,10 @@ public class MagicPeerConnectionWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (peerConnection != null) {
|
if (peerConnection != null) {
|
||||||
|
if (localMediaStream != null) {
|
||||||
peerConnection.removeStream(localMediaStream);
|
peerConnection.removeStream(localMediaStream);
|
||||||
|
}
|
||||||
|
|
||||||
peerConnection.close();
|
peerConnection.close();
|
||||||
peerConnection = null;
|
peerConnection = null;
|
||||||
}
|
}
|
||||||
@ -175,6 +190,7 @@ public class MagicPeerConnectionWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendInitialMediaStatus() {
|
private void sendInitialMediaStatus() {
|
||||||
|
if (localMediaStream != null) {
|
||||||
if (localMediaStream.videoTracks.size() == 1 && localMediaStream.videoTracks.get(0).enabled()) {
|
if (localMediaStream.videoTracks.size() == 1 && localMediaStream.videoTracks.get(0).enabled()) {
|
||||||
sendChannelData(new DataChannelMessage("videoOn"));
|
sendChannelData(new DataChannelMessage("videoOn"));
|
||||||
} else {
|
} else {
|
||||||
@ -187,6 +203,7 @@ public class MagicPeerConnectionWrapper {
|
|||||||
sendChannelData(new DataChannelMessage("audioOff"));
|
sendChannelData(new DataChannelMessage("audioOff"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class MagicDataChannelObserver implements DataChannel.Observer {
|
private class MagicDataChannelObserver implements DataChannel.Observer {
|
||||||
|
|
||||||
@ -219,8 +236,8 @@ public class MagicPeerConnectionWrapper {
|
|||||||
try {
|
try {
|
||||||
DataChannelMessage dataChannelMessage = LoganSquare.parse(strData, DataChannelMessage.class);
|
DataChannelMessage dataChannelMessage = LoganSquare.parse(strData, DataChannelMessage.class);
|
||||||
|
|
||||||
if ("nickChanged".equals(dataChannelMessage.getType())) {
|
|
||||||
String internalNick;
|
String internalNick;
|
||||||
|
if ("nickChanged".equals(dataChannelMessage.getType())) {
|
||||||
if (dataChannelMessage.getPayload() instanceof String) {
|
if (dataChannelMessage.getPayload() instanceof String) {
|
||||||
internalNick = (String) dataChannelMessage.getPayload();
|
internalNick = (String) dataChannelMessage.getPayload();
|
||||||
if (!internalNick.equals(nick)) {
|
if (!internalNick.equals(nick)) {
|
||||||
@ -233,6 +250,7 @@ public class MagicPeerConnectionWrapper {
|
|||||||
EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
|
EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
|
||||||
.NICK_CHANGE, payloadHashMap.get("userid"), payloadHashMap.get("name"), null));
|
.NICK_CHANGE, payloadHashMap.get("userid"), payloadHashMap.get("name"), null));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ("audioOn".equals(dataChannelMessage.getType())) {
|
} else if ("audioOn".equals(dataChannelMessage.getType())) {
|
||||||
remoteAudioOn = true;
|
remoteAudioOn = true;
|
||||||
EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
|
EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
|
||||||
@ -268,11 +286,15 @@ public class MagicPeerConnectionWrapper {
|
|||||||
if (iceConnectionState.equals(PeerConnection.IceConnectionState.CONNECTED)) {
|
if (iceConnectionState.equals(PeerConnection.IceConnectionState.CONNECTED)) {
|
||||||
/*EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
|
/*EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
|
||||||
.PEER_CONNECTED, sessionId, null, null));*/
|
.PEER_CONNECTED, sessionId, null, null));*/
|
||||||
|
|
||||||
|
if (!isMCUPublisher) {
|
||||||
EventBus.getDefault().post(new MediaStreamEvent(remoteMediaStream, sessionId));
|
EventBus.getDefault().post(new MediaStreamEvent(remoteMediaStream, sessionId));
|
||||||
|
}
|
||||||
|
|
||||||
if (hasInitiated) {
|
if (hasInitiated) {
|
||||||
sendInitialMediaStatus();
|
sendInitialMediaStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (iceConnectionState.equals(PeerConnection.IceConnectionState.CLOSED)) {
|
} else if (iceConnectionState.equals(PeerConnection.IceConnectionState.CLOSED)) {
|
||||||
EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
|
EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
|
||||||
.PEER_CLOSED, sessionId, null, null));
|
.PEER_CLOSED, sessionId, null, null));
|
||||||
@ -311,8 +333,10 @@ public class MagicPeerConnectionWrapper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRemoveStream(MediaStream mediaStream) {
|
public void onRemoveStream(MediaStream mediaStream) {
|
||||||
|
if (!isMCUPublisher) {
|
||||||
EventBus.getDefault().post(new MediaStreamEvent(null, sessionId));
|
EventBus.getDefault().post(new MediaStreamEvent(null, sessionId));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDataChannel(DataChannel dataChannel) {
|
public void onDataChannel(DataChannel dataChannel) {
|
||||||
@ -347,16 +371,18 @@ public class MagicPeerConnectionWrapper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateSuccess(SessionDescription sessionDescription) {
|
public void onCreateSuccess(SessionDescription sessionDescription) {
|
||||||
|
SessionDescription sessionDescriptionWithPreferredCodec;
|
||||||
String sessionDescriptionStringWithPreferredCodec = MagicWebRTCUtils.preferCodec
|
String sessionDescriptionStringWithPreferredCodec = MagicWebRTCUtils.preferCodec
|
||||||
(sessionDescription.description,
|
(sessionDescription.description,
|
||||||
"VP8", false);
|
"VP8", false);
|
||||||
|
sessionDescriptionWithPreferredCodec = new SessionDescription(
|
||||||
SessionDescription sessionDescriptionWithPreferredCodec = new SessionDescription(
|
|
||||||
sessionDescription.type,
|
sessionDescription.type,
|
||||||
sessionDescriptionStringWithPreferredCodec);
|
sessionDescriptionStringWithPreferredCodec);
|
||||||
|
|
||||||
|
|
||||||
EventBus.getDefault().post(new SessionDescriptionSendEvent(sessionDescriptionWithPreferredCodec, sessionId,
|
EventBus.getDefault().post(new SessionDescriptionSendEvent(sessionDescriptionWithPreferredCodec, sessionId,
|
||||||
sessionDescription.type.canonicalForm().toLowerCase(), null));
|
sessionDescription.type.canonicalForm().toLowerCase(), null));
|
||||||
|
|
||||||
if (peerConnection != null) {
|
if (peerConnection != null) {
|
||||||
peerConnection.setLocalDescription(magicSdpObserver, sessionDescriptionWithPreferredCodec);
|
peerConnection.setLocalDescription(magicSdpObserver, sessionDescriptionWithPreferredCodec);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user