From 1b5be43cea18634d3dc8fc5f4b78afa95ce83af5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Mon, 21 Feb 2022 07:02:41 +0100 Subject: [PATCH] Handle offers to renegotiate an already established connection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Once a RTCPeerConnection is established new offers can still be received for that connection. These offers will update/renegotiate the connection (for example, to add a video track to an audio only connection) and need to be handled like the offers to establish the original connection (the offer needs to be set as the remote description and a local answer needs to be created for it, set as the local description and sent to the other peer). In the PeerConnectionWrapper the same SdpObserver object is called when setting both local and remote descriptions, so the answer should be created only when a remote description was set. Before the answer was created if there was no local description already, so this only worked when establishing the initial connection. Once the connection is established new answers need to replace the current local description, so now the creation of new answers is based on the signaling state instead. Signed-off-by: Daniel Calviño Sánchez --- .../java/com/nextcloud/talk/webrtc/PeerConnectionWrapper.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/PeerConnectionWrapper.java b/app/src/main/java/com/nextcloud/talk/webrtc/PeerConnectionWrapper.java index 1da81d7bc..59ff5e9c1 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/PeerConnectionWrapper.java +++ b/app/src/main/java/com/nextcloud/talk/webrtc/PeerConnectionWrapper.java @@ -575,7 +575,9 @@ public class PeerConnectionWrapper { @Override public void onSetSuccess() { if (peerConnection != null) { - if (peerConnection.getLocalDescription() == null) { + // Local provisional answers ("pranswer") are not used anywhere, + // so the "have-local-pranswer" state is not taken into account. + if (peerConnection.signalingState() == PeerConnection.SignalingState.HAVE_REMOTE_OFFER) { if (shouldNotReceiveVideo()) { for (RtpTransceiver t : peerConnection.getTransceivers()) {