Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create parameter elements inside sources with the correct namespace #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,16 @@ public ColibriConferenceIqProvider()
SourceRidGroupPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider<>(
SourceRidGroupPacketExtension.class));

ExtensionElementProvider<ParameterPacketExtension> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tt>ParameterPacketExtension</tt> to add to this
* @param parameter the <tt>SourceParameterPacketExtension</tt> to add to this
* source
*/
public void addParameter(ParameterPacketExtension parameter)
public void addParameter(SourceParameterPacketExtension parameter)
{
addChildExtension(parameter);
}
Expand All @@ -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 <tt>ParameterPacketExtension</tt>s of this source
* @return the <tt>SourceParameterPacketExtension</tt>s of this source
*/
public List<ParameterPacketExtension> getParameters()
public List<SourceParameterPacketExtension> getParameters()
{
return getChildExtensionsOfType(ParameterPacketExtension.class);
return getChildExtensionsOfType(SourceParameterPacketExtension.class);
}

/**
Expand All @@ -104,7 +104,7 @@ public List<ParameterPacketExtension> getParameters()
*/
public String getParameter(String name)
{
for (ParameterPacketExtension param : getParameters())
for (SourceParameterPacketExtension param : getParameters())
{
if (name.equals(param.getName()))
return param.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <tt>parameters</tt> property of <tt>SourcePacketExtension</tt>.
*/
static final String SOURCE_PARAMETERS
= SourceParameterPacketExtension.ELEMENT + "s";

/**
* The name of the JSON pair which specifies the value of the
* <tt>payloadTypes</tt> property of <tt>ColibriConferenceIQ.Channel</tt>.
Expand Down Expand Up @@ -704,6 +711,35 @@ public static JSONObject serializeParameters(
return parametersJSONObject;
}

public static JSONObject serializeSourceParameters(
Collection<SourceParameterPacketExtension> 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<RtcpFbPacketExtension> rtcpFbs)
{
Expand Down Expand Up @@ -914,7 +950,7 @@ public static Object serializeSource(SourcePacketExtension source)
String name = source.getName();
String videoType = source.getVideoType();
String rid = source.getRid();
List<ParameterPacketExtension> parameters = source.getParameters();
List<SourceParameterPacketExtension> parameters = source.getParameters();

/* Backward compatibility - sources used to just be their ssrc values. */
if (name == null && rid == null && parameters.isEmpty())
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,17 @@ public JingleIQProvider()
//<parameter/> provider
ProviderManager.addExtensionProvider(
ParameterPacketExtension.ELEMENT,
RtpDescriptionPacketExtension.NAMESPACE,
ParameterPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider
<>(ParameterPacketExtension.class));

//<parameter/> inside <source/> provider
ProviderManager.addExtensionProvider(
SourceParameterPacketExtension.ELEMENT,
SourceParameterPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider
<>(SourceParameterPacketExtension.class));

//<rtp-hdrext/> provider
ProviderManager.addExtensionProvider(
RTPHdrExtPacketExtension.ELEMENT,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <tt>parameter</tt> 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 <tt>name</tt> parameter in the <tt>parameter</tt>
* element.
*/
public static final String NAME_ATTR_NAME = "name";

/**
* The name of the <tt>value</tt> parameter in the <tt>parameter</tt>
* 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,12 @@ private val expectedMappings = listOf(
<sources xmlns="jitsi:colibri2">
<media-source type="audio" id="jvb-a0">
<source xmlns="urn:xmpp:jingle:apps:rtp:ssma:0" ssrc="411312308" name="jvb-a0">
<parameter xmlns="urn:xmpp:jingle:apps:rtp:1" name="msid" value="mixedmslabel mixedlabelaudio0"/>
<parameter name="msid" value="mixedmslabel mixedlabelaudio0"/>
</source>
</media-source>
<media-source type="video" id="jvb-v0">
<source xmlns="urn:xmpp:jingle:apps:rtp:ssma:0" ssrc="3929652146" name="jvb-v0">
<parameter xmlns="urn:xmpp:jingle:apps:rtp:1" name="msid" value="mixedmslabel mixedlabelvideo0"/>
<parameter name="msid" value="mixedmslabel mixedlabelvideo0"/>
</source>
</media-source>
</sources>
Expand Down