From 4d70855b4c4f74e3b7fe2869340c851b1145a9b1 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 5 Apr 2020 10:55:36 +0200 Subject: [PATCH] sdp to ice transport conversion --- .../xmpp/jingle/RtpContentMap.java | 2 +- .../jingle/stanzas/IceUdpTransportInfo.java | 48 ++++++++++++++++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/RtpContentMap.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/RtpContentMap.java index 681686fb9..f1dd58aba 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/RtpContentMap.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/RtpContentMap.java @@ -91,7 +91,7 @@ public class RtpContentMap { public static DescriptionTransport of(final SessionDescription sessionDescription, final SessionDescription.Media media) { final RtpDescription rtpDescription = RtpDescription.of(media); - final IceUdpTransportInfo transportInfo = new IceUdpTransportInfo(); + final IceUdpTransportInfo transportInfo = IceUdpTransportInfo.of(sessionDescription, media); return new DescriptionTransport(rtpDescription, transportInfo); } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/IceUdpTransportInfo.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/IceUdpTransportInfo.java index 52868f136..275f6cd2b 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/IceUdpTransportInfo.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/IceUdpTransportInfo.java @@ -1,16 +1,19 @@ package eu.siacs.conversations.xmpp.jingle.stanzas; import com.google.common.base.Preconditions; +import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; import java.util.List; import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Namespace; +import eu.siacs.conversations.xmpp.jingle.SessionDescription; public class IceUdpTransportInfo extends GenericTransportInfo { - public IceUdpTransportInfo() { + private IceUdpTransportInfo() { super("transport", Namespace.JINGLE_TRANSPORT_ICE_UDP); } @@ -21,7 +24,7 @@ public class IceUdpTransportInfo extends GenericTransportInfo { public List getCandidates() { final ImmutableList.Builder builder = new ImmutableList.Builder<>(); - for(final Element child : getChildren()) { + for (final Element child : getChildren()) { if ("candidate".equals(child.getName())) { builder.add(Candidate.upgrade(child)); } @@ -38,6 +41,24 @@ public class IceUdpTransportInfo extends GenericTransportInfo { return transportInfo; } + public static IceUdpTransportInfo of(SessionDescription sessionDescription, SessionDescription.Media media) { + final String ufrag = Iterables.getFirst(media.attributes.get("ice-ufrag"), null); + final String pwd = Iterables.getFirst(media.attributes.get("ice-pwd"), null); + IceUdpTransportInfo iceUdpTransportInfo = new IceUdpTransportInfo(); + if (ufrag != null) { + iceUdpTransportInfo.setAttribute("ufrag", ufrag); + } + if (pwd != null) { + iceUdpTransportInfo.setAttribute("pwd", pwd); + } + final Fingerprint fingerprint = Fingerprint.of(sessionDescription, media); + if (fingerprint != null) { + iceUdpTransportInfo.addChild(fingerprint); + } + return iceUdpTransportInfo; + + } + public static class Candidate extends Element { private Candidate() { @@ -136,5 +157,28 @@ public class IceUdpTransportInfo extends GenericTransportInfo { fingerprint.setContent(element.getContent()); return fingerprint; } + + private static Fingerprint of(ArrayListMultimap attributes) { + final String fingerprint = Iterables.getFirst(attributes.get("fingerprint"), null); + final String setup = Iterables.getFirst(attributes.get("setup"), null); + if (setup != null && fingerprint != null) { + final String[] fingerprintParts = fingerprint.split(" ", 2); + if (fingerprintParts.length == 2) { + final String hash = fingerprintParts[0]; + final String actualFingerprint = fingerprintParts[1]; + final Fingerprint element = new Fingerprint(); + element.setAttribute("hash", hash); + element.setAttribute("setup", setup); + element.setContent(actualFingerprint); + return element; + } + } + return null; + } + + public static Fingerprint of(final SessionDescription sessionDescription, final SessionDescription.Media media) { + final Fingerprint fingerprint = of(media.attributes); + return fingerprint == null ? of(sessionDescription.attributes) : fingerprint; + } } }