mirror of
https://github.com/nextcloud/talk-android
synced 2025-08-13 23:15:19 +01:00
Nick sending + fix regular calls
This commit is contained in:
parent
68b663244b
commit
498ae0dfc3
@ -131,6 +131,7 @@ import butterknife.BindView;
|
|||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
import butterknife.OnLongClick;
|
import butterknife.OnLongClick;
|
||||||
import eu.davidea.flipview.FlipView;
|
import eu.davidea.flipview.FlipView;
|
||||||
|
import io.reactivex.Observable;
|
||||||
import io.reactivex.Observer;
|
import io.reactivex.Observer;
|
||||||
import io.reactivex.Scheduler;
|
import io.reactivex.Scheduler;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
@ -1223,6 +1224,10 @@ public class CallController extends BaseController {
|
|||||||
joinRoomAndCall();
|
joinRoomAndCall();
|
||||||
break;
|
break;
|
||||||
case "roomJoined":
|
case "roomJoined":
|
||||||
|
if (hasMCU) {
|
||||||
|
startSendingNick();
|
||||||
|
}
|
||||||
|
|
||||||
if (webSocketCommunicationEvent.getHashMap().get("roomToken").equals(roomToken)) {
|
if (webSocketCommunicationEvent.getHashMap().get("roomToken").equals(roomToken)) {
|
||||||
performCall();
|
performCall();
|
||||||
}
|
}
|
||||||
@ -1555,7 +1560,7 @@ public class CallController extends BaseController {
|
|||||||
if ((magicPeerConnectionWrapper = getPeerConnectionWrapperForSessionId(sessionId)) != null) {
|
if ((magicPeerConnectionWrapper = getPeerConnectionWrapperForSessionId(sessionId)) != null) {
|
||||||
return magicPeerConnectionWrapper;
|
return magicPeerConnectionWrapper;
|
||||||
} else {
|
} else {
|
||||||
hasMCU = webSocketClient != null && webSocketClient.hasMCU();
|
hasMCU = externalSignalingServer != null && webSocketClient != null && webSocketClient.hasMCU();
|
||||||
|
|
||||||
if (hasMCU && publisher) {
|
if (hasMCU && publisher) {
|
||||||
magicPeerConnectionWrapper = new MagicPeerConnectionWrapper(peerConnectionFactory,
|
magicPeerConnectionWrapper = new MagicPeerConnectionWrapper(peerConnectionFactory,
|
||||||
@ -1649,6 +1654,27 @@ public class CallController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startSendingNick() {
|
||||||
|
DataChannelMessage dataChannelMessage = new DataChannelMessage();
|
||||||
|
dataChannelMessage.setType("nickChanged");
|
||||||
|
HashMap<String, String> nickChangedPayload = new HashMap<>();
|
||||||
|
nickChangedPayload.put("userid", conversationUser.getUserId());
|
||||||
|
nickChangedPayload.put("name", conversationUser.getDisplayName());
|
||||||
|
dataChannelMessage.setPayload(nickChangedPayload);
|
||||||
|
for (int i = 0; i < magicPeerConnectionWrapperList.size(); i++) {
|
||||||
|
if (magicPeerConnectionWrapperList.get(i).isMCUPublisher()) {
|
||||||
|
int finalI = i;
|
||||||
|
Observable
|
||||||
|
.interval(1, TimeUnit.SECONDS)
|
||||||
|
.takeWhile(observer -> inCall)
|
||||||
|
.observeOn(Schedulers.newThread())
|
||||||
|
.doOnNext(n -> magicPeerConnectionWrapperList.get(finalI).sendChannelData(dataChannelMessage));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
public void onMessageEvent(MediaStreamEvent mediaStreamEvent) {
|
public void onMessageEvent(MediaStreamEvent mediaStreamEvent) {
|
||||||
if (mediaStreamEvent.getMediaStream() != null) {
|
if (mediaStreamEvent.getMediaStream() != null) {
|
||||||
|
@ -30,7 +30,6 @@ 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;
|
||||||
|
|
||||||
@ -51,14 +50,13 @@ 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";
|
||||||
private List<IceCandidate> iceCandidates = new ArrayList<>();
|
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;
|
||||||
@ -75,7 +73,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, @Nullable MediaStream mediaStream,
|
String sessionId, String localSession, MediaStream mediaStream,
|
||||||
boolean isMCUPublisher, boolean hasMCU) {
|
boolean isMCUPublisher, boolean hasMCU) {
|
||||||
|
|
||||||
this.localMediaStream = mediaStream;
|
this.localMediaStream = mediaStream;
|
||||||
@ -85,28 +83,21 @@ 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());
|
||||||
|
|
||||||
if (peerConnection != null) {
|
this.isMCUPublisher = isMCUPublisher;
|
||||||
if (localSession != null && localMediaStream != null) {
|
|
||||||
peerConnection.addStream(localMediaStream);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasMCU || hasInitiated) {
|
if (peerConnection != null) {
|
||||||
|
peerConnection.addStream(localMediaStream);
|
||||||
|
|
||||||
|
if (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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,10 +109,7 @@ 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;
|
||||||
}
|
}
|
||||||
@ -187,18 +175,16 @@ 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 {
|
sendChannelData(new DataChannelMessage("videoOff"));
|
||||||
sendChannelData(new DataChannelMessage("videoOff"));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (localMediaStream.audioTracks.size() == 1 && localMediaStream.audioTracks.get(0).enabled()) {
|
if (localMediaStream.audioTracks.size() == 1 && localMediaStream.audioTracks.get(0).enabled()) {
|
||||||
sendChannelData(new DataChannelMessage("audioOn"));
|
sendChannelData(new DataChannelMessage("audioOn"));
|
||||||
} else {
|
} else {
|
||||||
sendChannelData(new DataChannelMessage("audioOff"));
|
sendChannelData(new DataChannelMessage("audioOff"));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,8 +219,8 @@ public class MagicPeerConnectionWrapper {
|
|||||||
try {
|
try {
|
||||||
DataChannelMessage dataChannelMessage = LoganSquare.parse(strData, DataChannelMessage.class);
|
DataChannelMessage dataChannelMessage = LoganSquare.parse(strData, DataChannelMessage.class);
|
||||||
|
|
||||||
String internalNick;
|
|
||||||
if ("nickChanged".equals(dataChannelMessage.getType())) {
|
if ("nickChanged".equals(dataChannelMessage.getType())) {
|
||||||
|
String internalNick;
|
||||||
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)) {
|
||||||
@ -247,7 +233,6 @@ 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
|
||||||
@ -283,15 +268,11 @@ 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));*/
|
||||||
|
EventBus.getDefault().post(new MediaStreamEvent(remoteMediaStream, sessionId));
|
||||||
if (!isMCUPublisher) {
|
|
||||||
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));
|
||||||
@ -330,9 +311,7 @@ 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
|
||||||
@ -368,18 +347,16 @@ 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);
|
||||||
}
|
}
|
||||||
@ -398,4 +375,8 @@ public class MagicPeerConnectionWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public boolean isMCUPublisher() {
|
||||||
|
return isMCUPublisher;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user