use of org.jivesoftware.smack.packet.IQ 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.smack.packet.IQ in project Smack by igniterealtime.
the class TransportNegotiator method receiveContentAcceptAction.
/**
* One of our transport candidates has been accepted.
*
* @param jin The input packet
* @return a Jingle packet
* @throws XMPPException an exception
* @see org.jivesoftware.smackx.jingleold.JingleNegotiator.State#eventAccept(org.jivesoftware.smackx.jingleold.packet.Jingle)
*/
private IQ receiveContentAcceptAction(Jingle jingle) throws XMPPException {
IQ response = null;
// Parse the Jingle and get the accepted candidate
List<TransportCandidate> accepted = obtainCandidatesList(jingle);
if (!accepted.isEmpty()) {
for (TransportCandidate cand : accepted) {
LOGGER.fine("Remote acccepted candidate addr: " + cand.getIp());
}
TransportCandidate cand = accepted.get(0);
setAcceptedLocalCandidate(cand);
if (isEstablished()) {
LOGGER.fine(cand.getIp() + " is set active");
//setNegotiatorState(JingleNegotiatorState.SUCCEEDED);
}
}
return response;
}
use of org.jivesoftware.smack.packet.IQ in project Smack by igniterealtime.
the class TransportNegotiator method receiveSessionAcceptAction.
/**
* @param jingle
* @return the iq
*/
private static IQ receiveSessionAcceptAction(Jingle jingle) {
IQ response = null;
LOGGER.fine("Transport stabilished");
return response;
}
use of org.jivesoftware.smack.packet.IQ in project Smack by igniterealtime.
the class AgentSession method sendRoomInvitation.
/**
* Invites a user or agent to an existing session support. The provided invitee's JID can be of
* a user, an agent, a queue or a workgroup. In the case of a queue or a workgroup the workgroup service
* will decide the best agent to receive the invitation.<p>
*
* This method will return either when the service returned an ACK of the request or if an error occured
* while requesting the invitation. After sending the ACK the service will send the invitation to the target
* entity. When dealing with agents the common sequence of offer-response will be followed. However, when
* sending an invitation to a user a standard MUC invitation will be sent.<p>
*
* The agent or user that accepted the offer <b>MUST</b> join the room. Failing to do so will make
* the invitation to fail. The inviter will eventually receive a message error indicating that the invitee
* accepted the offer but failed to join the room.
*
* Different situations may lead to a failed invitation. Possible cases are: 1) all agents rejected the
* offer and ther are no agents available, 2) the agent that accepted the offer failed to join the room or
* 2) the user that received the MUC invitation never replied or joined the room. In any of these cases
* (or other failing cases) the inviter will get an error message with the failed notification.
*
* @param type type of entity that will get the invitation.
* @param invitee JID of entity that will get the invitation.
* @param sessionID ID of the support session that the invitee is being invited.
* @param reason the reason of the invitation.
* @throws XMPPErrorException if the sender of the invitation is not an agent or the service failed to process
* the request.
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void sendRoomInvitation(RoomInvitation.Type type, String invitee, String sessionID, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
final RoomInvitation invitation = new RoomInvitation(type, invitee, sessionID, reason);
IQ iq = new RoomInvitation.RoomInvitationIQ(invitation);
iq.setType(IQ.Type.set);
iq.setTo(workgroupJID);
iq.setFrom(connection.getUser());
connection.createStanzaCollectorAndSend(iq).nextResultOrThrow();
}
use of org.jivesoftware.smack.packet.IQ in project Smack by igniterealtime.
the class MamPrefIQProviderTest method checkMamPrefResult.
@Test
public void checkMamPrefResult() throws Exception {
IQ iq = (IQ) PacketParserUtils.parseStanza(exampleMamPrefsResultIQ);
MamPrefsIQ mamPrefsIQ = (MamPrefsIQ) iq;
List<Jid> alwaysJids = mamPrefsIQ.getAlwaysJids();
List<Jid> neverJids = mamPrefsIQ.getNeverJids();
Assert.assertEquals(alwaysJids.size(), 1);
Assert.assertEquals(neverJids.size(), 2);
Assert.assertEquals(alwaysJids.get(0).toString(), "romeo@montague.lit");
Assert.assertEquals(neverJids.get(1).toString(), "montague@montague.lit");
}
Aggregations