Search in sources :

Example 21 with IQ

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;
}
Also used : Jingle(org.jivesoftware.smackx.jingleold.packet.Jingle) ArrayList(java.util.ArrayList) IQ(org.jivesoftware.smack.packet.IQ) JingleActionEnum(org.jivesoftware.smackx.jingleold.JingleActionEnum) JingleException(org.jivesoftware.smackx.jingleold.JingleException)

Example 22 with IQ

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;
}
Also used : JingleTransportCandidate(org.jivesoftware.smackx.jingleold.packet.JingleTransport.JingleTransportCandidate) IQ(org.jivesoftware.smack.packet.IQ)

Example 23 with IQ

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;
}
Also used : IQ(org.jivesoftware.smack.packet.IQ)

Example 24 with IQ

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();
}
Also used : RoomInvitation(org.jivesoftware.smackx.workgroup.packet.RoomInvitation) IQ(org.jivesoftware.smack.packet.IQ)

Example 25 with IQ

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");
}
Also used : MamPrefsIQ(org.jivesoftware.smackx.mam.element.MamPrefsIQ) Jid(org.jxmpp.jid.Jid) MamPrefsIQ(org.jivesoftware.smackx.mam.element.MamPrefsIQ) IQ(org.jivesoftware.smack.packet.IQ) Test(org.junit.Test)

Aggregations

IQ (org.jivesoftware.smack.packet.IQ)138 Test (org.junit.Test)57 ErrorIQ (org.jivesoftware.smack.packet.ErrorIQ)12 Stanza (org.jivesoftware.smack.packet.Stanza)12 InputStream (java.io.InputStream)11 StanzaListener (org.jivesoftware.smack.StanzaListener)10 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)10 Data (org.jivesoftware.smackx.bytestreams.ibb.packet.Data)10 DataPacketExtension (org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension)10 OutputStream (java.io.OutputStream)9 ArrayList (java.util.ArrayList)9 Bytestream (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream)8 XMPPError (org.jivesoftware.smack.packet.XMPPError)7 Jid (org.jxmpp.jid.Jid)7 NetworkException (com.xabber.android.data.NetworkException)6 OnResponseListener (com.xabber.android.data.connection.OnResponseListener)6 IOException (java.io.IOException)6 XMPPConnection (org.jivesoftware.smack.XMPPConnection)6 EmptyResultIQ (org.jivesoftware.smack.packet.EmptyResultIQ)6 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)6