Rename MagicPeerConnectionWrapper to PeerConnectionWrapper

Signed-off-by: Tim Krüger <t@timkrueger.me>
This commit is contained in:
Tim Krüger 2022-02-16 14:40:46 +01:00
parent 0ea29ee0cd
commit f08a9ef463
No known key found for this signature in database
GPG key ID: FECE3A7222C52A4E
2 changed files with 95 additions and 95 deletions

View file

@ -93,7 +93,7 @@ import com.nextcloud.talk.utils.power.PowerManagerUtils;
import com.nextcloud.talk.utils.preferences.AppPreferences; import com.nextcloud.talk.utils.preferences.AppPreferences;
import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder; import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder;
import com.nextcloud.talk.webrtc.MagicAudioManager; import com.nextcloud.talk.webrtc.MagicAudioManager;
import com.nextcloud.talk.webrtc.MagicPeerConnectionWrapper; import com.nextcloud.talk.webrtc.PeerConnectionWrapper;
import com.nextcloud.talk.webrtc.MagicWebRTCUtils; import com.nextcloud.talk.webrtc.MagicWebRTCUtils;
import com.nextcloud.talk.webrtc.MagicWebSocketInstance; import com.nextcloud.talk.webrtc.MagicWebSocketInstance;
import com.nextcloud.talk.webrtc.WebSocketConnectionHelper; import com.nextcloud.talk.webrtc.WebSocketConnectionHelper;
@ -215,7 +215,7 @@ public class CallActivity extends CallBaseActivity {
private String callSession; private String callSession;
private MediaStream localStream; private MediaStream localStream;
private String credentials; private String credentials;
private List<MagicPeerConnectionWrapper> magicPeerConnectionWrapperList = new ArrayList<>(); private List<PeerConnectionWrapper> peerConnectionWrapperList = new ArrayList<>();
private Map<String, Participant> participantMap = new HashMap<>(); private Map<String, Participant> participantMap = new HashMap<>();
private boolean videoOn = false; private boolean videoOn = false;
@ -985,15 +985,15 @@ public class CallActivity extends CallBaseActivity {
} }
} }
if (isConnectionEstablished() && magicPeerConnectionWrapperList != null) { if (isConnectionEstablished() && peerConnectionWrapperList != null) {
if (!hasMCU) { if (!hasMCU) {
for (MagicPeerConnectionWrapper magicPeerConnectionWrapper : magicPeerConnectionWrapperList) { for (PeerConnectionWrapper peerConnectionWrapper : peerConnectionWrapperList) {
magicPeerConnectionWrapper.sendChannelData(new DataChannelMessage(message)); peerConnectionWrapper.sendChannelData(new DataChannelMessage(message));
} }
} else { } else {
for (MagicPeerConnectionWrapper magicPeerConnectionWrapper : magicPeerConnectionWrapperList) { for (PeerConnectionWrapper peerConnectionWrapper : peerConnectionWrapperList) {
if (magicPeerConnectionWrapper.getSessionId().equals(webSocketClient.getSessionId())) { if (peerConnectionWrapper.getSessionId().equals(webSocketClient.getSessionId())) {
magicPeerConnectionWrapper.sendChannelData(new DataChannelMessage(message)); peerConnectionWrapper.sendChannelData(new DataChannelMessage(message));
break; break;
} }
} }
@ -1517,7 +1517,7 @@ public class CallActivity extends CallBaseActivity {
private void processMessage(NCSignalingMessage ncSignalingMessage) { private void processMessage(NCSignalingMessage ncSignalingMessage) {
if (ncSignalingMessage.getRoomType().equals("video") || ncSignalingMessage.getRoomType().equals("screen")) { if (ncSignalingMessage.getRoomType().equals("video") || ncSignalingMessage.getRoomType().equals("screen")) {
MagicPeerConnectionWrapper magicPeerConnectionWrapper = PeerConnectionWrapper peerConnectionWrapper =
getPeerConnectionWrapperForSessionIdAndType(ncSignalingMessage.getFrom(), getPeerConnectionWrapperForSessionIdAndType(ncSignalingMessage.getFrom(),
ncSignalingMessage.getRoomType(), false); ncSignalingMessage.getRoomType(), false);
@ -1535,7 +1535,7 @@ public class CallActivity extends CallBaseActivity {
break; break;
case "offer": case "offer":
case "answer": case "answer":
magicPeerConnectionWrapper.setNick(ncSignalingMessage.getPayload().getNick()); peerConnectionWrapper.setNick(ncSignalingMessage.getPayload().getNick());
SessionDescription sessionDescriptionWithPreferredCodec; SessionDescription sessionDescriptionWithPreferredCodec;
String sessionDescriptionStringWithPreferredCodec = MagicWebRTCUtils.preferCodec String sessionDescriptionStringWithPreferredCodec = MagicWebRTCUtils.preferCodec
@ -1546,8 +1546,8 @@ public class CallActivity extends CallBaseActivity {
SessionDescription.Type.fromCanonicalForm(type), SessionDescription.Type.fromCanonicalForm(type),
sessionDescriptionStringWithPreferredCodec); sessionDescriptionStringWithPreferredCodec);
if (magicPeerConnectionWrapper.getPeerConnection() != null) { if (peerConnectionWrapper.getPeerConnection() != null) {
magicPeerConnectionWrapper.getPeerConnection().setRemoteDescription(magicPeerConnectionWrapper peerConnectionWrapper.getPeerConnection().setRemoteDescription(peerConnectionWrapper
.getMagicSdpObserver(), sessionDescriptionWithPreferredCodec); .getMagicSdpObserver(), sessionDescriptionWithPreferredCodec);
} }
break; break;
@ -1555,10 +1555,10 @@ public class CallActivity extends CallBaseActivity {
NCIceCandidate ncIceCandidate = ncSignalingMessage.getPayload().getIceCandidate(); NCIceCandidate ncIceCandidate = ncSignalingMessage.getPayload().getIceCandidate();
IceCandidate iceCandidate = new IceCandidate(ncIceCandidate.getSdpMid(), IceCandidate iceCandidate = new IceCandidate(ncIceCandidate.getSdpMid(),
ncIceCandidate.getSdpMLineIndex(), ncIceCandidate.getCandidate()); ncIceCandidate.getSdpMLineIndex(), ncIceCandidate.getCandidate());
magicPeerConnectionWrapper.addCandidate(iceCandidate); peerConnectionWrapper.addCandidate(iceCandidate);
break; break;
case "endOfCandidates": case "endOfCandidates":
magicPeerConnectionWrapper.drainIceCandidates(); peerConnectionWrapper.drainIceCandidates();
break; break;
default: default:
break; break;
@ -1624,8 +1624,8 @@ public class CallActivity extends CallBaseActivity {
} }
} }
for (int i = 0; i < magicPeerConnectionWrapperList.size(); i++) { for (int i = 0; i < peerConnectionWrapperList.size(); i++) {
endPeerConnection(magicPeerConnectionWrapperList.get(i).getSessionId(), false); endPeerConnection(peerConnectionWrapperList.get(i).getSessionId(), false);
} }
hangupNetworkCalls(shutDownView); hangupNetworkCalls(shutDownView);
@ -1709,9 +1709,9 @@ public class CallActivity extends CallBaseActivity {
} }
} }
for (MagicPeerConnectionWrapper magicPeerConnectionWrapper : magicPeerConnectionWrapperList) { for (PeerConnectionWrapper peerConnectionWrapper : peerConnectionWrapperList) {
if (!magicPeerConnectionWrapper.isMCUPublisher()) { if (!peerConnectionWrapper.isMCUPublisher()) {
oldSessions.add(magicPeerConnectionWrapper.getSessionId()); oldSessions.add(peerConnectionWrapper.getSessionId());
} }
} }
@ -1781,86 +1781,86 @@ public class CallActivity extends CallBaseActivity {
}); });
} }
private void deleteMagicPeerConnection(MagicPeerConnectionWrapper magicPeerConnectionWrapper) { private void deletePeerConnection(PeerConnectionWrapper peerConnectionWrapper) {
magicPeerConnectionWrapper.removePeerConnection(); peerConnectionWrapper.removePeerConnection();
magicPeerConnectionWrapperList.remove(magicPeerConnectionWrapper); peerConnectionWrapperList.remove(peerConnectionWrapper);
} }
private MagicPeerConnectionWrapper getPeerConnectionWrapperForSessionId(String sessionId, String type) { private PeerConnectionWrapper getPeerConnectionWrapperForSessionId(String sessionId, String type) {
for (int i = 0; i < magicPeerConnectionWrapperList.size(); i++) { for (int i = 0; i < peerConnectionWrapperList.size(); i++) {
if (magicPeerConnectionWrapperList.get(i).getSessionId().equals(sessionId) && magicPeerConnectionWrapperList.get(i).getVideoStreamType().equals(type)) { if (peerConnectionWrapperList.get(i).getSessionId().equals(sessionId) && peerConnectionWrapperList.get(i).getVideoStreamType().equals(type)) {
return magicPeerConnectionWrapperList.get(i); return peerConnectionWrapperList.get(i);
} }
} }
return null; return null;
} }
private MagicPeerConnectionWrapper getPeerConnectionWrapperForSessionIdAndType(String sessionId, String type, boolean publisher) { private PeerConnectionWrapper getPeerConnectionWrapperForSessionIdAndType(String sessionId, String type, boolean publisher) {
MagicPeerConnectionWrapper magicPeerConnectionWrapper; PeerConnectionWrapper peerConnectionWrapper;
if ((magicPeerConnectionWrapper = getPeerConnectionWrapperForSessionId(sessionId, type)) != null) { if ((peerConnectionWrapper = getPeerConnectionWrapperForSessionId(sessionId, type)) != null) {
return magicPeerConnectionWrapper; return peerConnectionWrapper;
} else { } else {
if (hasMCU && publisher) { if (hasMCU && publisher) {
magicPeerConnectionWrapper = new MagicPeerConnectionWrapper(peerConnectionFactory, peerConnectionWrapper = new PeerConnectionWrapper(peerConnectionFactory,
iceServers, iceServers,
sdpConstraintsForMCU, sdpConstraintsForMCU,
sessionId, sessionId,
callSession, callSession,
localStream, localStream,
true, true,
true, true,
type); type);
} else if (hasMCU) { } else if (hasMCU) {
magicPeerConnectionWrapper = new MagicPeerConnectionWrapper(peerConnectionFactory, peerConnectionWrapper = new PeerConnectionWrapper(peerConnectionFactory,
iceServers, iceServers,
sdpConstraints, sdpConstraints,
sessionId, sessionId,
callSession, callSession,
null, null,
false, false,
true, true,
type); type);
} else { } else {
if (!"screen".equals(type)) { if (!"screen".equals(type)) {
magicPeerConnectionWrapper = new MagicPeerConnectionWrapper(peerConnectionFactory, peerConnectionWrapper = new PeerConnectionWrapper(peerConnectionFactory,
iceServers, iceServers,
sdpConstraints, sdpConstraints,
sessionId, sessionId,
callSession, callSession,
localStream, localStream,
false, false,
false, false,
type); type);
} else { } else {
magicPeerConnectionWrapper = new MagicPeerConnectionWrapper(peerConnectionFactory, peerConnectionWrapper = new PeerConnectionWrapper(peerConnectionFactory,
iceServers, iceServers,
sdpConstraints, sdpConstraints,
sessionId, sessionId,
callSession, callSession,
null, null,
false, false,
false, false,
type); type);
} }
} }
magicPeerConnectionWrapperList.add(magicPeerConnectionWrapper); peerConnectionWrapperList.add(peerConnectionWrapper);
if (publisher) { if (publisher) {
startSendingNick(); startSendingNick();
} }
return magicPeerConnectionWrapper; return peerConnectionWrapper;
} }
} }
private List<MagicPeerConnectionWrapper> getPeerConnectionWrapperListForSessionId(String sessionId) { private List<PeerConnectionWrapper> getPeerConnectionWrapperListForSessionId(String sessionId) {
List<MagicPeerConnectionWrapper> internalList = new ArrayList<>(); List<PeerConnectionWrapper> internalList = new ArrayList<>();
for (MagicPeerConnectionWrapper magicPeerConnectionWrapper : magicPeerConnectionWrapperList) { for (PeerConnectionWrapper peerConnectionWrapper : peerConnectionWrapperList) {
if (magicPeerConnectionWrapper.getSessionId().equals(sessionId)) { if (peerConnectionWrapper.getSessionId().equals(sessionId)) {
internalList.add(magicPeerConnectionWrapper); internalList.add(peerConnectionWrapper);
} }
} }
@ -1868,15 +1868,15 @@ public class CallActivity extends CallBaseActivity {
} }
private void endPeerConnection(String sessionId, boolean justScreen) { private void endPeerConnection(String sessionId, boolean justScreen) {
List<MagicPeerConnectionWrapper> magicPeerConnectionWrappers; List<PeerConnectionWrapper> peerConnectionWrappers;
MagicPeerConnectionWrapper magicPeerConnectionWrapper; PeerConnectionWrapper peerConnectionWrapper;
if (!(magicPeerConnectionWrappers = getPeerConnectionWrapperListForSessionId(sessionId)).isEmpty()) { if (!(peerConnectionWrappers = getPeerConnectionWrapperListForSessionId(sessionId)).isEmpty()) {
for (int i = 0; i < magicPeerConnectionWrappers.size(); i++) { for (int i = 0; i < peerConnectionWrappers.size(); i++) {
magicPeerConnectionWrapper = magicPeerConnectionWrappers.get(i); peerConnectionWrapper = peerConnectionWrappers.get(i);
if (magicPeerConnectionWrapper.getSessionId().equals(sessionId)) { if (peerConnectionWrapper.getSessionId().equals(sessionId)) {
if (magicPeerConnectionWrapper.getVideoStreamType().equals("screen") || !justScreen) { if (peerConnectionWrapper.getVideoStreamType().equals("screen") || !justScreen) {
runOnUiThread(() -> removeMediaStream(sessionId)); runOnUiThread(() -> removeMediaStream(sessionId));
deleteMagicPeerConnection(magicPeerConnectionWrapper); deletePeerConnection(peerConnectionWrapper);
} }
} }
} }
@ -1988,10 +1988,10 @@ public class CallActivity extends CallBaseActivity {
nickChangedPayload.put("userid", conversationUser.getUserId()); nickChangedPayload.put("userid", conversationUser.getUserId());
nickChangedPayload.put("name", conversationUser.getDisplayName()); nickChangedPayload.put("name", conversationUser.getDisplayName());
dataChannelMessage.setPayload(nickChangedPayload); dataChannelMessage.setPayload(nickChangedPayload);
final MagicPeerConnectionWrapper magicPeerConnectionWrapper; final PeerConnectionWrapper peerConnectionWrapper;
for (int i = 0; i < magicPeerConnectionWrapperList.size(); i++) { for (int i = 0; i < peerConnectionWrapperList.size(); i++) {
if (magicPeerConnectionWrapperList.get(i).isMCUPublisher()) { if (peerConnectionWrapperList.get(i).isMCUPublisher()) {
magicPeerConnectionWrapper = magicPeerConnectionWrapperList.get(i); peerConnectionWrapper = peerConnectionWrapperList.get(i);
Observable Observable
.interval(1, TimeUnit.SECONDS) .interval(1, TimeUnit.SECONDS)
.repeatUntil(() -> (!isConnectionEstablished() || isDestroyed())) .repeatUntil(() -> (!isConnectionEstablished() || isDestroyed()))
@ -2004,7 +2004,7 @@ public class CallActivity extends CallBaseActivity {
@Override @Override
public void onNext(@io.reactivex.annotations.NonNull Long aLong) { public void onNext(@io.reactivex.annotations.NonNull Long aLong) {
magicPeerConnectionWrapper.sendNickChannelData(dataChannelMessage); peerConnectionWrapper.sendNickChannelData(dataChannelMessage);
} }
@Override @Override

View file

@ -68,9 +68,9 @@ import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE; import static java.lang.Boolean.TRUE;
@AutoInjector(NextcloudTalkApplication.class) @AutoInjector(NextcloudTalkApplication.class)
public class MagicPeerConnectionWrapper { public class PeerConnectionWrapper {
private static final String TAG = MagicPeerConnectionWrapper.class.getCanonicalName(); private static final String TAG = PeerConnectionWrapper.class.getCanonicalName();
private List<IceCandidate> iceCandidates = new ArrayList<>(); private List<IceCandidate> iceCandidates = new ArrayList<>();
private PeerConnection peerConnection; private PeerConnection peerConnection;
@ -90,11 +90,11 @@ public class MagicPeerConnectionWrapper {
@Inject @Inject
Context context; Context context;
public MagicPeerConnectionWrapper(PeerConnectionFactory peerConnectionFactory, public PeerConnectionWrapper(PeerConnectionFactory peerConnectionFactory,
List<PeerConnection.IceServer> iceServerList, List<PeerConnection.IceServer> iceServerList,
MediaConstraints mediaConstraints, MediaConstraints mediaConstraints,
String sessionId, String localSession, @Nullable MediaStream localStream, String sessionId, String localSession, @Nullable MediaStream localStream,
boolean isMCUPublisher, boolean hasMCU, String videoStreamType) { boolean isMCUPublisher, boolean hasMCU, String videoStreamType) {
Objects.requireNonNull(NextcloudTalkApplication.Companion.getSharedApplication()).getComponentApplication().inject(this); Objects.requireNonNull(NextcloudTalkApplication.Companion.getSharedApplication()).getComponentApplication().inject(this);
@ -392,8 +392,8 @@ public class MagicPeerConnectionWrapper {
@Override @Override
public void onDataChannel(DataChannel dataChannel) { public void onDataChannel(DataChannel dataChannel) {
if (dataChannel.label().equals("status") || dataChannel.label().equals("JanusDataChannel")) { if (dataChannel.label().equals("status") || dataChannel.label().equals("JanusDataChannel")) {
MagicPeerConnectionWrapper.this.dataChannel = dataChannel; PeerConnectionWrapper.this.dataChannel = dataChannel;
MagicPeerConnectionWrapper.this.dataChannel.registerObserver(new MagicDataChannelObserver()); PeerConnectionWrapper.this.dataChannel.registerObserver(new MagicDataChannelObserver());
} }
} }