From 172d2c693f1f83d203baf1b45e8bdc50f0212aaf Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 14 Apr 2020 09:06:07 +0200 Subject: [PATCH] depulicate 'propose's when doing mam catchup --- build.gradle | 4 +- .../conversations/parser/MessageParser.java | 6 ++ .../xmpp/jingle/JingleRtpConnection.java | 100 +++++++++--------- 3 files changed, 59 insertions(+), 51 deletions(-) diff --git a/build.gradle b/build.gradle index 84ec32270..606021a97 100644 --- a/build.gradle +++ b/build.gradle @@ -92,8 +92,8 @@ android { defaultConfig { minSdkVersion 16 targetSdkVersion 28 - versionCode 368 - versionName "2.8.0-alpha.2" + versionCode 369 + versionName "2.8.0-alpha.3" archivesBaseName += "-$versionName" applicationId "eu.siacs.conversations" resValue "string", "applicationId", applicationId diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 908166de4..9cb6e7bbd 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -854,6 +854,12 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece final String namespace = description == null ? null : description.getNamespace(); if (Namespace.JINGLE_APPS_RTP.equals(namespace)) { final Conversation c = mXmppConnectionService.findOrCreateConversation(account, counterpart.asBareJid(), false, false); + final Message preExistingMessage = c.findRtpSession(sessionId, status); + if (preExistingMessage != null) { + preExistingMessage.setServerMsgId(serverMsgId); + mXmppConnectionService.updateMessage(preExistingMessage); + break; + } final Message message = new Message( c, status, diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java index 4bb502633..883995416 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java @@ -349,31 +349,33 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web sendSessionAccept(offer); } - private void sendSessionAccept(SessionDescription offer) { - discoverIceServers(iceServers -> { - try { - setupWebRTC(iceServers); - } catch (WebRTCWrapper.InitializationException e) { - sendSessionTerminate(Reason.FAILED_APPLICATION); - return; - } - final org.webrtc.SessionDescription sdp = new org.webrtc.SessionDescription( - org.webrtc.SessionDescription.Type.OFFER, - offer.toString() - ); - try { - this.webRTCWrapper.setRemoteDescription(sdp).get(); - addIceCandidatesFromBlackLog(); - org.webrtc.SessionDescription webRTCSessionDescription = this.webRTCWrapper.createAnswer().get(); - final SessionDescription sessionDescription = SessionDescription.parse(webRTCSessionDescription.description); - final RtpContentMap respondingRtpContentMap = RtpContentMap.of(sessionDescription); - sendSessionAccept(respondingRtpContentMap); - this.webRTCWrapper.setLocalDescription(webRTCSessionDescription); - } catch (Exception e) { - Log.d(Config.LOGTAG, "unable to send session accept", e); + private void sendSessionAccept(final SessionDescription offer) { + discoverIceServers(iceServers -> sendSessionAccept(offer,iceServers)); + } - } - }); + private void sendSessionAccept(final SessionDescription offer, final List iceServers) { + try { + setupWebRTC(iceServers); + } catch (WebRTCWrapper.InitializationException e) { + sendSessionTerminate(Reason.FAILED_APPLICATION); + return; + } + final org.webrtc.SessionDescription sdp = new org.webrtc.SessionDescription( + org.webrtc.SessionDescription.Type.OFFER, + offer.toString() + ); + try { + this.webRTCWrapper.setRemoteDescription(sdp).get(); + addIceCandidatesFromBlackLog(); + org.webrtc.SessionDescription webRTCSessionDescription = this.webRTCWrapper.createAnswer().get(); + final SessionDescription sessionDescription = SessionDescription.parse(webRTCSessionDescription.description); + final RtpContentMap respondingRtpContentMap = RtpContentMap.of(sessionDescription); + sendSessionAccept(respondingRtpContentMap); + this.webRTCWrapper.setLocalDescription(webRTCSessionDescription); + } catch (Exception e) { + Log.d(Config.LOGTAG, "unable to send session accept", e); + + } } private void addIceCandidatesFromBlackLog() { @@ -532,38 +534,39 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web private void sendSessionInitiate(final State targetState) { Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": prepare session-initiate"); - discoverIceServers(iceServers -> { - try { - setupWebRTC(iceServers); - } catch (WebRTCWrapper.InitializationException e) { - Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": unable to initialize webrtc"); + discoverIceServers(iceServers -> sendSessionInitiate(targetState, iceServers)); + } + + private void sendSessionInitiate(final State targetState, final List iceServers) { + try { + setupWebRTC(iceServers); + } catch (WebRTCWrapper.InitializationException e) { + Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": unable to initialize webrtc"); + transitionOrThrow(State.TERMINATED_APPLICATION_FAILURE); + return; + } + try { + org.webrtc.SessionDescription webRTCSessionDescription = this.webRTCWrapper.createOffer().get(); + final SessionDescription sessionDescription = SessionDescription.parse(webRTCSessionDescription.description); + Log.d(Config.LOGTAG, "description: " + webRTCSessionDescription.description); + final RtpContentMap rtpContentMap = RtpContentMap.of(sessionDescription); + sendSessionInitiate(rtpContentMap, targetState); + this.webRTCWrapper.setLocalDescription(webRTCSessionDescription).get(); + } catch (final Exception e) { + Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": unable to sendSessionInitiate", e); + webRTCWrapper.close(); + if (isInState(targetState)) { + sendSessionTerminate(Reason.FAILED_APPLICATION); + } else { transitionOrThrow(State.TERMINATED_APPLICATION_FAILURE); - return; } - try { - org.webrtc.SessionDescription webRTCSessionDescription = this.webRTCWrapper.createOffer().get(); - final SessionDescription sessionDescription = SessionDescription.parse(webRTCSessionDescription.description); - Log.d(Config.LOGTAG, "description: " + webRTCSessionDescription.description); - final RtpContentMap rtpContentMap = RtpContentMap.of(sessionDescription); - sendSessionInitiate(rtpContentMap, targetState); - this.webRTCWrapper.setLocalDescription(webRTCSessionDescription).get(); - } catch (final Exception e) { - Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": unable to sendSessionInitiate", e); - webRTCWrapper.close(); - if (isInState(targetState)) { - sendSessionTerminate(Reason.FAILED_APPLICATION); - } else { - transitionOrThrow(State.TERMINATED_APPLICATION_FAILURE); - } - } - }); + } } private void sendSessionInitiate(RtpContentMap rtpContentMap, final State targetState) { this.initiatorRtpContentMap = rtpContentMap; this.transitionOrThrow(targetState); final JinglePacket sessionInitiate = rtpContentMap.toJinglePacket(JinglePacket.Action.SESSION_INITIATE, id.sessionId); - Log.d(Config.LOGTAG, sessionInitiate.toString()); send(sessionInitiate); } @@ -591,7 +594,6 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web return; } final JinglePacket jinglePacket = transportInfo.toJinglePacket(JinglePacket.Action.TRANSPORT_INFO, id.sessionId); - Log.d(Config.LOGTAG, jinglePacket.toString()); send(jinglePacket); }