From e16e0d895e0e277b431b3a2f814e5122b4874442 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 13 Apr 2020 18:30:12 +0200 Subject: [PATCH] cancle ongoing jingle sessions on xmpp rebind --- .../services/XmppConnectionService.java | 4 +-- .../xmpp/jingle/AbstractJingleConnection.java | 2 ++ .../xmpp/jingle/JingleConnectionManager.java | 8 ++--- .../jingle/JingleFileTransferConnection.java | 7 ++++ .../xmpp/jingle/JingleRtpConnection.java | 34 ++++++++++++++----- .../xmpp/jingle/WebRTCWrapper.java | 4 ++- 6 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 543eb9fd5..d7adc05e9 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -145,9 +145,7 @@ import eu.siacs.conversations.xmpp.chatstate.ChatState; import eu.siacs.conversations.xmpp.forms.Data; import eu.siacs.conversations.xmpp.jingle.AbstractJingleConnection; import eu.siacs.conversations.xmpp.jingle.JingleConnectionManager; -import eu.siacs.conversations.xmpp.jingle.OnJinglePacketReceived; import eu.siacs.conversations.xmpp.jingle.RtpEndUserState; -import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket; import eu.siacs.conversations.xmpp.mam.MamReference; import eu.siacs.conversations.xmpp.pep.Avatar; import eu.siacs.conversations.xmpp.pep.PublishOptions; @@ -314,7 +312,7 @@ public class XmppConnectionService extends Service { synchronized (account.inProgressConferencePings) { account.inProgressConferencePings.clear(); } - mJingleConnectionManager.cancelInTransmission(); + mJingleConnectionManager.notifyRebound(); mQuickConversationsService.considerSyncBackground(false); fetchRosterFromServer(account); diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/AbstractJingleConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/AbstractJingleConnection.java index bea185902..b6e160898 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/AbstractJingleConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/AbstractJingleConnection.java @@ -36,6 +36,8 @@ public abstract class AbstractJingleConnection { return id; } + abstract void notifyRebound(); + public static class Id { public final Account account; diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java index 7df61767b..e6f17ac7f 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java @@ -376,11 +376,9 @@ public class JingleConnectionManager extends AbstractConnectionManager { account.getXmppConnection().sendIqPacket(packet.generateResponse(IqPacket.TYPE.ERROR), null); } - public void cancelInTransmission() { - for (AbstractJingleConnection connection : this.connections.values()) { - /*if (connection.getJingleStatus() == JingleFileTransferConnection.JINGLE_STATUS_TRANSMITTING) { - connection.abort("connectivity-error"); - }*/ + public void notifyRebound() { + for (final AbstractJingleConnection connection : this.connections.values()) { + connection.notifyRebound(); } } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java index b375398d2..f0941d27c 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java @@ -293,6 +293,13 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple } } + @Override + void notifyRebound() { + if (getJingleStatus() == JINGLE_STATUS_TRANSMITTING) { + abort(Reason.CONNECTIVITY_ERROR); + } + } + private void respondToIq(final IqPacket packet, final boolean result) { final IqPacket response; if (result) { 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 b8a67cb0e..4bb502633 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java @@ -65,7 +65,8 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web State.PROCEED, State.REJECTED, State.RETRACTED, - State.TERMINATED_APPLICATION_FAILURE + State.TERMINATED_APPLICATION_FAILURE, + State.TERMINATED_CONNECTIVITY_ERROR //only used when the xmpp connection rebinds )); transitionBuilder.put(State.PROCEED, ImmutableList.of( State.SESSION_INITIALIZED_PRE_APPROVED, @@ -164,6 +165,24 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web } } + @Override + void notifyRebound() { + if (TERMINATED.contains(this.state)) { + return; + } + webRTCWrapper.close(); + if (!isInitiator() && isInState(State.PROPOSED,State.SESSION_INITIALIZED)) { + xmppConnectionService.getNotificationService().cancelIncomingCallNotification(); + } + if (isInState(State.SESSION_INITIALIZED, State.SESSION_INITIALIZED_PRE_APPROVED, State.SESSION_ACCEPTED)) { + //we might have already changed resources (full jid) at this point; so this might not even reach the other party + sendSessionTerminate(Reason.CONNECTIVITY_ERROR); + } else { + transitionOrThrow(State.TERMINATED_CONNECTIVITY_ERROR); + jingleConnectionManager.finishConnection(this); + } + } + private void receiveSessionTerminate(final JinglePacket jinglePacket) { respondOk(jinglePacket); final JinglePacket.ReasonWrapper wrapper = jinglePacket.getReason(); @@ -496,7 +515,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web if (from.equals(id.with)) { if (transition(State.RETRACTED)) { xmppConnectionService.getNotificationService().cancelIncomingCallNotification(); - Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": session with " + id.with + " has been retracted (serverMsgId="+serverMsgId+")"); + Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": session with " + id.with + " has been retracted (serverMsgId=" + serverMsgId + ")"); if (serverMsgId != null) { this.message.setServerMsgId(serverMsgId); } @@ -559,7 +578,6 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web final JinglePacket jinglePacket = new JinglePacket(JinglePacket.Action.SESSION_TERMINATE, id.sessionId); jinglePacket.setReason(reason, text); send(jinglePacket); - Log.d(Config.LOGTAG, jinglePacket.toString()); jingleConnectionManager.finishConnection(this); } @@ -837,14 +855,14 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web return webRTCWrapper.getAudioManager(); } - public void setMicrophoneEnabled(final boolean enabled) { - webRTCWrapper.setMicrophoneEnabled(enabled); - } - public boolean isMicrophoneEnabled() { return webRTCWrapper.isMicrophoneEnabled(); } + public void setMicrophoneEnabled(final boolean enabled) { + webRTCWrapper.setMicrophoneEnabled(enabled); + } + @Override public void onAudioDeviceChanged(AppRTCAudioManager.AudioDevice selectedAudioDevice, Set availableAudioDevices) { xmppConnectionService.notifyJingleRtpConnectionUpdate(selectedAudioDevice, availableAudioDevices); @@ -934,7 +952,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web } private void writeLogMessageMissed() { - this.message.setBody(new RtpSessionStatus(false,0).toString()); + this.message.setBody(new RtpSessionStatus(false, 0).toString()); this.writeMessage(); } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java index d723e96e5..c3d71d4a6 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java @@ -50,7 +50,9 @@ public class WebRTCWrapper { @Override public void onSignalingChange(PeerConnection.SignalingState signalingState) { Log.d(Config.LOGTAG, "onSignalingChange(" + signalingState + ")"); - + //this is called after removeTrack or addTrack + //and should then trigger a content-add or content-remove or something + //https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/removeTrack } @Override