From 0ce49bf2b1e9c57e4348d93e2db26cc0e9d9230a Mon Sep 17 00:00:00 2001 From: Jasper Hugo Date: Tue, 6 Sep 2022 14:56:22 +0700 Subject: [PATCH] Create parameter elements inside sources with the correct namespace --- .../colibri/ColibriConferenceIqProvider.java | 15 +-- .../colibri/SourcePacketExtension.java | 12 +- .../colibri/json/JSONDeserializer.java | 2 +- .../colibri/json/JSONSerializer.java | 40 ++++++- .../extensions/colibri2/IqProviderUtils.java | 3 + .../extensions/jingle/JingleIQProvider.java | 9 +- .../SourceParameterPacketExtension.java | 109 ++++++++++++++++++ .../json/Colibri2JSONSerializerTest.kt | 4 +- 8 files changed, 173 insertions(+), 21 deletions(-) create mode 100644 src/main/java/org/jitsi/xmpp/extensions/jingle/SourceParameterPacketExtension.java diff --git a/src/main/java/org/jitsi/xmpp/extensions/colibri/ColibriConferenceIqProvider.java b/src/main/java/org/jitsi/xmpp/extensions/colibri/ColibriConferenceIqProvider.java index 6cce8306..b074a351 100644 --- a/src/main/java/org/jitsi/xmpp/extensions/colibri/ColibriConferenceIqProvider.java +++ b/src/main/java/org/jitsi/xmpp/extensions/colibri/ColibriConferenceIqProvider.java @@ -80,19 +80,16 @@ public ColibriConferenceIqProvider() SourceRidGroupPacketExtension.NAMESPACE, new DefaultPacketExtensionProvider<>( SourceRidGroupPacketExtension.class)); - - ExtensionElementProvider parameterProvider - = new DefaultPacketExtensionProvider<>( - ParameterPacketExtension.class); - ProviderManager.addExtensionProvider( ParameterPacketExtension.ELEMENT, ColibriConferenceIQ.NAMESPACE, - parameterProvider); + new DefaultPacketExtensionProvider<>( + ParameterPacketExtension.class)); ProviderManager.addExtensionProvider( - ParameterPacketExtension.ELEMENT, - SourcePacketExtension.NAMESPACE, - parameterProvider); + SourceParameterPacketExtension.ELEMENT, + SourceParameterPacketExtension.NAMESPACE, + new DefaultPacketExtensionProvider<>( + SourceParameterPacketExtension.class)); // ssrc-info ProviderManager.addExtensionProvider( diff --git a/src/main/java/org/jitsi/xmpp/extensions/colibri/SourcePacketExtension.java b/src/main/java/org/jitsi/xmpp/extensions/colibri/SourcePacketExtension.java index 44da8482..97b9af6c 100644 --- a/src/main/java/org/jitsi/xmpp/extensions/colibri/SourcePacketExtension.java +++ b/src/main/java/org/jitsi/xmpp/extensions/colibri/SourcePacketExtension.java @@ -78,10 +78,10 @@ public SourcePacketExtension() * Adds a specific parameter (as defined by Source-Specific Media Attributes * in Jingle) to this source. * - * @param parameter the ParameterPacketExtension to add to this + * @param parameter the SourceParameterPacketExtension to add to this * source */ - public void addParameter(ParameterPacketExtension parameter) + public void addParameter(SourceParameterPacketExtension parameter) { addChildExtension(parameter); } @@ -90,11 +90,11 @@ public void addParameter(ParameterPacketExtension parameter) * Gets the parameters (as defined by Source-Specific Media Attributes in * Jingle) of this source. * - * @return the ParameterPacketExtensions of this source + * @return the SourceParameterPacketExtensions of this source */ - public List getParameters() + public List getParameters() { - return getChildExtensionsOfType(ParameterPacketExtension.class); + return getChildExtensionsOfType(SourceParameterPacketExtension.class); } /** @@ -104,7 +104,7 @@ public List getParameters() */ public String getParameter(String name) { - for (ParameterPacketExtension param : getParameters()) + for (SourceParameterPacketExtension param : getParameters()) { if (name.equals(param.getName())) return param.getValue(); diff --git a/src/main/java/org/jitsi/xmpp/extensions/colibri/json/JSONDeserializer.java b/src/main/java/org/jitsi/xmpp/extensions/colibri/json/JSONDeserializer.java index ff9335a2..fecaade7 100644 --- a/src/main/java/org/jitsi/xmpp/extensions/colibri/json/JSONDeserializer.java +++ b/src/main/java/org/jitsi/xmpp/extensions/colibri/json/JSONDeserializer.java @@ -922,7 +922,7 @@ else if (source instanceof JSONObject) if ((paramName != null) || (paramValue != null)) { sourceIQ.addParameter( - new ParameterPacketExtension( + new SourceParameterPacketExtension( Objects.toString(paramName, null), Objects.toString(paramValue, null))); } diff --git a/src/main/java/org/jitsi/xmpp/extensions/colibri/json/JSONSerializer.java b/src/main/java/org/jitsi/xmpp/extensions/colibri/json/JSONSerializer.java index 0bf995ff..92844a86 100644 --- a/src/main/java/org/jitsi/xmpp/extensions/colibri/json/JSONSerializer.java +++ b/src/main/java/org/jitsi/xmpp/extensions/colibri/json/JSONSerializer.java @@ -84,6 +84,13 @@ public final class JSONSerializer static final String PARAMETERS = ParameterPacketExtension.ELEMENT + "s"; + /** + * The name of the JSON pair which specifies the value of the + * parameters property of SourcePacketExtension. + */ + static final String SOURCE_PARAMETERS + = SourceParameterPacketExtension.ELEMENT + "s"; + /** * The name of the JSON pair which specifies the value of the * payloadTypes property of ColibriConferenceIQ.Channel. @@ -704,6 +711,35 @@ public static JSONObject serializeParameters( return parametersJSONObject; } + public static JSONObject serializeSourceParameters( + Collection parameters) + { + /* + * A parameter is a key-value pair and the order of the parameters in a + * payload-type does not appear to matter so a natural representation of + * a parameter set is a JSONObject rather than a JSONArray. + */ + JSONObject parametersJSONObject; + + if (parameters == null) + { + parametersJSONObject = null; + } + else + { + parametersJSONObject = new JSONObject(); + for (SourceParameterPacketExtension parameter : parameters) + { + String name = parameter.getName(); + String value = parameter.getValue(); + + if ((name != null) || (value != null)) + parametersJSONObject.put(name, value); + } + } + return parametersJSONObject; + } + public static JSONArray serializeRtcpFbs( @NotNull Collection rtcpFbs) { @@ -914,7 +950,7 @@ public static Object serializeSource(SourcePacketExtension source) String name = source.getName(); String videoType = source.getVideoType(); String rid = source.getRid(); - List parameters = source.getParameters(); + List parameters = source.getParameters(); /* Backward compatibility - sources used to just be their ssrc values. */ if (name == null && rid == null && parameters.isEmpty()) @@ -939,7 +975,7 @@ public static Object serializeSource(SourcePacketExtension source) } if (!parameters.isEmpty()) { - sourceJSONObject.put(JSONSerializer.PARAMETERS, serializeParameters(parameters)); + sourceJSONObject.put(JSONSerializer.SOURCE_PARAMETERS, serializeSourceParameters(parameters)); } return sourceJSONObject; diff --git a/src/main/java/org/jitsi/xmpp/extensions/colibri2/IqProviderUtils.java b/src/main/java/org/jitsi/xmpp/extensions/colibri2/IqProviderUtils.java index 49d93693..aab9aaec 100644 --- a/src/main/java/org/jitsi/xmpp/extensions/colibri2/IqProviderUtils.java +++ b/src/main/java/org/jitsi/xmpp/extensions/colibri2/IqProviderUtils.java @@ -155,6 +155,9 @@ public static void registerProviders() ProviderManager.addExtensionProvider(ParameterPacketExtension.ELEMENT, ParameterPacketExtension.NAMESPACE, new DefaultPacketExtensionProvider<>(ParameterPacketExtension.class)); + ProviderManager.addExtensionProvider(SourceParameterPacketExtension.ELEMENT, + SourceParameterPacketExtension.NAMESPACE, + new DefaultPacketExtensionProvider<>(SourceParameterPacketExtension.class)); ProviderManager.addExtensionProvider(RTPHdrExtPacketExtension.ELEMENT, RTPHdrExtPacketExtension.NAMESPACE, new DefaultPacketExtensionProvider<>(RTPHdrExtPacketExtension.class)); diff --git a/src/main/java/org/jitsi/xmpp/extensions/jingle/JingleIQProvider.java b/src/main/java/org/jitsi/xmpp/extensions/jingle/JingleIQProvider.java index f4a748fa..22874f58 100644 --- a/src/main/java/org/jitsi/xmpp/extensions/jingle/JingleIQProvider.java +++ b/src/main/java/org/jitsi/xmpp/extensions/jingle/JingleIQProvider.java @@ -61,10 +61,17 @@ public JingleIQProvider() // provider ProviderManager.addExtensionProvider( ParameterPacketExtension.ELEMENT, - RtpDescriptionPacketExtension.NAMESPACE, + ParameterPacketExtension.NAMESPACE, new DefaultPacketExtensionProvider <>(ParameterPacketExtension.class)); + // inside provider + ProviderManager.addExtensionProvider( + SourceParameterPacketExtension.ELEMENT, + SourceParameterPacketExtension.NAMESPACE, + new DefaultPacketExtensionProvider + <>(SourceParameterPacketExtension.class)); + // provider ProviderManager.addExtensionProvider( RTPHdrExtPacketExtension.ELEMENT, diff --git a/src/main/java/org/jitsi/xmpp/extensions/jingle/SourceParameterPacketExtension.java b/src/main/java/org/jitsi/xmpp/extensions/jingle/SourceParameterPacketExtension.java new file mode 100644 index 00000000..b4dd48c4 --- /dev/null +++ b/src/main/java/org/jitsi/xmpp/extensions/jingle/SourceParameterPacketExtension.java @@ -0,0 +1,109 @@ +/* + * Copyright @ 2018 - present 8x8, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jitsi.xmpp.extensions.jingle; + +import org.jitsi.xmpp.extensions.*; +import org.jitsi.xmpp.extensions.colibri.*; + +/** + * Represents the parameter elements described in XEP-0167. + * + * @author Emil Ivov + */ +public class SourceParameterPacketExtension extends AbstractPacketExtension +{ + /** + * The name of the "parameter" element. + */ + public static final String ELEMENT = "parameter"; + + /** + * XML namespace of this extension. + */ + public static final String NAMESPACE = SourcePacketExtension.NAMESPACE; + + /** + * The name of the name parameter in the parameter + * element. + */ + public static final String NAME_ATTR_NAME = "name"; + + /** + * The name of the value parameter in the parameter + * element. + */ + public static final String VALUE_ATTR_NAME = "value"; + + /** + * Creates a new {@link SourceParameterPacketExtension} instance. + */ + public SourceParameterPacketExtension() + { + super(NAMESPACE, ELEMENT); + } + + /** + * Creates a new {@link SourceParameterPacketExtension} instance and + * sets the given name and value. + */ + public SourceParameterPacketExtension(String name, String value) + { + super(NAMESPACE, ELEMENT); + + setName(name); + setValue(value); + } + + /** + * Sets the name of the format parameter we are representing here. + * + * @param name the name of the format parameter we are representing here. + */ + public void setName(String name) + { + super.setAttribute(NAME_ATTR_NAME, name); + } + + /** + * Returns the name of the format parameter we are representing here. + * + * @return the name of the format parameter we are representing here. + */ + public String getName() + { + return super.getAttributeAsString(NAME_ATTR_NAME); + } + + /** + * Sets that value of the format parameter we are representing here. + * + * @param value the value of the format parameter we are representing here. + */ + public void setValue(String value) + { + super.setAttribute(VALUE_ATTR_NAME, value); + } + + /** + * Returns the value of the format parameter we are representing here. + * + * @return the value of the format parameter we are representing here. + */ + public String getValue() + { + return super.getAttributeAsString(VALUE_ATTR_NAME); + } +} diff --git a/src/test/kotlin/org/jitsi/xmpp/extensions/colibri2/json/Colibri2JSONSerializerTest.kt b/src/test/kotlin/org/jitsi/xmpp/extensions/colibri2/json/Colibri2JSONSerializerTest.kt index 73a908b0..d2e729dc 100644 --- a/src/test/kotlin/org/jitsi/xmpp/extensions/colibri2/json/Colibri2JSONSerializerTest.kt +++ b/src/test/kotlin/org/jitsi/xmpp/extensions/colibri2/json/Colibri2JSONSerializerTest.kt @@ -297,12 +297,12 @@ private val expectedMappings = listOf( - + - +