1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-24 04:52:05 +01:00

Merge branch 'jingleS5B' into jingle2

This commit is contained in:
vanitasvitae 2017-06-18 12:32:08 +02:00
commit d0701f8fd1
3 changed files with 57 additions and 55 deletions

View file

@ -41,6 +41,7 @@ public class JingleS5BTransport extends JingleContentTransport {
protected JingleS5BTransport(List<JingleContentTransportCandidate> candidates, List<JingleContentTransportInfo> infos, String streamId, String dstAddr, Bytestream.Mode mode) { protected JingleS5BTransport(List<JingleContentTransportCandidate> candidates, List<JingleContentTransportInfo> infos, String streamId, String dstAddr, Bytestream.Mode mode) {
super(candidates, infos); super(candidates, infos);
StringUtils.requireNotNullOrEmpty(streamId, "sid MUST be neither null, nor empty.");
this.streamId = streamId; this.streamId = streamId;
this.dstAddr = dstAddr; this.dstAddr = dstAddr;
this.mode = mode; this.mode = mode;
@ -137,7 +138,6 @@ public class JingleS5BTransport extends JingleContentTransport {
} }
public JingleS5BTransport build() { public JingleS5BTransport build() {
StringUtils.requireNotNullOrEmpty(streamId, "sid MUST be neither null, nor empty.");
return new JingleS5BTransport(candidates, infos, streamId, dstAddr, mode); return new JingleS5BTransport(candidates, infos, streamId, dstAddr, mode);
} }
} }

View file

@ -50,6 +50,14 @@ public final class JingleS5BTransportCandidate extends JingleContentTransportCan
private final Type type; private final Type type;
public JingleS5BTransportCandidate(String candidateId, String host, Jid jid, int port, int priority, Type type) { public JingleS5BTransportCandidate(String candidateId, String host, Jid jid, int port, int priority, Type type) {
Objects.requireNonNull(candidateId);
Objects.requireNonNull(host);
Objects.requireNonNull(jid);
if (priority < 0) {
throw new IllegalArgumentException("Priority MUST be present and NOT less than 0.");
}
this.cid = candidateId; this.cid = candidateId;
this.host = host; this.host = host;
this.jid = jid; this.jid = jid;
@ -59,12 +67,7 @@ public final class JingleS5BTransportCandidate extends JingleContentTransportCan
} }
public JingleS5BTransportCandidate(Bytestream.StreamHost streamHost, int priority) { public JingleS5BTransportCandidate(Bytestream.StreamHost streamHost, int priority) {
this.cid = StringUtils.randomString(24); this(StringUtils.randomString(24), streamHost.getAddress(), streamHost.getJID(), streamHost.getPort(), priority, Type.proxy);
this.host = streamHost.getAddress();
this.jid = streamHost.getJID();
this.port = streamHost.getPort();
this.priority = priority;
this.type = Type.proxy;
} }
public enum Type { public enum Type {
@ -191,12 +194,6 @@ public final class JingleS5BTransportCandidate extends JingleContentTransportCan
} }
public JingleS5BTransportCandidate build() { public JingleS5BTransportCandidate build() {
Objects.requireNonNull(cid);
Objects.requireNonNull(host);
Objects.requireNonNull(jid);
if (priority < 0) {
throw new IllegalArgumentException("Priority MUST be present and NOT less than 0.");
}
return new JingleS5BTransportCandidate(cid, host, jid, port, priority, type); return new JingleS5BTransportCandidate(cid, host, jid, port, priority, type);
} }
} }

View file

@ -56,58 +56,63 @@ public class JingleS5BTransportProvider extends JingleContentTransportProvider<J
} }
JingleS5BTransportCandidate.Builder cb; JingleS5BTransportCandidate.Builder cb;
while (true) { outerloop: while (true) {
int tag = parser.nextTag(); int tag = parser.nextTag();
String name = parser.getName(); String name = parser.getName();
if (tag == START_TAG) { switch (tag) {
switch (name) { case START_TAG: {
switch (name) {
case JingleS5BTransportCandidate.ELEMENT: case JingleS5BTransportCandidate.ELEMENT:
cb = JingleS5BTransportCandidate.getBuilder(); cb = JingleS5BTransportCandidate.getBuilder();
cb.setCandidateId(parser.getAttributeValue(null, ATTR_CID)); cb.setCandidateId(parser.getAttributeValue(null, ATTR_CID));
cb.setHost(parser.getAttributeValue(null, ATTR_HOST)); cb.setHost(parser.getAttributeValue(null, ATTR_HOST));
cb.setJid(parser.getAttributeValue(null, ATTR_JID)); cb.setJid(parser.getAttributeValue(null, ATTR_JID));
cb.setPriority(Integer.parseInt(parser.getAttributeValue(null, ATTR_PRIORITY))); cb.setPriority(Integer.parseInt(parser.getAttributeValue(null, ATTR_PRIORITY)));
String portString = parser.getAttributeValue(null, ATTR_PORT); String portString = parser.getAttributeValue(null, ATTR_PORT);
if (portString != null) { if (portString != null) {
cb.setPort(Integer.parseInt(portString)); cb.setPort(Integer.parseInt(portString));
}
String typeString = parser.getAttributeValue(null, ATTR_TYPE);
if (typeString != null) {
cb.setType(JingleS5BTransportCandidate.Type.fromString(typeString));
}
builder.addTransportCandidate(cb.build());
break;
case JingleS5BTransportInfo.CandidateActivated.ELEMENT:
builder.addTransportInfo(JingleS5BTransportInfo.CandidateActivated(
parser.getAttributeValue(null,
JingleS5BTransportInfo.CandidateActivated.ATTR_CID)));
break;
case JingleS5BTransportInfo.CandidateUsed.ELEMENT:
builder.addTransportInfo(JingleS5BTransportInfo.CandidateUsed(
parser.getAttributeValue(null,
JingleS5BTransportInfo.CandidateUsed.ATTR_CID)));
break;
case JingleS5BTransportInfo.CandidateError.ELEMENT:
builder.addTransportInfo(JingleS5BTransportInfo.CandidateError());
break;
case JingleS5BTransportInfo.ProxyError.ELEMENT:
builder.addTransportInfo(JingleS5BTransportInfo.ProxyError());
break;
} }
}
break;
String typeString = parser.getAttributeValue(null, ATTR_TYPE); case END_TAG: {
if (typeString != null) { switch (name) {
cb.setType(JingleS5BTransportCandidate.Type.fromString(typeString)); case JingleContentTransport.ELEMENT:
break outerloop;
} }
builder.addTransportCandidate(cb.build());
break;
case JingleS5BTransportInfo.CandidateActivated.ELEMENT:
builder.addTransportInfo(JingleS5BTransportInfo.CandidateActivated(
parser.getAttributeValue(null,
JingleS5BTransportInfo.CandidateActivated.ATTR_CID)));
break;
case JingleS5BTransportInfo.CandidateUsed.ELEMENT:
builder.addTransportInfo(JingleS5BTransportInfo.CandidateUsed(
parser.getAttributeValue(null,
JingleS5BTransportInfo.CandidateUsed.ATTR_CID)));
break;
case JingleS5BTransportInfo.CandidateError.ELEMENT:
builder.addTransportInfo(JingleS5BTransportInfo.CandidateError());
break;
case JingleS5BTransportInfo.ProxyError.ELEMENT:
builder.addTransportInfo(JingleS5BTransportInfo.ProxyError());
break;
} }
} }
if (tag == END_TAG && name.equals(JingleContentTransport.ELEMENT)) {
break;
}
} }
return builder.build(); return builder.build();
} }
} }