Search in sources :

Example 1 with JingleProvider

use of org.jivesoftware.smackx.jingle.provider.JingleProvider in project Smack by igniterealtime.

the class JingleManagerTest method testInitJingleSessionRequestListeners.

/**
 * Test for the session request detection. Here, we use the same filter we
 * use in the JingleManager...
 */
public void testInitJingleSessionRequestListeners() {
    resetCounter();
    ProviderManager.getInstance().addIQProvider("jingle", "http://jabber.org/protocol/jingle", new JingleProvider());
    PacketFilter initRequestFilter = new PacketFilter() {

        // Return true if we accept this packet
        public boolean accept(Packet pin) {
            if (pin instanceof IQ) {
                System.out.println("packet: " + pin.toXML());
                IQ iq = (IQ) pin;
                if (iq.getType().equals(IQ.Type.set)) {
                    System.out.println("packet");
                    if (iq instanceof Jingle) {
                        Jingle jin = (Jingle) pin;
                        if (jin.getAction().equals(JingleActionEnum.SESSION_INITIATE)) {
                            System.out.println("Session initiation packet accepted... ");
                            return true;
                        }
                    }
                }
            }
            return false;
        }
    };
    // Start a packet listener for session initiation requests
    getConnection(0).addAsyncPacketListener(new PacketListener() {

        public void processStanza(final Packet packet) {
            System.out.println("Packet detected... ");
            incCounter();
        }
    }, initRequestFilter);
    // Create a dummy packet for testing...
    IQfake iqSent = new IQfake(" <jingle xmlns='http://jabber.org/protocol/jingle'" + " initiator=\"user1@thiago\"" + " responder=\"user0@thiago\"" + " action=\"session-initiate\" sid=\"08666555\">" + "</jingle>");
    iqSent.setTo(getFullJID(0));
    iqSent.setFrom(getFullJID(0));
    iqSent.setType(IQ.Type.set);
    System.out.println("Sending packet and waiting... ");
    getConnection(1).sendStanza(iqSent);
    try {
        Thread.sleep(10000);
    } catch (InterruptedException e) {
    }
    System.out.println("Awake... " + valCounter());
    assertTrue(valCounter() > 0);
}
Also used : Jingle(org.jivesoftware.smackx.jingle.packet.Jingle) Packet(org.jivesoftware.smack.packet.Packet) DatagramPacket(java.net.DatagramPacket) PacketFilter(org.jivesoftware.smack.filter.PacketFilter) IQ(org.jivesoftware.smack.packet.IQ) PacketListener(org.jivesoftware.smack.PacketListener) JingleProvider(org.jivesoftware.smackx.jingle.provider.JingleProvider)

Aggregations

DatagramPacket (java.net.DatagramPacket)1 PacketListener (org.jivesoftware.smack.PacketListener)1 PacketFilter (org.jivesoftware.smack.filter.PacketFilter)1 IQ (org.jivesoftware.smack.packet.IQ)1 Packet (org.jivesoftware.smack.packet.Packet)1 Jingle (org.jivesoftware.smackx.jingle.packet.Jingle)1 JingleProvider (org.jivesoftware.smackx.jingle.provider.JingleProvider)1