From 9edadc9835ddfc04193ae4691a5f861a441e29be Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 8 Apr 2020 11:29:01 +0200 Subject: [PATCH] process retract jingle messages --- .../generator/MessageGenerator.java | 2 ++ .../conversations/ui/RtpSessionActivity.java | 3 ++- .../xmpp/jingle/JingleRtpConnection.java | 26 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java index c0acf50b7..7e93303cd 100644 --- a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java @@ -236,6 +236,7 @@ public class MessageGenerator extends AbstractGenerator { public MessagePacket sessionProposal(final JingleConnectionManager.RtpSessionProposal proposal) { final MessagePacket packet = new MessagePacket(); + packet.setType(MessagePacket.TYPE_CHAT); //we want to carbon copy those packet.setTo(proposal.with); packet.setId(JingleRtpConnection.JINGLE_MESSAGE_ID_PREFIX+proposal.sessionId); final Element propose = packet.addChild("propose", Namespace.JINGLE_MESSAGE); @@ -247,6 +248,7 @@ public class MessageGenerator extends AbstractGenerator { public MessagePacket sessionRetract(final JingleConnectionManager.RtpSessionProposal proposal) { final MessagePacket packet = new MessagePacket(); + packet.setType(MessagePacket.TYPE_CHAT); //we want to carbon copy those packet.setTo(proposal.with); final Element propose = packet.addChild("retract", Namespace.JINGLE_MESSAGE); propose.setAttribute("id", proposal.sessionId); diff --git a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java index 2e6436b3d..1aef98afc 100644 --- a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java @@ -8,7 +8,6 @@ import android.view.View; import android.view.WindowManager; import java.lang.ref.WeakReference; -import java.util.Arrays; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; @@ -23,6 +22,8 @@ import rocks.xmpp.addr.Jid; import static java.util.Arrays.asList; +//TODO if last state was BUSY (or RETRY); we want to reset action to view or something so we don’t automatically call again on recreate + public class RtpSessionActivity extends XmppActivity implements XmppConnectionService.OnJingleRtpConnectionUpdate { public static final String EXTRA_WITH = "with"; 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 28e06ed3a..1a66d41b9 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java @@ -236,11 +236,29 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web case "retract": receiveRetract(from, message); break; + case "reject": + receiveReject(from, message); + break; default: break; } } + private void receiveReject(Jid from, Element message) { + final boolean originatedFromMyself = from.asBareJid().equals(id.account.getJid().asBareJid()); + //reject from another one of my clients + if (originatedFromMyself) { + if (transition(State.REJECTED)) { + this.xmppConnectionService.getNotificationService().cancelIncomingCallNotification(); + this.jingleConnectionManager.finishConnection(this); + } else { + Log.d(Config.LOGTAG,"not able to transition into REJECTED because already in "+this.state); + } + } else { + Log.d(Config.LOGTAG,id.account.getJid()+": ignoring reject from "+from+" for session with "+id.with); + } + } + private void receivePropose(final Jid from, final Element propose) { final boolean originatedFromMyself = from.asBareJid().equals(id.account.getJid().asBareJid()); //TODO we can use initiator logic here @@ -269,7 +287,14 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web } else { Log.d(Config.LOGTAG, String.format("%s: ignoring proceed because we were not initializing", id.account.getJid().asBareJid())); } + } else if (from.asBareJid().equals(id.account.getJid().asBareJid())) { + if (transition(State.ACCEPTED)) { + Log.d(Config.LOGTAG,id.account.getJid().asBareJid()+": moved session with "+id.with+" into state accepted after received carbon copied procced"); + this.xmppConnectionService.getNotificationService().cancelIncomingCallNotification(); + this.jingleConnectionManager.finishConnection(this); + } } else { + //TODO a carbon copied proceed from another client of mine has the same logic as `accept` Log.d(Config.LOGTAG, String.format("%s: ignoring proceed from %s. was expected from %s", id.account.getJid().asBareJid(), from, id.with)); } } @@ -442,6 +467,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web private void sendJingleMessage(final String action) { final MessagePacket messagePacket = new MessagePacket(); + messagePacket.setType(MessagePacket.TYPE_CHAT); //we want to carbon copy those messagePacket.setTo(id.with); messagePacket.addChild(action, Namespace.JINGLE_MESSAGE).setAttribute("id", id.sessionId); Log.d(Config.LOGTAG, messagePacket.toString());