From 4ef42075936a49ac848f0b4bef5e0460207a6df9 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 12 Dec 2022 10:15:10 +0100 Subject: [PATCH] show switch to video only if other party has caps fixes #4421 --- .../conversations/ui/RtpSessionActivity.java | 2 +- .../xmpp/jingle/JingleRtpConnection.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java index b91269c25..a052f8b39 100644 --- a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java @@ -217,7 +217,7 @@ public class RtpSessionActivity extends XmppActivity if (connection == null) { return false; } - return Media.audioOnly(connection.getMedia()) && STATES_CONSIDERED_CONNECTED.contains(connection.getEndUserState()); + return connection.isSwitchToVideoAvailable(); } private void switchToConversation() { 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 2581088ca..4c327a31f 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java @@ -45,10 +45,13 @@ import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.crypto.axolotl.CryptoFailedException; import eu.siacs.conversations.crypto.axolotl.FingerprintStatus; import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversational; import eu.siacs.conversations.entities.Message; +import eu.siacs.conversations.entities.Presence; import eu.siacs.conversations.entities.RtpSessionStatus; +import eu.siacs.conversations.entities.ServiceDiscoveryResult; import eu.siacs.conversations.services.AppRTCAudioManager; import eu.siacs.conversations.utils.IP; import eu.siacs.conversations.xml.Element; @@ -2763,6 +2766,25 @@ public class JingleRtpConnection extends AbstractJingleConnection id.account, id.with, id.sessionId, endUserState); } + public boolean isSwitchToVideoAvailable() { + final boolean prerequisite = + Media.audioOnly(getMedia()) + && Arrays.asList(RtpEndUserState.CONNECTED, RtpEndUserState.RECONNECTING) + .contains(getEndUserState()); + return prerequisite && remoteHasVideoFeature(); + } + + private boolean remoteHasVideoFeature() { + final Contact contact = id.getContact(); + final Presence presence = + contact.getPresences().get(Strings.nullToEmpty(id.with.getResource())); + final ServiceDiscoveryResult serviceDiscoveryResult = + presence == null ? null : presence.getServiceDiscoveryResult(); + final List features = + serviceDiscoveryResult == null ? null : serviceDiscoveryResult.getFeatures(); + return features != null && features.contains(Namespace.JINGLE_FEATURE_VIDEO); + } + private interface OnIceServersDiscovered { void onIceServersDiscovered(List iceServers); }