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