use of org.jivesoftware.smackx.jingleold.JingleActionEnum in project Smack by igniterealtime.
the class TransportNegotiator method dispatchIncomingPacket.
/**
* Dispatch an incoming packet. The method is responsible for recognizing
* the stanza(/packet) type and, depending on the current state, deliverying the
* stanza(/packet) to the right event handler and wait for a response.
*
* @param iq the stanza(/packet) received
* @return the new Jingle stanza(/packet) to send.
* @throws XMPPException
* @throws SmackException
* @throws InterruptedException
*/
@Override
public final List<IQ> dispatchIncomingPacket(IQ iq, String id) throws XMPPException, SmackException, InterruptedException {
List<IQ> responses = new ArrayList<IQ>();
IQ response = null;
if (iq != null) {
if (iq.getType().equals(IQ.Type.error)) {
// Process errors
setNegotiatorState(JingleNegotiatorState.FAILED);
triggerTransportClosed(null);
// This next line seems wrong, and may subvert the normal closing process.
throw new JingleException(iq.getError().getDescriptiveText());
} else if (iq.getType().equals(IQ.Type.result)) {
// Process ACKs
if (isExpectedId(iq.getStanzaId())) {
response = receiveResult(iq);
removeExpectedId(iq.getStanzaId());
}
} else if (iq instanceof Jingle) {
// Get the action from the Jingle packet
Jingle jingle = (Jingle) iq;
JingleActionEnum action = jingle.getAction();
switch(action) {
case CONTENT_ACCEPT:
response = receiveContentAcceptAction(jingle);
break;
case CONTENT_MODIFY:
break;
case CONTENT_REMOVE:
break;
case SESSION_INFO:
break;
case SESSION_INITIATE:
response = receiveSessionInitiateAction(jingle);
break;
case SESSION_ACCEPT:
response = receiveSessionAcceptAction(jingle);
break;
case TRANSPORT_INFO:
response = receiveTransportInfoAction(jingle);
break;
default:
break;
}
}
}
if (response != null) {
addExpectedId(response.getStanzaId());
responses.add(response);
}
return responses;
}
use of org.jivesoftware.smackx.jingleold.JingleActionEnum in project Smack by igniterealtime.
the class JingleProvider method parse.
/**
* Parse a iq/jingle element.
* @throws Exception
*/
@Override
public Jingle parse(XmlPullParser parser, int intialDepth) throws Exception {
Jingle jingle = new Jingle();
String sid = "";
JingleActionEnum action;
Jid initiator = null;
Jid responder = null;
boolean done = false;
JingleContent currentContent = null;
// Sub-elements providers
JingleContentProvider jcp = new JingleContentProvider();
JingleDescriptionProvider jdpAudio = new JingleDescriptionProvider.Audio();
JingleTransportProvider jtpRawUdp = new JingleTransportProvider.RawUdp();
JingleTransportProvider jtpIce = new JingleTransportProvider.Ice();
ExtensionElementProvider<?> jmipAudio = new JingleContentInfoProvider.Audio();
int eventType;
String elementName;
String namespace;
// Get some attributes for the <jingle> element
sid = parser.getAttributeValue("", "sid");
action = JingleActionEnum.getAction(parser.getAttributeValue("", "action"));
initiator = ParserUtils.getJidAttribute(parser, "initiator");
responder = ParserUtils.getJidAttribute(parser, "responder");
jingle.setSid(sid);
jingle.setAction(action);
jingle.setInitiator(initiator);
jingle.setResponder(responder);
// Start processing sub-elements
while (!done) {
eventType = parser.next();
elementName = parser.getName();
namespace = parser.getNamespace();
if (eventType == XmlPullParser.START_TAG) {
if (elementName.equals(JingleContent.NODENAME)) {
// Add a new <content> element to the jingle
currentContent = jcp.parse(parser);
jingle.addContent(currentContent);
} else if (elementName.equals(JingleDescription.NODENAME) && namespace.equals(JingleDescription.Audio.NAMESPACE)) {
// Set the <description> element of the <content>
currentContent.setDescription(jdpAudio.parse(parser));
} else if (elementName.equals(JingleTransport.NODENAME)) {
// Parse the possible transport namespaces
if (namespace.equals(JingleTransport.RawUdp.NAMESPACE)) {
currentContent.addJingleTransport(jtpRawUdp.parse(parser));
} else if (namespace.equals(JingleTransport.Ice.NAMESPACE)) {
currentContent.addJingleTransport(jtpIce.parse(parser));
} else {
throw new SmackException("Unknown transport namespace \"" + namespace + "\" in Jingle packet.");
}
} else if (namespace.equals(JingleContentInfo.Audio.NAMESPACE)) {
jingle.setContentInfo((JingleContentInfo) jmipAudio.parse(parser));
} else {
throw new SmackException("Unknown combination of namespace \"" + namespace + "\" and element name \"" + elementName + "\" in Jingle packet.");
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals(Jingle.getElementName())) {
done = true;
}
}
}
return jingle;
}
use of org.jivesoftware.smackx.jingleold.JingleActionEnum in project Smack by igniterealtime.
the class MediaNegotiator method dispatchIncomingPacket.
/**
* Dispatch an incoming packet. The method is responsible for recognizing
* the stanza(/packet) type and, depending on the current state, delivering the
* stanza(/packet) to the right event handler and wait for a response.
*
* @param iq
* the stanza(/packet) received
* @return the new Jingle stanza(/packet) to send.
* @throws XMPPException
* @throws NotConnectedException
* @throws InterruptedException
*/
@Override
public List<IQ> dispatchIncomingPacket(IQ iq, String id) throws XMPPException, NotConnectedException, InterruptedException {
List<IQ> responses = new ArrayList<IQ>();
IQ response = null;
if (iq.getType().equals(IQ.Type.error)) {
// Process errors
setNegotiatorState(JingleNegotiatorState.FAILED);
triggerMediaClosed(getBestCommonAudioPt());
// This next line seems wrong, and may subvert the normal closing process.
throw new JingleException(iq.getError().getDescriptiveText());
} else if (iq.getType().equals(IQ.Type.result)) {
// Process ACKs
if (isExpectedId(iq.getStanzaId())) {
receiveResult(iq);
removeExpectedId(iq.getStanzaId());
}
} else if (iq instanceof Jingle) {
Jingle jingle = (Jingle) iq;
JingleActionEnum action = jingle.getAction();
// Only act on the JingleContent sections that belong to this media negotiator.
for (JingleContent jingleContent : jingle.getContentsList()) {
if (jingleContent.getName().equals(parentNegotiator.getName())) {
JingleDescription description = jingleContent.getDescription();
if (description != null) {
switch(action) {
case CONTENT_ACCEPT:
response = receiveContentAcceptAction(jingle, description);
break;
case CONTENT_MODIFY:
break;
case CONTENT_REMOVE:
break;
case SESSION_INFO:
response = receiveSessionInfoAction(jingle, description);
break;
case SESSION_INITIATE:
response = receiveSessionInitiateAction(jingle, description);
break;
case SESSION_ACCEPT:
response = receiveSessionAcceptAction(jingle, description);
break;
default:
break;
}
}
}
}
}
if (response != null) {
addExpectedId(response.getStanzaId());
responses.add(response);
}
return responses;
}
Aggregations