use of org.jivesoftware.smack.packet.Presence in project Smack by igniterealtime.
the class LowLevelRosterIntegrationTest method testPresenceEventListenersOffline.
@SmackIntegrationTest
public void testPresenceEventListenersOffline(final XMPPTCPConnection conOne, final XMPPTCPConnection conTwo) throws TimeoutException, Exception {
RosterIntegrationTest.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo);
final Roster rosterOne = Roster.getInstanceFor(conOne);
final Roster rosterTwo = Roster.getInstanceFor(conTwo);
// TODO create Roster.createEntry() with boolean flag for subscribe or not.
rosterOne.createEntry(conTwo.getUser().asBareJid(), "Con Two", null);
rosterTwo.createEntry(conOne.getUser().asBareJid(), "Con One", null);
// TODO Change timeout form '5000' to something configurable.
final long timeout = 5000;
RosterIntegrationTest.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout);
final SimpleResultSyncPoint offlineTriggered = new SimpleResultSyncPoint();
rosterOne.addPresenceEventListener(new AbstractPresenceEventListener() {
@Override
public void presenceUnavailable(FullJid jid, Presence presence) {
if (!jid.equals(conTwo.getUser())) {
return;
}
offlineTriggered.signal();
}
});
// Disconnect conTwo, this should cause an 'unavilable' presence to be send from conTwo to
// conOne.
conTwo.disconnect();
Boolean result = offlineTriggered.waitForResult(timeout);
if (!result) {
throw new Exception("presenceUnavailable() was not called");
}
}
use of org.jivesoftware.smack.packet.Presence in project Smack by igniterealtime.
the class RosterIntegrationTest method ensureSubscribedTo.
private static void ensureSubscribedTo(final XMPPConnection conOne, final XMPPConnection conTwo, long timeout) throws TimeoutException, Exception {
Roster rosterOne = Roster.getInstanceFor(conOne);
Roster rosterTwo = Roster.getInstanceFor(conTwo);
if (rosterOne.isSubscribedToMyPresence(conTwo.getUser())) {
return;
}
final SubscribeListener subscribeListener = new SubscribeListener() {
@Override
public SubscribeAnswer processSubscribe(Jid from, Presence subscribeRequest) {
if (from.equals(conTwo.getUser().asBareJid())) {
return SubscribeAnswer.Approve;
}
return SubscribeAnswer.Deny;
}
};
rosterOne.addSubscribeListener(subscribeListener);
final SimpleResultSyncPoint syncPoint = new SimpleResultSyncPoint();
rosterTwo.addPresenceEventListener(new AbstractPresenceEventListener() {
@Override
public void presenceSubscribed(BareJid address, Presence subscribedPresence) {
if (!address.equals(conOne.getUser().asBareJid())) {
return;
}
syncPoint.signal();
}
});
rosterTwo.sendSubscriptionRequest(conOne.getUser().asBareJid());
try {
syncPoint.waitForResult(timeout);
} finally {
rosterOne.removeSubscribeListener(subscribeListener);
}
}
use of org.jivesoftware.smack.packet.Presence in project Openfire by igniterealtime.
the class XMPPSession method sendChatState.
/**
* @see net.sf.kraken.session.TransportSession#sendChatState(org.xmpp.packet.JID, net.sf.kraken.type.ChatStateType)
*/
@Override
public void sendChatState(JID jid, ChatStateType chatState) {
final Presence presence = conn.getRoster().getPresence(jid.toString());
if (presence == null || presence.getType().equals(Presence.Type.unavailable)) {
// don't send chat state to contacts that are offline.
return;
}
Chat chat = conn.getChatManager().createChat(getTransport().convertJIDToID(jid), listener);
try {
ChatState state = ChatState.active;
switch(chatState) {
case active:
state = ChatState.active;
break;
case composing:
state = ChatState.composing;
break;
case paused:
state = ChatState.paused;
break;
case inactive:
state = ChatState.inactive;
break;
case gone:
state = ChatState.gone;
break;
}
Message message = new Message();
message.addExtension(new ChatStateExtension(state));
chat.sendMessage(message);
} catch (XMPPException e) {
// Ignore
}
}
use of org.jivesoftware.smack.packet.Presence in project Openfire by igniterealtime.
the class XMPPSession method updateStatus.
/**
* @see net.sf.kraken.session.TransportSession#updateStatus(net.sf.kraken.type.PresenceType, String)
*/
@Override
public void updateStatus(PresenceType presenceType, String verboseStatus) {
setPresenceAndStatus(presenceType, verboseStatus);
final org.jivesoftware.smack.packet.Presence presence = constructCurrentLegacyPresencePacket();
try {
conn.sendPacket(presence);
} catch (IllegalStateException e) {
Log.debug("XMPP: Not connected while trying to change status.");
}
}
use of org.jivesoftware.smack.packet.Presence in project Openfire by igniterealtime.
the class XMPPSession method acceptAddContact.
/**
* @see net.sf.kraken.session.TransportSession#acceptAddContact(JID)
*/
@Override
public void acceptAddContact(JID jid) {
final String userID = getTransport().convertJIDToID(jid);
Log.debug("XMPP: accept-add contact: " + userID);
final Presence accept = new Presence(Type.subscribed);
accept.setTo(userID);
conn.sendPacket(accept);
}
Aggregations