public synchronized void receivePacketAndRespond ( IQ iq ) throws XMPPException , SmackException , InterruptedException { List < IQ > responses = new ArrayList <> ( ) ; String responseId ; LOGGER . fine ( "Packet: " + iq . toXML ( ) ) ; try { // Dispatch the packet to the JingleNegotiators and get back a list of the results. responses . addAll ( dispatchIncomingPacket ( iq , null ) ) ; if ( iq != null ) { responseId = iq . getStanzaId ( ) ; // Send the IQ to each of the content negotiators for further processing. // Each content negotiator may pass back a list of JingleContent for addition to the response packet. // CHECKSTYLE:OFF for ( ContentNegotiator contentNegotiator : contentNegotiators ) { // If at this point the content negotiator isn't started, it's because we sent a session-init jingle // packet from startOutgoing() and we're waiting for the other side to let us know they're ready // to take jingle packets. (This packet might be a session-terminate, but that will get handled // later. if ( ! contentNegotiator . isStarted ( ) ) { contentNegotiator . start ( ) ; } responses . addAll ( contentNegotiator . dispatchIncomingPacket ( iq , responseId ) ) ; } // CHECKSTYLE:ON } // Acknowledge the IQ reception // Not anymore. The state machine generates an appropriate response IQ that // gets sent back at the end of this routine. // sendAck(iq); } catch ( JingleException e ) { // Send an error message, if present JingleError error = e . getError ( ) ; if ( error != null ) { responses . add ( createJingleError ( iq , error ) ) ; } // Notify the session end and close everything... triggerSessionClosedOnError ( e ) ; } // // If the response is anything other than a RESULT then send it now. // if ((response != null) && (!response.getType().equals(IQ.Type.result))) { // getConnection().sendStanza(response); // } // Loop through all of the responses and send them. for ( IQ response : responses ) { sendStanza ( response ) ; } }
Process and respond to an incoming packet . This method is called from the stanza listener dispatcher when a new stanza has arrived . The method is responsible for recognizing the stanza type and depending on the current state delivering it to the right event handler and wait for a response . The response will be another Jingle stanza that will be sent to the other end point .