Search in sources :

Example 36 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project Openfire by igniterealtime.

the class SmackServiceNode method getServices.

public static JingleTrackerIQ getServices(final XMPPConnection xmppConnection, final String serviceNode) {
    if (xmppConnection == null || !xmppConnection.isConnected()) {
        return null;
    }
    final JingleTrackerIQ iq = new JingleTrackerIQ();
    iq.setFrom(xmppConnection.getUser());
    iq.setTo(serviceNode);
    PacketCollector collector = xmppConnection.createPacketCollector(new PacketIDFilter(iq.getPacketID()));
    xmppConnection.sendPacket(iq);
    Packet result = collector.nextResult(Math.round(SmackConfiguration.getPacketReplyTimeout() * 1.5));
    collector.cancel();
    return result instanceof JingleTrackerIQ ? (JingleTrackerIQ) result : null;
}
Also used : Packet(org.jivesoftware.smack.packet.Packet) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 37 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project Spark by igniterealtime.

the class TicTacToePlugin method addButtonToToolBar.

/**
 * Add the TTT-Button to every opening Chatroom
 * and create Listeners for it
 */
private void addButtonToToolBar() {
    _chatRoomListener = new ChatRoomListenerAdapter() {

        @Override
        public void chatRoomOpened(final ChatRoom room) {
            if (!(room instanceof ChatRoomImpl)) {
                // Don't do anything if this is not a 1on1-Chat
                return;
            }
            final ChatRoomButton sendGameButton = new ChatRoomButton(buttonimg);
            room.getToolBar().addChatRoomButton(sendGameButton);
            final String opponentJID = ((ChatRoomImpl) room).getJID();
            sendGameButton.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (_currentInvitations.contains(XmppStringUtils.parseBareJid(opponentJID))) {
                        return;
                    }
                    final GameOfferPacket offer = new GameOfferPacket();
                    offer.setTo(opponentJID);
                    offer.setType(IQ.Type.get);
                    _currentInvitations.add(XmppStringUtils.parseBareJid(opponentJID));
                    room.getTranscriptWindow().insertCustomText(TTTRes.getString("ttt.request.sent"), false, false, Color.BLUE);
                    try {
                        SparkManager.getConnection().sendStanza(offer);
                    } catch (SmackException.NotConnectedException e1) {
                        Log.warning("Unable to send offer to " + opponentJID, e1);
                    }
                    SparkManager.getConnection().addAsyncStanzaListener(new StanzaListener() {

                        @Override
                        public void processPacket(Stanza stanza) {
                            GameOfferPacket answer = (GameOfferPacket) stanza;
                            answer.setStartingPlayer(offer.isStartingPlayer());
                            answer.setGameID(offer.getGameID());
                            if (answer.getType() == IQ.Type.result) {
                                // ACCEPT
                                _currentInvitations.remove(XmppStringUtils.parseBareJid(opponentJID));
                                room.getTranscriptWindow().insertCustomText(TTTRes.getString("ttt.request.accept"), false, false, Color.BLUE);
                                createTTTWindow(answer, opponentJID);
                            } else {
                                // DECLINE
                                room.getTranscriptWindow().insertCustomText(TTTRes.getString("ttt.request.decline"), false, false, Color.RED);
                                _currentInvitations.remove(XmppStringUtils.parseBareJid(opponentJID));
                            }
                        }
                    }, new PacketIDFilter(offer.getPacketID()));
                }
            });
        }

        @Override
        public void chatRoomClosed(ChatRoom room) {
            if (room instanceof ChatRoomImpl) {
                ChatRoomImpl cri = (ChatRoomImpl) room;
                _currentInvitations.remove(cri.getParticipantJID());
            }
        }
    };
    SparkManager.getChatManager().addChatRoomListener(_chatRoomListener);
}
Also used : ActionEvent(java.awt.event.ActionEvent) SmackException(org.jivesoftware.smack.SmackException) Stanza(org.jivesoftware.smack.packet.Stanza) StanzaListener(org.jivesoftware.smack.StanzaListener) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl) ChatRoomListenerAdapter(org.jivesoftware.spark.ui.ChatRoomListenerAdapter) ActionListener(java.awt.event.ActionListener) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) GameOfferPacket(tic.tac.toe.packet.GameOfferPacket) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter) ChatRoomButton(org.jivesoftware.spark.ui.ChatRoomButton)

Example 38 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project Spark by igniterealtime.

the class SipAccountPacket method getSipSettings.

/**
 * Returns the SIP Setting for the user.
 *
 * @param connection the XMPPConnection to use.
 * @return the information for about the latest Spark Client.
 * @throws XMPPException thrown if an exception occurs while retrieving Sip Settings.
 */
public static SipAccountPacket getSipSettings(XMPPConnection connection) throws XMPPException, SmackException {
    SipAccountPacket sp = new SipAccountPacket();
    sp.setTo("sipark." + connection.getServiceName());
    sp.setType(IQ.Type.get);
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(sp.getPacketID()));
    connection.sendStanza(sp);
    SipAccountPacket response = (SipAccountPacket) collector.nextResult(SmackConfiguration.getDefaultPacketReplyTimeout());
    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw SmackException.NoResponseException.newWith(connection, collector);
    }
    XMPPException.XMPPErrorException.ifHasErrorThenThrow(response);
    return response;
}
Also used : PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 39 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project Spark by igniterealtime.

the class LogPacket method logEvent.

/**
 * Returns the SIP Setting for the user.
 *
 * @param connection the XMPPConnection to use.
 * @return the information for about the latest Spark Client.
 * @throws XMPPException
 */
public static LogPacket logEvent(XMPPConnection connection, ExtensionElement ext) throws XMPPException, SmackException.NotConnectedException {
    LogPacket lp = new LogPacket();
    lp.addExtension(ext);
    lp.setTo(NAME + "." + connection.getServiceName());
    lp.setType(IQ.Type.set);
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(lp.getPacketID()));
    connection.sendStanza(lp);
    LogPacket response = (LogPacket) collector.nextResult(SmackConfiguration.getDefaultPacketReplyTimeout());
    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        SmackException.NoResponseException.newWith(connection, collector);
    }
    XMPPException.XMPPErrorException.ifHasErrorThenThrow(response);
    return response;
}
Also used : PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 40 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project ecf by eclipse.

the class MultiUserChat method getAffiliatesByAdmin.

/**
 * Returns a collection of <code>Affiliate</code> that have the specified room affiliation
 * sending a request in the admin namespace.
 *
 * @param affiliation the affiliation of the users in the room.
 * @return a collection of <code>Affiliate</code> that have the specified room affiliation.
 * @throws XMPPException if an error occured while performing the request to the server or you
 *         don't have enough privileges to get this information.
 */
private Collection<Affiliate> getAffiliatesByAdmin(String affiliation) throws XMPPException {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.GET);
    // Set the specified affiliation. This may request the list of owners/admins/members/outcasts.
    MUCAdmin.Item item = new MUCAdmin.Item(affiliation, null);
    iq.addItem(item);
    // Wait for a response packet back from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the request to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    MUCAdmin answer = (MUCAdmin) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();
    if (answer == null) {
        throw new XMPPException("No response from server.");
    } else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
    // Get the list of affiliates from the server's answer
    List<Affiliate> affiliates = new ArrayList<Affiliate>();
    for (Iterator<MUCAdmin.Item> it = answer.getItems(); it.hasNext(); ) {
        affiliates.add(new Affiliate(it.next()));
    }
    return affiliates;
}
Also used : PacketFilter(org.jivesoftware.smack.filter.PacketFilter) MUCAdmin(org.jivesoftware.smackx.packet.MUCAdmin) PacketCollector(org.jivesoftware.smack.PacketCollector) ArrayList(java.util.ArrayList) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Aggregations

PacketIDFilter (org.jivesoftware.smack.filter.PacketIDFilter)66 IQ (org.jivesoftware.smack.packet.IQ)38 PacketCollector (org.jivesoftware.smack.PacketCollector)36 XMPPException (org.jivesoftware.smack.XMPPException)34 PacketFilter (org.jivesoftware.smack.filter.PacketFilter)22 Packet (org.jivesoftware.smack.packet.Packet)10 AndFilter (org.jivesoftware.smack.filter.AndFilter)7 PacketTypeFilter (org.jivesoftware.smack.filter.PacketTypeFilter)6 Registration (org.jivesoftware.smack.packet.Registration)6 MUCAdmin (org.jivesoftware.smackx.packet.MUCAdmin)6 MUCOwner (org.jivesoftware.smackx.packet.MUCOwner)6 RosterPacket (org.jivesoftware.smack.packet.RosterPacket)4 ArrayList (java.util.ArrayList)3 XMPPConnection (org.jivesoftware.smack.XMPPConnection)3 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 HashMap (java.util.HashMap)2 StanzaCollector (org.jivesoftware.smack.StanzaCollector)2 StanzaListener (org.jivesoftware.smack.StanzaListener)2 Authentication (org.jivesoftware.smack.packet.Authentication)2