use of org.jivesoftware.smack.packet.Presence in project Smack by igniterealtime.
the class PacketParserUtilsTest method validateSimplePresence.
@Test
public void validateSimplePresence() throws Exception {
// CHECKSTYLE:OFF
String stanza = "<presence from='juliet@example.com/balcony' to='romeo@example.net'/>";
Presence presence = PacketParserUtils.parsePresence(PacketParserUtils.getParserFor(stanza));
assertXMLEqual(stanza, presence.toXML().toString());
// CHECKSTYLE:ON
}
use of org.jivesoftware.smack.packet.Presence in project Smack by igniterealtime.
the class PacketParserUtilsTest method validatePresenceProbe.
@Test
public void validatePresenceProbe() throws Exception {
// CHECKSTYLE:OFF
String stanza = "<presence from='mercutio@example.com' id='xv291f38' to='juliet@example.com' type='unsubscribed'/>";
Presence presence = PacketParserUtils.parsePresence(PacketParserUtils.getParserFor(stanza));
assertXMLEqual(stanza, presence.toXML().toString());
assertEquals(Presence.Type.unsubscribed, presence.getType());
// CHECKSTYLE:ON
}
use of org.jivesoftware.smack.packet.Presence in project Smack by igniterealtime.
the class PacketParserUtilsTest method validatePresenceOptionalElements.
@Test
public void validatePresenceOptionalElements() throws Exception {
// CHECKSTYLE:OFF
String stanza = "<presence xml:lang='en' type='unsubscribed'>" + "<show>dnd</show>" + "<status>Wooing Juliet</status>" + "<priority>1</priority>" + "</presence>";
Presence presence = PacketParserUtils.parsePresence(PacketParserUtils.getParserFor(stanza));
assertXMLEqual(stanza, presence.toXML().toString());
assertEquals(Presence.Type.unsubscribed, presence.getType());
assertEquals("dnd", presence.getMode().name());
assertEquals("en", presence.getLanguage());
assertEquals("Wooing Juliet", presence.getStatus());
assertEquals(1, presence.getPriority());
// CHECKSTYLE:ON
}
use of org.jivesoftware.smack.packet.Presence in project Smack by igniterealtime.
the class AgentSession method setOnline.
/**
* Sets whether the agent is online with the workgroup. If the user tries to go online with
* the workgroup but is not allowed to be an agent, an XMPPError with error code 401 will
* be thrown.
*
* @param online true to set the agent as online with the workgroup.
* @throws XMPPException if an error occurs setting the online status.
* @throws SmackException assertEquals(SmackException.Type.NO_RESPONSE_FROM_SERVER, e.getType());
return;
* @throws InterruptedException
*/
public void setOnline(boolean online) throws XMPPException, SmackException, InterruptedException {
// If the online status hasn't changed, do nothing.
if (this.online == online) {
return;
}
Presence presence;
// If the user is going online...
if (online) {
presence = new Presence(Presence.Type.available);
presence.setTo(workgroupJID);
presence.addExtension(new StandardExtensionElement(AgentStatus.ELEMENT_NAME, AgentStatus.NAMESPACE));
StanzaCollector collector = this.connection.createStanzaCollectorAndSend(new AndFilter(new StanzaTypeFilter(Presence.class), FromMatchesFilter.create(workgroupJID)), presence);
presence = (Presence) collector.nextResultOrThrow();
// We can safely update this iv since we didn't get any error
this.online = online;
} else // Otherwise the user is going offline...
{
// Update this iv now since we don't care at this point of any error
this.online = online;
presence = new Presence(Presence.Type.unavailable);
presence.setTo(workgroupJID);
presence.addExtension(new StandardExtensionElement(AgentStatus.ELEMENT_NAME, AgentStatus.NAMESPACE));
connection.sendStanza(presence);
}
}
use of org.jivesoftware.smack.packet.Presence in project Smack by igniterealtime.
the class AgentSession method setStatus.
/**
* Sets the agent's current status with the workgroup. The presence mode affects how offers
* are routed to the agent. The possible presence modes with their meanings are as follows:<ul>
* <p/>
* <li>Presence.Mode.AVAILABLE -- (Default) the agent is available for more chats
* (equivalent to Presence.Mode.CHAT).
* <li>Presence.Mode.DO_NOT_DISTURB -- the agent is busy and should not be disturbed.
* However, special case, or extreme urgency chats may still be offered to the agent.
* <li>Presence.Mode.AWAY -- the agent is not available and should not
* have a chat routed to them (equivalent to Presence.Mode.EXTENDED_AWAY).</ul>
* <p/>
* The max chats value is the maximum number of chats the agent is willing to have routed to
* them at once. Some servers may be configured to only accept max chat values in a certain
* range; for example, between two and five. In that case, the maxChats value the agent sends
* may be adjusted by the server to a value within that range.
*
* @param presenceMode the presence mode of the agent.
* @param maxChats the maximum number of chats the agent is willing to accept.
* @param status sets the status message of the presence update.
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
* @throws IllegalStateException if the agent is not online with the workgroup.
*/
public void setStatus(Presence.Mode presenceMode, int maxChats, String status) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
if (!online) {
throw new IllegalStateException("Cannot set status when the agent is not online.");
}
if (presenceMode == null) {
presenceMode = Presence.Mode.available;
}
this.presenceMode = presenceMode;
this.maxChats = maxChats;
Presence presence = new Presence(Presence.Type.available);
presence.setMode(presenceMode);
presence.setTo(this.getWorkgroupJID());
if (status != null) {
presence.setStatus(status);
}
// Send information about max chats and current chats as a packet extension.
StandardExtensionElement.Builder builder = StandardExtensionElement.builder(AgentStatus.ELEMENT_NAME, AgentStatus.NAMESPACE);
builder.addElement("max_chats", Integer.toString(maxChats));
presence.addExtension(builder.build());
presence.addExtension(new MetaData(this.metaData));
StanzaCollector collector = this.connection.createStanzaCollectorAndSend(new AndFilter(new StanzaTypeFilter(Presence.class), FromMatchesFilter.create(workgroupJID)), presence);
collector.nextResultOrThrow();
}
Aggregations