|
@@ -2,6 +2,8 @@
|
|
|
* Nextcloud Talk application
|
|
|
*
|
|
|
* @author Mario Danic
|
|
|
+ * @author Tim Krüger
|
|
|
+ * Copyright (C) 2022 Tim Krüger <t@timkrueger.me>
|
|
|
* Copyright (C) 2017 Mario Danic <mario@lovelyhq.com>
|
|
|
*
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
@@ -37,6 +39,7 @@ import com.nextcloud.talk.models.json.signaling.DataChannelMessageNick;
|
|
|
import com.nextcloud.talk.models.json.signaling.NCIceCandidate;
|
|
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
+import org.webrtc.AudioTrack;
|
|
|
import org.webrtc.DataChannel;
|
|
|
import org.webrtc.IceCandidate;
|
|
|
import org.webrtc.MediaConstraints;
|
|
@@ -46,10 +49,12 @@ import org.webrtc.PeerConnectionFactory;
|
|
|
import org.webrtc.RtpReceiver;
|
|
|
import org.webrtc.SdpObserver;
|
|
|
import org.webrtc.SessionDescription;
|
|
|
+import org.webrtc.VideoTrack;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.nio.ByteBuffer;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -60,7 +65,7 @@ import autodagger.AutoInjector;
|
|
|
|
|
|
@AutoInjector(NextcloudTalkApplication.class)
|
|
|
public class MagicPeerConnectionWrapper {
|
|
|
- private static final String TAG = "MagicPeerConWrapper";
|
|
|
+ private static final String TAG = MagicPeerConnectionWrapper.class.getCanonicalName();
|
|
|
|
|
|
private List<IceCandidate> iceCandidates = new ArrayList<>();
|
|
|
private PeerConnection peerConnection;
|
|
@@ -107,14 +112,18 @@ public class MagicPeerConnectionWrapper {
|
|
|
this.isMCUPublisher = isMCUPublisher;
|
|
|
|
|
|
PeerConnection.RTCConfiguration configuration = new PeerConnection.RTCConfiguration(iceServerList);
|
|
|
- configuration.sdpSemantics = PeerConnection.SdpSemantics.PLAN_B;
|
|
|
-
|
|
|
- peerConnection = peerConnectionFactory.createPeerConnection(configuration, sdpConstraints,
|
|
|
- new MagicPeerConnectionObserver());
|
|
|
+ configuration.sdpSemantics = PeerConnection.SdpSemantics.UNIFIED_PLAN;
|
|
|
+ peerConnection = peerConnectionFactory.createPeerConnection(configuration, new MagicPeerConnectionObserver());
|
|
|
|
|
|
if (peerConnection != null) {
|
|
|
- if (localMediaStream != null) {
|
|
|
- peerConnection.addStream(localMediaStream);
|
|
|
+ if (localStream != null) {
|
|
|
+ List<String> localMediaStreamIds = Collections.singletonList(localMediaStream.getId());
|
|
|
+ for(AudioTrack track : localMediaStream.audioTracks) {
|
|
|
+ peerConnection.addTrack(track, localMediaStreamIds);
|
|
|
+ }
|
|
|
+ for(VideoTrack track : localStream.videoTracks) {
|
|
|
+ peerConnection.addTrack(track, localMediaStreamIds);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (hasMCU || hasInitiated) {
|
|
@@ -145,15 +154,17 @@ public class MagicPeerConnectionWrapper {
|
|
|
if (magicDataChannel != null) {
|
|
|
magicDataChannel.dispose();
|
|
|
magicDataChannel = null;
|
|
|
+ Log.d(TAG, "Disposed DataChannel");
|
|
|
+ } else {
|
|
|
+ Log.d(TAG, "DataChannel is null.");
|
|
|
}
|
|
|
|
|
|
if (peerConnection != null) {
|
|
|
- if (localMediaStream != null) {
|
|
|
- peerConnection.removeStream(localMediaStream);
|
|
|
- }
|
|
|
-
|
|
|
peerConnection.close();
|
|
|
peerConnection = null;
|
|
|
+ Log.d(TAG, "Disposed PeerConnection");
|
|
|
+ } else {
|
|
|
+ Log.d(TAG, "PeerConnection is null.");
|
|
|
}
|
|
|
}
|
|
|
|