@Override
    public List<IQ> dispatchIncomingPacket(IQ iq, String id) throws XMPPException, SmackException, InterruptedException {
        List<IQ> responses = new ArrayList<>();
        IQ response = null;

        if (iq != null) {
            if (iq.getType().equals(IQ.Type.error)) {
                // Process errors
                // TODO getState().eventError(iq);
            } else if (iq.getType().equals(IQ.Type.result)) {
                // Process ACKs
                if (isExpectedId(iq.getStanzaId())) {

                    // The other side provisionally accepted our session-initiate.
                    // Kick off some negotiators.
                    if (iq.getStanzaId().equals(sessionInitPacketID)) {
                        startNegotiators();
                    }
                    removeExpectedId(iq.getStanzaId());
                }
            } else if (iq instanceof Jingle) {
                // It is not an error: it is a Jingle packet...
                Jingle jin = (Jingle) iq;
                JingleActionEnum action = jin.getAction();

                // Depending on the state we're in we'll get different processing actions.
                // (See Design Patterns AKA GoF State behavioral pattern.)
                response = getSessionState().processJingle(this, jin, action);
            }
        }

        if (response != null) {
            // Save the packet id, for recognizing ACKs...
            addExpectedId(response.getStanzaId());
            responses.add(response);
        }

        return responses;
    }
@ Override public List < IQ > dispatchIncomingPacket ( IQ iq , String id ) throws XMPPException , SmackException , InterruptedException { List < IQ > responses = new ArrayList < > ( ) ; IQ response = null ; if ( iq != null ) { if ( iq . getType ( ) . equals ( IQ . Type . error ) ) { } else if ( iq . getType ( ) . equals ( IQ . Type . result ) ) { if ( isExpectedId ( iq . getStanzaId ( ) ) ) { if ( iq . getStanzaId ( ) . equals ( sessionInitPacketID ) ) { startNegotiators ( ) ; } removeExpectedId ( iq . getStanzaId ( ) ) ; } } else if ( iq instanceof Jingle ) { Jingle jin = ( Jingle ) iq ; JingleActionEnum action = jin . getAction ( ) ; response = getSessionState ( ) . processJingle ( this , jin , action ) ; } } if ( response != null ) { addExpectedId ( response . getStanzaId ( ) ) ; responses . add ( response ) ; } return responses ; }
Dispatch an incoming packet. The method is responsible for recognizing
the stanza type and, depending on the current state, delivering the
stanza to the right event handler and wait for a response.

@param iq
the stanza received
@return the new Jingle stanza to send.
@throws XMPPException
@throws SmackException
@throws InterruptedException