Package org.jivesoftware.smack

Examples of org.jivesoftware.smack.PacketListener


    public void startConference(String roomName, String server,
            List<String> users, String reason) {
        // Create a MultiUserChat using a Connection for a room
        MultiUserChat muc = new MultiUserChat(connection, roomName + "@"
                + server);
        PacketListener myListener = new PacketListener() {

            @Override
            public void processPacket(Packet packet) {
                //System.out.println("PacketData:" + packet.toXML());
                if (packet.getClass().toString().equalsIgnoreCase(
                        "class org.jivesoftware.smack.packet.Message")) {
                    Message m = (Message) packet;

                    if (m.getBody() != null) {
                       // System.out.println("Body is " + m.getBody());
                        DelayInformation inf = null;
                        try {
                            inf = (DelayInformation) packet.getExtension(
                                    "x", "jabber:x:delay");


                            String[] username = m.getFrom().split("/");

                            String t[] = username[0].split("@");
                            if (t.length >= 2) {
                                System.out.println("Room:" + t[0] + ",msg:" + m.getBody() + ",User:" + username[1]);
                                sendToConfPage(t[0], m.getBody(), username[1], t[1]);
                            }

                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        };
        muc.addMessageListener(myListener);

        PacketListener peopleListener = new PacketListener() {

            @Override
            public void processPacket(Packet packet) {
                //System.out.println("People PacketData:" + packet.toXML());
                if (packet.getClass().toString().equalsIgnoreCase(
View Full Code Here


    public void joinConference(String room) {
        MultiUserChat muc = new MultiUserChat(connection, room);
        try {
            muc.join(chatRoom);
            myChatRooms.add(muc);
            PacketListener myListener = new PacketListener() {

                @Override
                public void processPacket(Packet packet) {
                    //System.out.println("\nIN:" + chatRoom);
                    //System.out.println("PacketClass:" + packet.getClass());
                    //System.out.println("PacketProperties:"
                    //+ packet.getPropertyNames());
                    //System.out.println("PacketData:" + packet.toXML());
                    if (packet.getClass().toString().equalsIgnoreCase(
                            "class org.jivesoftware.smack.packet.Message")) {
                        Message m = (Message) packet;

                        if (m.getBody() != null) {
                            System.out.println("Body is " + m.getBody());
                            DelayInformation inf = null;
                            try {
                                inf = (DelayInformation) packet.getExtension(
                                        "x", "jabber:x:delay");

                                // get offline message timestamp

                                String[] username = m.getFrom().split("/");

                                String t[] = username[0].split("@");
                                System.out.println("Room:" + t[0] + ",msg:" + m.getBody() + ",User:" + username[1]);
                                sendToConfPage(t[0], m.getBody(), username[1], t[1]);

                            } catch (Exception e) {
                                // log.error(e);
                                e.printStackTrace();
                            }
                        }

                    }
                }
            };
            muc.addMessageListener(myListener);

            PacketListener peopleListener = new PacketListener() {

                @Override
                public void processPacket(Packet packet) {
                    //System.out.println("People PacketData:" + packet.toXML());
                    if (packet.getClass().toString().equalsIgnoreCase(
View Full Code Here

  }

  private void initListeners() {
    listeners = new ArrayList();

    connection.addPacketListener(new PacketListener() {
      public void processPacket(Packet packet) {
        fireNewRequest((StreamInitiation) packet);
      }
    }, new AndFilter(new PacketTypeFilter(StreamInitiation.class),
        new IQTypeFilter(IQ.Type.SET)));
View Full Code Here

        addInformationPanel();

        // Create a thread that will listen for all incoming packets and write them to
        // the GUI. This is what we call "interpreted" packet data, since it's the packet
        // data as Smack sees it and not as it's coming in as raw XML.
        packetReaderListener = new PacketListener() {
            SimpleDateFormat dateFormatter = new SimpleDateFormat("hh:mm:ss aaa");

            public void processPacket(final Packet packet) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        addReadPacketToTable(dateFormatter, packet);
                    }
                });

            }
        };

        // Create a thread that will listen for all outgoing packets and write them to
        // the GUI.
        packetWriterListener = new PacketListener() {
            SimpleDateFormat dateFormatter = new SimpleDateFormat("hh:mm:ss aaa");

            public void processPacket(final Packet packet) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
View Full Code Here

        writer = debugWriter;

        // Create a thread that will listen for all incoming packets and write them to
        // the GUI. This is what we call "interpreted" packet data, since it's the packet
        // data as Smack sees it and not as it's coming in as raw XML.
        listener = new PacketListener() {
            public void processPacket(Packet packet) {
                if (printInterpreted) {
                    System.out.println(
                            dateFormatter.format(new Date()) + " RCV PKT (" +
                            connection.hashCode() +
View Full Code Here

        addInformationPanel();

        // Create a thread that will listen for all incoming packets and write them to
        // the GUI. This is what we call "interpreted" packet data, since it's the packet
        // data as Smack sees it and not as it's coming in as raw XML.
        packetReaderListener = new PacketListener() {
            SimpleDateFormat dateFormatter = new SimpleDateFormat("hh:mm:ss aaa");

            public void processPacket(final Packet packet) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        addReadPacketToTable(dateFormatter, packet);
                    }
                });

            }
        };

        // Create a thread that will listen for all outgoing packets and write them to
        // the GUI.
        packetWriterListener = new PacketListener() {
            SimpleDateFormat dateFormatter = new SimpleDateFormat("hh:mm:ss aaa");

            public void processPacket(final Packet packet) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
View Full Code Here

  }

  private void initListeners() {
    listeners = new ArrayList();

    connection.addPacketListener(new PacketListener() {
      public void processPacket(Packet packet) {
        fireNewRequest((StreamInitiation) packet);
      }
    }, new AndFilter(new PacketTypeFilter(StreamInitiation.class),
        new IQTypeFilter(IQ.Type.SET)));
View Full Code Here

        writer = debugWriter;

        // Create a thread that will listen for all incoming packets and write them to
        // the GUI. This is what we call "interpreted" packet data, since it's the packet
        // data as Smack sees it and not as it's coming in as raw XML.
        listener = new PacketListener() {
            public void processPacket(Packet packet) {
                if (printInterpreted) {
                    System.out.println(
                            dateFormatter.format(new Date()) + " RCV PKT (" +
                            connection.hashCode() +
View Full Code Here


        // TODO: ToContainsFilter which was in Smack 4.0.0!?
        PacketFilter filter = new MessageTypeFilter(Message.Type.chat);

    PacketListener listener = new PrivateChatListener();
    this.connection.addPacketListener(listener, filter);
  }
View Full Code Here

        LoggingFilterWriter debugWriter = new LoggingFilterWriter(this.writer,
                LOGGER, MIN_LOG_LEVEL);
        this.writer = debugWriter;

        this.listener = new PacketListener() {
            public void processPacket(Packet packet) {
                if (LOGGER.isLoggable(Level.FINEST)) {
                    LOGGER.finest("RCV PKT: " + packet.toXML());
                }
            }
View Full Code Here

TOP

Related Classes of org.jivesoftware.smack.PacketListener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.