本文整理匯總了Java中org.jivesoftware.smack.packet.Presence.Mode方法的典型用法代碼示例。如果您正苦於以下問題:Java Presence.Mode方法的具體用法?Java Presence.Mode怎麽用?Java Presence.Mode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jivesoftware.smack.packet.Presence
的用法示例。
在下文中一共展示了Presence.Mode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: perform
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
Presence.Type typeVal = Presence.Type.valueOf(sampler.getPropertyAsString(TYPE, Presence.Type.available.toString()));
Presence.Mode modeVal = Presence.Mode.valueOf(sampler.getPropertyAsString(MODE, Presence.Mode.available.toString()));
Presence presence = new Presence(typeVal);
presence.setMode(modeVal);
String to = sampler.getPropertyAsString(RECIPIENT);
if (!to.isEmpty()) {
presence.setTo(to);
}
String text = sampler.getPropertyAsString(STATUS_TEXT);
if (!text.isEmpty()) {
presence.setStatus(text);
}
sampler.getXMPPConnection().sendPacket(presence);
res.setSamplerData(presence.toXML().toString());
return res;
}
示例2: setStatus
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* 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>
*
* @param presenceMode the presence mode of the agent.
* @param status sets the status message of the presence update.
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws IllegalStateException if the agent is not online with the workgroup.
*/
public void setStatus(Presence.Mode presenceMode, String status) throws NoResponseException, XMPPErrorException, NotConnectedException {
if (!online) {
throw new IllegalStateException("Cannot set status when the agent is not online.");
}
if (presenceMode == null) {
presenceMode = Presence.Mode.available;
}
this.presenceMode = presenceMode;
Presence presence = new Presence(Presence.Type.available);
presence.setMode(presenceMode);
presence.setTo(this.getWorkgroupJID());
if (status != null) {
presence.setStatus(status);
}
presence.addExtension(new MetaData(this.metaData));
PacketCollector collector = this.connection.createPacketCollectorAndSend(new AndFilter(new StanzaTypeFilter(Presence.class),
FromMatchesFilter.create(workgroupJID)), presence);
collector.nextResultOrThrow();
}
示例3: changeAvailabilityStatus
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* Changes the occupant's availability status within the room. The presence type
* will remain available but with a new status that describes the presence update and
* a new presence mode (e.g. Extended away).
*
* @param status a text message describing the presence update.
* @param mode the mode type for the presence update.
* @throws NotConnectedException
*/
public void changeAvailabilityStatus(String status, Presence.Mode mode) throws NotConnectedException {
StringUtils.requireNotNullOrEmpty(nickname, "Nickname must not be null or blank.");
// Check that we already have joined the room before attempting to change the
// availability status.
if (!joined) {
throw new IllegalStateException(
"Must be logged into the room to change the " + "availability status.");
}
// We change the availability status by sending a presence packet to the room with the
// new presence status and mode
Presence joinPresence = new Presence(Presence.Type.available);
joinPresence.setStatus(status);
joinPresence.setMode(mode);
joinPresence.setTo(room + "/" + nickname);
// Send join packet.
connection.sendStanza(joinPresence);
}
示例4: changeAvailabilityStatus
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* Changes the occupant's availability status within the room. The presence type
* will remain available but with a new status that describes the presence update and
* a new presence mode (e.g. Extended away).
*
* @param status a text message describing the presence update.
* @param mode the mode type for the presence update.
*/
public void changeAvailabilityStatus(String status, Presence.Mode mode) {
if (nickname == null || nickname.equals("")) {
throw new IllegalArgumentException("Nickname must not be null or blank.");
}
// Check that we already have joined the room before attempting to change the
// availability status.
if (!joined) {
throw new IllegalStateException(
"Must be logged into the room to change the " + "availability status.");
}
// We change the availability status by sending a presence packet to the room with the
// new presence status and mode
Presence joinPresence = new Presence(Presence.Type.available);
joinPresence.setStatus(status);
joinPresence.setMode(mode);
joinPresence.setTo(room + "/" + nickname);
// Invoke presence interceptors so that extra information can be dynamically added
for (PacketInterceptor packetInterceptor : presenceInterceptors) {
packetInterceptor.interceptPacket(joinPresence);
}
// Send join packet.
connection.sendPacket(joinPresence);
}
示例5: constructCurrentLegacyPresencePacket
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* Returns a (legacy/Smack-based) Presence stanza that represents the
* current presence of this session. The Presence includes relevant Mode,
* Status and VCardUpdate information.
*
* This method uses the fields {@link TransportSession#presence} and
* {@link TransportSession#verboseStatus} to generate the result.
*
* @return A Presence packet representing the current presence state of this
* session.
*/
public Presence constructCurrentLegacyPresencePacket() {
final org.jivesoftware.smack.packet.Presence presence = new org.jivesoftware.smack.packet.Presence(
org.jivesoftware.smack.packet.Presence.Type.available);
final Presence.Mode pMode = ((XMPPTransport) getTransport())
.convertGatewayStatusToXMPP(this.presence);
if (pMode != null) {
presence.setMode(pMode);
}
if (verboseStatus != null && verboseStatus.trim().length() > 0) {
presence.setStatus(verboseStatus);
}
final Avatar avatar = getAvatar();
if (avatar != null) {
final VCardUpdateExtension ext = new VCardUpdateExtension();
ext.setPhotoHash(avatar.getLegacyIdentifier());
presence.addExtension(ext);
}
return presence;
}
示例6: getAvailability
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public Presence.Mode getAvailability() {
Presence.Mode mode = Presence.Mode.away;
if (isAway()) {
mode = Presence.Mode.xa;
}
else if (isLooking()) {
mode = Presence.Mode.chat;
}
return mode;
}
示例7: setPresence
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public void setPresence() throws SmackException.NotConnectedException {
Presence.Mode presMode;
switch(mAccount.getPresenceMode()) {
case XmppAccount.PRESENCE_MODE_CHAT:
presMode = Presence.Mode.chat;
break;
case XmppAccount.PRESENCE_MODE_AVAILABLE:
default:
presMode = Presence.Mode.available;
break;
case XmppAccount.PRESENCE_MODE_AWAY:
presMode = Presence.Mode.away;
break;
case XmppAccount.PRESENCE_MODE_XA:
presMode = Presence.Mode.xa;
break;
case XmppAccount.PRESENCE_MODE_DND:
presMode = Presence.Mode.dnd;
break;
}
mConnection.sendStanza(new Presence(Presence.Type.available, mAccount.getPersonalMessage(),
mAccount.getPriority(), presMode));
}
示例8: convertGatewayStatusToXMPP
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* Converts a Gateway status to an XMPP/Smack status.
*
* Returns null if the status is "unavailable".
*
* @param type Gateway status.
* @return Smack presence mode.
*/
public Presence.Mode convertGatewayStatusToXMPP(PresenceType type) {
if (type == PresenceType.available) {
return Presence.Mode.available;
}
else if (type == PresenceType.away) {
return Presence.Mode.away;
}
else if (type == PresenceType.chat) {
return Presence.Mode.chat;
}
else if (type == PresenceType.dnd) {
return Presence.Mode.dnd;
}
else if (type == PresenceType.unavailable) {
return null;
}
else if (type == PresenceType.xa) {
return Presence.Mode.xa;
}
else if (type == PresenceType.unknown) {
return Presence.Mode.available;
}
else {
return Presence.Mode.available;
}
}
示例9: getChatMode
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* Returns the current ChatMode of this friend (e.g. away, busy, available).
*
* @see ChatMode
* @return ChatMode of this friend
*/
public ChatMode getChatMode() {
final Presence.Mode mode = con.getRoster().getPresence(getUserId())
.getMode();
for (final ChatMode c : ChatMode.values()) {
if (c.mode == mode) {
return c;
}
}
return null;
}
示例10: getChatMode
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* Returns the current ChatMode of this friend (e.g. away, busy, available).
*
* @see ChatMode
* @return ChatMode of this friend
*/
public ChatMode getChatMode() {
final Presence.Mode mode = con.getRoster().getPresence(getUserId())
.getMode();
for (final ChatMode c : ChatMode.values()) {
if (mode != null && c.mode == mode) {//some LOL clients do not set the mode, so we have to check if the mode is null
return c;
}
}
return ChatMode.AVAILABLE;//changed from null
}
示例11: handlePresence
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
private void handlePresence(Presence p) {
Intent i = new Intent(ACTION_PRESENCE);
Presence.Type type = p.getType();
i.putExtra(EXTRA_TYPE, type != null ? type.name() : Presence.Type.available.name());
i.putExtra(EXTRA_PACKET_ID, p.getPacketID());
String from = p.getFrom();
String network = StringUtils.parseServer(from);
// our network - convert to userId
if (network.equalsIgnoreCase(getServer().getNetwork())) {
StringBuilder b = new StringBuilder();
b.append(StringUtils.parseName(from));
b.append(StringUtils.parseResource(from));
i.putExtra(EXTRA_FROM_USERID, b.toString());
}
i.putExtra(EXTRA_FROM, from);
i.putExtra(EXTRA_TO, p.getTo());
i.putExtra(EXTRA_STATUS, p.getStatus());
Presence.Mode mode = p.getMode();
i.putExtra(EXTRA_SHOW, mode != null ? mode.name() : Presence.Mode.available.name());
i.putExtra(EXTRA_PRIORITY, p.getPriority());
// getExtension doesn't work here
Iterator<PacketExtension> iter = p.getExtensions().iterator();
while (iter.hasNext()) {
PacketExtension _ext = iter.next();
if (_ext instanceof DelayInformation) {
DelayInformation delay = (DelayInformation) _ext;
i.putExtra(EXTRA_STAMP, delay.getStamp().getTime());
break;
}
}
// non-standard stanza group extension
PacketExtension ext = p.getExtension(StanzaGroupExtension.ELEMENT_NAME, StanzaGroupExtension.NAMESPACE);
if (ext != null && ext instanceof StanzaGroupExtension) {
StanzaGroupExtension g = (StanzaGroupExtension) ext;
i.putExtra(EXTRA_GROUP_ID, g.getId());
i.putExtra(EXTRA_GROUP_COUNT, g.getCount());
}
Log.v(MessageCenterService.TAG, "broadcasting presence: " + i);
sendBroadcast(i);
}
示例12: getPresenceMode
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public Presence.Mode getPresenceMode() {
return presenceMode;
}
示例13: sendPresence
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* change jabber status. Example: sendPresencePacket(Presence.Type.AVAILABLE, "at meeting...", 1, Presence.Mode.AWAY);
*
* @param type
* @param status
* @param priority
* @param mode
*/
public void sendPresence(final Presence.Type type, String status, final int priority, final Presence.Mode mode) {
// get rid of "&" because they break xml packages!
if (status != null) {
status = status.replaceAll("&", "&");
}
if (connection == null || !connection.isConnected()) {
return;
}
if (collaborationDisabled) {
return;
}
setStatus(mode);
final Presence presence = new Presence(type);
if (status == null) {
if (mode == Presence.Mode.available) {
status = InstantMessagingConstants.PRESENCE_MODE_AVAILABLE;
} else if (mode == Presence.Mode.away) {
status = InstantMessagingConstants.PRESENCE_MODE_AWAY;
} else if (mode == Presence.Mode.chat) {
status = InstantMessagingConstants.PRESENCE_MODE_CHAT;
} else if (mode == Presence.Mode.dnd) {
status = InstantMessagingConstants.PRESENCE_MODE_DND;
} else if (mode == Presence.Mode.xa) {
status = InstantMessagingConstants.PRESENCE_MODE_XAWAY;
}
presence.setStatus(status);
} else {
presence.setStatus(status);
}
setStatusMsg(presence.getStatus());
// setting prio when type == unavailable causes error on IM server
if (presence.getType() == Presence.Type.available) {
presence.setPriority(priority);
}
if (mode != null) {
presence.setMode(mode);
}
try {
connection.sendPacket(presence);
} catch (final RuntimeException ex) {
log.warn("Error while trying to send Instant Messaging packet for user: " + userInfo.getUsername() + " .Errormessage: ", ex);
}
}
示例14: sendPresence
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* Sends our initial presence.
*/
private void sendPresence(Presence.Mode mode) {
sendPacket(createPresence(mode));
}
示例15: onPresence
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
@Override
protected void onPresence(String jid, Presence.Type type, boolean removed, Presence.Mode mode, String fingerprint) {
Context context = getContext();
if (context == null)
return;
if (Log.isDebug()) {
Log.d(TAG, "group member presence from " + jid + " (type=" + type + ", fingerprint=" + fingerprint + ")");
}
// handle null type - meaning no subscription (warn user)
if (type == null) {
// some users are missing subscription - disable sending
// FIXME a toast isn't the right way to warn about this (discussion going on in #179)
Toast.makeText(context,
"You can't chat with some of the group members because you haven't been authorized yet. Open a private chat with unknown users first.",
Toast.LENGTH_LONG).show();
mComposer.setSendEnabled(false);
}
else if (type == Presence.Type.available || type == Presence.Type.unavailable) {
// no encryption - pointless to verify keys
if (!Preferences.getEncryptionEnabled(context))
return;
String bareJid = XmppStringUtils.parseBareJid(jid);
Contact contact = Contact.findByUserId(context, bareJid);
if (contact != null) {
// if this is null, we are accepting the key for the first time
PGPPublicKeyRing trustedPublicKey = contact.getTrustedPublicKeyRing();
// request the key if we don't have a trusted one and of course if the user has a key
boolean unknownKey = (trustedPublicKey == null && contact.getFingerprint() != null);
boolean changedKey = false;
// check if fingerprint changed
if (trustedPublicKey != null && fingerprint != null) {
String oldFingerprint = PGP.getFingerprint(PGP.getMasterKey(trustedPublicKey));
if (!fingerprint.equalsIgnoreCase(oldFingerprint)) {
// fingerprint has changed since last time
changedKey = true;
}
}
if (changedKey || unknownKey) {
showKeyWarning();
}
}
}
}