Search in sources :

Example 1 with PacketIDFilter

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

the class SmackServiceNode method getChannel.

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

Example 2 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project intellij-plugins by JetBrains.

the class JabberFacadeImpl method setVCardInfo.

public void setVCardInfo(String nickName, String firstName, String lastName) throws XMPPException {
    assert isConnectedAndAuthenticated() : "Not connected or authenticated";
    VCard vCard = new VCard();
    vCard.setFirstName(firstName);
    vCard.setLastName(lastName);
    vCard.setNickName(nickName);
    PacketCollector collector = myConnection.createPacketCollector(new PacketIDFilter(vCard.getPacketID()));
    vCard.save(myConnection);
    IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from the server.");
    } else // If the server replied with an error, throw an exception.
    if (response.getType() == IQ.Type.ERROR) {
        throw new XMPPException(response.getError());
    }
}
Also used : IQ(org.jivesoftware.smack.packet.IQ) VCard(org.jivesoftware.smackx.packet.VCard) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 3 with PacketIDFilter

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

the class SipAccountPacket method setSipRegisterStatus.

/**
 * Sends the current SIP registering status.
 *
 * @param connection the XMPPConnection to use.
 * @param register   the current registration status.
 * @throws XMPPException thrown if an exception occurs.
 */
public static void setSipRegisterStatus(XMPPConnection connection, SipRegisterStatus register) throws XMPPException, SmackException {
    if (!connection.isConnected()) {
        return;
    }
    SipAccountPacket sp = new SipAccountPacket(SipAccountPacket.Type.status);
    sp.setTo("sipark." + connection.getServiceName());
    sp.setType(IQ.Type.set);
    sp.setContent(register.name());
    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);
}
Also used : PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 4 with PacketIDFilter

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

the class ChatRoomOpeningListener method chatRoomOpened.

@Override
public void chatRoomOpened(final ChatRoom room) {
    if (// Check for 1on1 Chat
    !(room instanceof ChatRoomImpl)) {
        return;
    }
    final ChatRoomButton sendGameButton = new ChatRoomButton("BS");
    room.getToolBar().addChatRoomButton(sendGameButton);
    final String opponentJID = ((ChatRoomImpl) room).getJID();
    sendGameButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final GameOfferPacket offer = new GameOfferPacket();
            offer.setTo(opponentJID);
            offer.setType(IQ.Type.get);
            room.getTranscriptWindow().insertCustomText(BsRes.getString("request"), 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());
                    String name = XmppStringUtils.parseLocalpart(opponentJID);
                    if (answer.getType() == IQ.Type.result) {
                        // ACCEPT
                        room.getTranscriptWindow().insertCustomText(BsRes.getString("accepted", name), false, false, Color.BLUE);
                        createWindow(answer, opponentJID);
                    } else {
                        // DECLINE
                        room.getTranscriptWindow().insertCustomText(BsRes.getString("declined", name), false, false, Color.RED);
                    }
                }
            }, new PacketIDFilter(offer.getPacketID()));
        }
    });
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) GameOfferPacket(battleship.packets.GameOfferPacket) Stanza(org.jivesoftware.smack.packet.Stanza) StanzaListener(org.jivesoftware.smack.StanzaListener) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter) ChatRoomButton(org.jivesoftware.spark.ui.ChatRoomButton)

Example 5 with PacketIDFilter

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

the class MultiUserChat method changeAffiliationByAdmin.

private void changeAffiliationByAdmin(Collection<String> jids, String affiliation) throws XMPPException {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.SET);
    for (String jid : jids) {
        // Set the new affiliation.
        MUCAdmin.Item item = new MUCAdmin.Item(affiliation, null);
        item.setJid(jid);
        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 change request to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) 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());
    }
}
Also used : PacketFilter(org.jivesoftware.smack.filter.PacketFilter) MUCAdmin(org.jivesoftware.smackx.packet.MUCAdmin) PacketCollector(org.jivesoftware.smack.PacketCollector) IQ(org.jivesoftware.smack.packet.IQ) 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