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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations