mirror of https://github.com/sipwise/jitsi.git
parent
4d97b7349b
commit
b7e2854f3b
@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package org.jitsi.jirecon.extension;
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
|
||||
/**
|
||||
* SctpMap extension in transport packet extension.
|
||||
* Defined by XEP-0343: Signaling WebRTC datachannels in Jingle.
|
||||
*
|
||||
* @author lishunyang
|
||||
*
|
||||
*/
|
||||
public class SctpMapExtension
|
||||
implements PacketExtension
|
||||
{
|
||||
/**
|
||||
* The name of the "sctpmap" element.
|
||||
*/
|
||||
public static final String ELEMENT_NAME = "sctpmap";
|
||||
|
||||
/**
|
||||
* The namespace for the "sctpmap" element.
|
||||
*/
|
||||
public static final String NAMESPACE =
|
||||
"urn:xmpp:jingle:transports:dtls-sctp:1";
|
||||
|
||||
/**
|
||||
* Port number of "sctpmap" element.
|
||||
*/
|
||||
public static final String PORT_ATTR_NAME = "number";
|
||||
|
||||
/**
|
||||
* Protocol name of "sctpmap" element.
|
||||
*/
|
||||
public static final String PROTOCOL_ATTR_NAME = "protocol";
|
||||
|
||||
/**
|
||||
* Number of streams of "sctpmap" element.
|
||||
*/
|
||||
public static final String STREAMS_ATTR_NAME = "streams";
|
||||
|
||||
/**
|
||||
* Value of "port".
|
||||
*/
|
||||
private int port = -1;
|
||||
|
||||
/**
|
||||
* Value of "protocol".
|
||||
* @See SctpMapExtension.Protocol
|
||||
*/
|
||||
private String protocol = "";
|
||||
|
||||
/**
|
||||
* Number of "streams".
|
||||
*/
|
||||
private int streams = -1;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getElementName()
|
||||
{
|
||||
return ELEMENT_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getNamespace()
|
||||
{
|
||||
return NAMESPACE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String toXML()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("<").append(getElementName());
|
||||
builder.append(" ").append("xmlns").append("='").append(getNamespace())
|
||||
.append("'");
|
||||
builder.append(" ").append(PORT_ATTR_NAME).append("='").append(port)
|
||||
.append("'");
|
||||
builder.append(" ").append(PROTOCOL_ATTR_NAME).append("='")
|
||||
.append(protocol).append("'");
|
||||
builder.append(" ").append(STREAMS_ATTR_NAME).append("='")
|
||||
.append(streams).append("'");
|
||||
builder.append("/>");
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public void setPort(int port)
|
||||
{
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public int getPort()
|
||||
{
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setProtocol(String protocol)
|
||||
{
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
public void setProtocol(Protocol protocol)
|
||||
{
|
||||
this.protocol = protocol.toString();
|
||||
}
|
||||
|
||||
public String getProtocol()
|
||||
{
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public void setStreams(int streams)
|
||||
{
|
||||
this.streams = streams;
|
||||
}
|
||||
|
||||
public int getStreams()
|
||||
{
|
||||
return streams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protocol enumeration of <tt>SctpMapExtension</tt>. Currently it only
|
||||
* contains WEBRTC_CHANNEL.
|
||||
*
|
||||
* @author lishunyang
|
||||
*
|
||||
*/
|
||||
public static enum Protocol
|
||||
{
|
||||
WEBRTC_CHANNEL("webrtc-datachannel");
|
||||
|
||||
private String name;
|
||||
|
||||
private Protocol(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package org.jitsi.jirecon.extension;
|
||||
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
import org.jivesoftware.smack.provider.*;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
* The <tt>SctpMapExtensionProvider</tt> parses "sctpmap" elements into
|
||||
* <tt>SctpMapExtension</tt> instances.
|
||||
*
|
||||
* @author lishunyang
|
||||
* @see SctpMapExtension
|
||||
*/
|
||||
public class SctpMapExtensionProvider
|
||||
implements PacketExtensionProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public PacketExtension parseExtension(XmlPullParser parser)
|
||||
throws Exception
|
||||
{
|
||||
SctpMapExtension result = new SctpMapExtension();
|
||||
|
||||
if (parser.getName().equals(SctpMapExtension.ELEMENT_NAME)
|
||||
&& parser.getNamespace().equals(SctpMapExtension.NAMESPACE))
|
||||
{
|
||||
result.setPort(Integer.parseInt(parser.getAttributeValue(null,
|
||||
SctpMapExtension.PORT_ATTR_NAME)));
|
||||
result.setProtocol(parser.getAttributeValue(null,
|
||||
SctpMapExtension.PROTOCOL_ATTR_NAME));
|
||||
result.setStreams(Integer.parseInt(parser.getAttributeValue(null,
|
||||
SctpMapExtension.STREAMS_ATTR_NAME)));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue