Java Code Examples for org.jivesoftware.smack.packet.Presence#addExtension()

The following examples show how to use org.jivesoftware.smack.packet.Presence#addExtension() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AgentSession.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * 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>
 *
 * <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>
 *
 * @param presenceMode the presence mode of the agent.
 * @param status       sets the status message of the presence update.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws IllegalStateException if the agent is not online with the workgroup.
 */
public void setStatus(Presence.Mode presenceMode, 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;

    PresenceBuilder presenceBuilder = connection.getStanzaFactory().buildPresenceStanza()
            .ofType(Presence.Type.available)
            .setMode(presenceMode)
            .to(getWorkgroupJID());

    if (status != null) {
        presenceBuilder.setStatus(status);
    }

    Presence presence = presenceBuilder.build();
    presence.addExtension(new MetaData(this.metaData));

    StanzaCollector collector = this.connection.createStanzaCollectorAndSend(new AndFilter(new StanzaTypeFilter(Presence.class),
            FromMatchesFilter.create(workgroupJID)), presence);

    collector.nextResultOrThrow();
}
 
Example 2
Source File: XMPPConnectionService.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
private void sendAvailablePresenceWithClientIdentifier() {
  String version = EntityCapsManager.getInstanceFor(connection).getCapsVersion();
  CapsExtension caps = new CapsExtension(XMPP_CLIENT_IDENTIFIER, version, CAPS_HASH_ALGORITHM);

  Presence presence = new Presence(Presence.Type.available);
  presence.addExtension(caps);
  connection.sendPacket(presence);
}
 
Example 3
Source File: AgentSession.java    From Smack with Apache License 2.0 4 votes vote down vote up
/**
 * 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 if the calling thread was interrupted.
 */
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 = connection.getStanzaFactory().buildPresenceStanza()
                .ofType(Presence.Type.available)
                .to(workgroupJID)
                .build();

        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 = collector.nextResultOrThrow();

        // We can safely update this iv since we didn't get any error
        this.online = online;
    }
    // Otherwise the user is going offline...
    else {
        // Update this iv now since we don't care at this point of any error
        this.online = online;

        presence = connection.getStanzaFactory().buildPresenceStanza()
                .ofType(Presence.Type.unavailable)
                .to(workgroupJID)
                .build();
        presence.addExtension(new StandardExtensionElement(AgentStatus.ELEMENT_NAME,
                AgentStatus.NAMESPACE));
        connection.sendStanza(presence);
    }
}
 
Example 4
Source File: IdleElement.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * Add an Idle element with current date to the presence.
 * @param presence presence
 */
public static void addToPresence(Presence presence) {
    presence.addExtension(new IdleElement());
}