mirror of
https://github.com/nextcloud/talk-android
synced 2025-08-12 06:25:02 +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.OnLongClick;
|
||||
import eu.davidea.flipview.FlipView;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.Scheduler;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
@ -1223,6 +1224,10 @@ public class CallController extends BaseController {
|
||||
joinRoomAndCall();
|
||||
break;
|
||||
case "roomJoined":
|
||||
if (hasMCU) {
|
||||
startSendingNick();
|
||||
}
|
||||
|
||||
if (webSocketCommunicationEvent.getHashMap().get("roomToken").equals(roomToken)) {
|
||||
performCall();
|
||||
}
|
||||
@ -1555,7 +1560,7 @@ public class CallController extends BaseController {
|
||||
if ((magicPeerConnectionWrapper = getPeerConnectionWrapperForSessionId(sessionId)) != null) {
|
||||
return magicPeerConnectionWrapper;
|
||||
} else {
|
||||
hasMCU = webSocketClient != null && webSocketClient.hasMCU();
|
||||
hasMCU = externalSignalingServer != null && webSocketClient != null && webSocketClient.hasMCU();
|
||||
|
||||
if (hasMCU && publisher) {
|
||||
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)
|
||||
public void onMessageEvent(MediaStreamEvent mediaStreamEvent) {
|
||||
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.PeerConnectionEvent;
|
||||
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.NCIceCandidate;
|
||||
|
||||
@ -51,14 +50,13 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class MagicPeerConnectionWrapper {
|
||||
private static String TAG = "MagicPeerConnectionWrapper";
|
||||
private List<IceCandidate> iceCandidates = new ArrayList<>();
|
||||
List<IceCandidate> iceCandidates = new ArrayList<>();
|
||||
private PeerConnection peerConnection;
|
||||
private String sessionId;
|
||||
private String nick;
|
||||
private String userId;
|
||||
private MediaConstraints mediaConstraints;
|
||||
private DataChannel magicDataChannel;
|
||||
private MagicSdpObserver magicSdpObserver;
|
||||
@ -75,7 +73,7 @@ public class MagicPeerConnectionWrapper {
|
||||
public MagicPeerConnectionWrapper(PeerConnectionFactory peerConnectionFactory,
|
||||
List<PeerConnection.IceServer> iceServerList,
|
||||
MediaConstraints mediaConstraints,
|
||||
String sessionId, String localSession, @Nullable MediaStream mediaStream,
|
||||
String sessionId, String localSession, MediaStream mediaStream,
|
||||
boolean isMCUPublisher, boolean hasMCU) {
|
||||
|
||||
this.localMediaStream = mediaStream;
|
||||
@ -85,28 +83,21 @@ public class MagicPeerConnectionWrapper {
|
||||
|
||||
magicSdpObserver = new MagicSdpObserver();
|
||||
hasInitiated = sessionId.compareTo(localSession) < 0;
|
||||
this.isMCUPublisher = isMCUPublisher;
|
||||
|
||||
peerConnection = peerConnectionFactory.createPeerConnection(iceServerList, mediaConstraints,
|
||||
new MagicPeerConnectionObserver());
|
||||
|
||||
if (peerConnection != null) {
|
||||
if (localSession != null && localMediaStream != null) {
|
||||
peerConnection.addStream(localMediaStream);
|
||||
}
|
||||
this.isMCUPublisher = isMCUPublisher;
|
||||
|
||||
if (hasMCU || hasInitiated) {
|
||||
if (peerConnection != null) {
|
||||
peerConnection.addStream(localMediaStream);
|
||||
|
||||
if (hasInitiated) {
|
||||
DataChannel.Init init = new DataChannel.Init();
|
||||
init.negotiated = false;
|
||||
magicDataChannel = peerConnection.createDataChannel("status", init);
|
||||
magicDataChannel.registerObserver(new MagicDataChannelObserver());
|
||||
if (isMCUPublisher) {
|
||||
peerConnection.createOffer(magicSdpObserver, mediaConstraints);
|
||||
} else if (hasMCU) {
|
||||
HashMap<String, String> hashMap = new HashMap<>();
|
||||
hashMap.put("sessionId", sessionId);
|
||||
EventBus.getDefault().post(new WebSocketCommunicationEvent("peerReadyForRequestingOffer", hashMap));
|
||||
}
|
||||
peerConnection.createOffer(magicSdpObserver, mediaConstraints);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -118,10 +109,7 @@ public class MagicPeerConnectionWrapper {
|
||||
}
|
||||
|
||||
if (peerConnection != null) {
|
||||
if (localMediaStream != null) {
|
||||
peerConnection.removeStream(localMediaStream);
|
||||
}
|
||||
|
||||
peerConnection.removeStream(localMediaStream);
|
||||
peerConnection.close();
|
||||
peerConnection = null;
|
||||
}
|
||||
@ -187,18 +175,16 @@ public class MagicPeerConnectionWrapper {
|
||||
}
|
||||
|
||||
private void sendInitialMediaStatus() {
|
||||
if (localMediaStream != null) {
|
||||
if (localMediaStream.videoTracks.size() == 1 && localMediaStream.videoTracks.get(0).enabled()) {
|
||||
sendChannelData(new DataChannelMessage("videoOn"));
|
||||
} else {
|
||||
sendChannelData(new DataChannelMessage("videoOff"));
|
||||
}
|
||||
if (localMediaStream.videoTracks.size() == 1 && localMediaStream.videoTracks.get(0).enabled()) {
|
||||
sendChannelData(new DataChannelMessage("videoOn"));
|
||||
} else {
|
||||
sendChannelData(new DataChannelMessage("videoOff"));
|
||||
}
|
||||
|
||||
if (localMediaStream.audioTracks.size() == 1 && localMediaStream.audioTracks.get(0).enabled()) {
|
||||
sendChannelData(new DataChannelMessage("audioOn"));
|
||||
} else {
|
||||
sendChannelData(new DataChannelMessage("audioOff"));
|
||||
}
|
||||
if (localMediaStream.audioTracks.size() == 1 && localMediaStream.audioTracks.get(0).enabled()) {
|
||||
sendChannelData(new DataChannelMessage("audioOn"));
|
||||
} else {
|
||||
sendChannelData(new DataChannelMessage("audioOff"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -233,8 +219,8 @@ public class MagicPeerConnectionWrapper {
|
||||
try {
|
||||
DataChannelMessage dataChannelMessage = LoganSquare.parse(strData, DataChannelMessage.class);
|
||||
|
||||
String internalNick;
|
||||
if ("nickChanged".equals(dataChannelMessage.getType())) {
|
||||
String internalNick;
|
||||
if (dataChannelMessage.getPayload() instanceof String) {
|
||||
internalNick = (String) dataChannelMessage.getPayload();
|
||||
if (!internalNick.equals(nick)) {
|
||||
@ -247,7 +233,6 @@ public class MagicPeerConnectionWrapper {
|
||||
EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
|
||||
.NICK_CHANGE, payloadHashMap.get("userid"), payloadHashMap.get("name"), null));
|
||||
}
|
||||
|
||||
} else if ("audioOn".equals(dataChannelMessage.getType())) {
|
||||
remoteAudioOn = true;
|
||||
EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
|
||||
@ -283,15 +268,11 @@ public class MagicPeerConnectionWrapper {
|
||||
if (iceConnectionState.equals(PeerConnection.IceConnectionState.CONNECTED)) {
|
||||
/*EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
|
||||
.PEER_CONNECTED, sessionId, null, null));*/
|
||||
|
||||
if (!isMCUPublisher) {
|
||||
EventBus.getDefault().post(new MediaStreamEvent(remoteMediaStream, sessionId));
|
||||
}
|
||||
EventBus.getDefault().post(new MediaStreamEvent(remoteMediaStream, sessionId));
|
||||
|
||||
if (hasInitiated) {
|
||||
sendInitialMediaStatus();
|
||||
}
|
||||
|
||||
} else if (iceConnectionState.equals(PeerConnection.IceConnectionState.CLOSED)) {
|
||||
EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
|
||||
.PEER_CLOSED, sessionId, null, null));
|
||||
@ -330,9 +311,7 @@ public class MagicPeerConnectionWrapper {
|
||||
|
||||
@Override
|
||||
public void onRemoveStream(MediaStream mediaStream) {
|
||||
if (!isMCUPublisher) {
|
||||
EventBus.getDefault().post(new MediaStreamEvent(null, sessionId));
|
||||
}
|
||||
EventBus.getDefault().post(new MediaStreamEvent(null, sessionId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -368,18 +347,16 @@ public class MagicPeerConnectionWrapper {
|
||||
|
||||
@Override
|
||||
public void onCreateSuccess(SessionDescription sessionDescription) {
|
||||
SessionDescription sessionDescriptionWithPreferredCodec;
|
||||
String sessionDescriptionStringWithPreferredCodec = MagicWebRTCUtils.preferCodec
|
||||
(sessionDescription.description,
|
||||
"VP8", false);
|
||||
sessionDescriptionWithPreferredCodec = new SessionDescription(
|
||||
|
||||
SessionDescription sessionDescriptionWithPreferredCodec = new SessionDescription(
|
||||
sessionDescription.type,
|
||||
sessionDescriptionStringWithPreferredCodec);
|
||||
|
||||
|
||||
EventBus.getDefault().post(new SessionDescriptionSendEvent(sessionDescriptionWithPreferredCodec, sessionId,
|
||||
sessionDescription.type.canonicalForm().toLowerCase(), null));
|
||||
|
||||
if (peerConnection != null) {
|
||||
peerConnection.setLocalDescription(magicSdpObserver, sessionDescriptionWithPreferredCodec);
|
||||
}
|
||||
@ -398,4 +375,8 @@ public class MagicPeerConnectionWrapper {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMCUPublisher() {
|
||||
return isMCUPublisher;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user