本文整理匯總了Java中org.jivesoftware.smack.packet.Presence.setMode方法的典型用法代碼示例。如果您正苦於以下問題:Java Presence.setMode方法的具體用法?Java Presence.setMode怎麽用?Java Presence.setMode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jivesoftware.smack.packet.Presence
的用法示例。
在下文中一共展示了Presence.setMode方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: sendStatus
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
protected void sendStatus(JabberPlayer player, String recipient, JabberRoom room) {
final SimpleStatus s = (SimpleStatus) player.getStatus();
final Presence p = new Presence(Presence.Type.available);
p.setStatus(""); //$NON-NLS-1$
p.setMode(Presence.Mode.chat);
p.setProperty(SimpleStatus.LOOKING, s.isLooking());
p.setProperty(SimpleStatus.AWAY, s.isAway());
p.setProperty(SimpleStatus.IP, s.getIp());
p.setProperty(SimpleStatus.CLIENT, s.getClient());
p.setProperty(SimpleStatus.MODULE_VERSION, s.getModuleVersion());
p.setProperty(SimpleStatus.CRC, s.getCrc());
p.setProperty(REAL_NAME, player.getName()); //$NON-NLS-1$
if (room != null) {
p.setProperty(ROOM_CONFIG, room.encodeConfig());
p.setProperty(ROOM_JID, room.getJID());
p.setProperty(ROOM_NAME, room.getName());
}
p.setTo(recipient == null ? monitorRoom.getRoom() : recipient);
conn.sendPacket(p);
}
示例3: 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();
}
示例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.
* @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);
}
示例5: 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);
}
示例6: setStatusFromConfig
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
@Override
public void setStatusFromConfig() {// 設置自己的當前狀態,供外部服務調用
boolean messageCarbons = PreferenceUtils.getPrefBoolean(mService,
PreferenceConstants.MESSAGE_CARBONS, true);
String statusMode = PreferenceUtils.getPrefString(mService,
PreferenceConstants.STATUS_MODE, PreferenceConstants.AVAILABLE);
String statusMessage = PreferenceUtils.getPrefString(mService,
PreferenceConstants.STATUS_MESSAGE,
mService.getString(R.string.status_online));
int priority = PreferenceUtils.getPrefInt(mService,
PreferenceConstants.PRIORITY, 0);
if (messageCarbons)
CarbonManager.getInstanceFor(mXMPPConnection).sendCarbonsEnabled(
true);
Presence presence = new Presence(Presence.Type.available);
Mode mode = Mode.valueOf(statusMode);
presence.setMode(mode);
presence.setStatus(statusMessage);
presence.setPriority(priority);
mXMPPConnection.sendPacket(presence);
}
示例7: login
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public void login(String user, String pass, StatusItem status, String username)
throws XMPPException, SmackException, IOException, InterruptedException {
Log.i(TAG, "inside XMPP getlogin Method");
long l = System.currentTimeMillis();
XMPPTCPConnection connect = connect();
if (connect.isAuthenticated()) {
Log.i(TAG, "User already logged in");
return;
}
Log.i(TAG, "Time taken to connect: " + (System.currentTimeMillis() - l));
l = System.currentTimeMillis();
connect.login(user, pass);
Log.i(TAG, "Time taken to login: " + (System.currentTimeMillis() - l));
Log.i(TAG, "login step passed");
Presence p = new Presence(Presence.Type.available);
p.setMode(Presence.Mode.available);
p.setPriority(24);
p.setFrom(connect.getUser());
if (status != null) {
p.setStatus(status.toJSON());
} else {
p.setStatus(new StatusItem().toJSON());
}
// p.setTo("");
VCard ownVCard = new VCard();
ownVCard.load(connect);
ownVCard.setNickName(username);
ownVCard.save(connect);
PingManager pingManager = PingManager.getInstanceFor(connect);
pingManager.setPingInterval(150000);
connect.sendPacket(p);
}
示例8: createPresence
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
private Presence createPresence(Presence.Mode mode) {
String status = Preferences.getStatusMessage();
Presence p = new Presence(Presence.Type.available);
if (!TextUtils.isEmpty(status))
p.setStatus(status);
if (mode != null)
p.setMode(mode);
// TODO find a place for this
p.addExtension(new CapsExtension("http://www.kontalk.org/", "none", "sha-1"));
return p;
}
示例9: 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);
}
示例10: 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);
}
}
示例11: handlePresence
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
@CommandHandler(name = ACTION_PRESENCE)
private boolean handlePresence(Intent intent, boolean canConnect) {
if (canConnect && isConnected()) {
final String id = intent.getStringExtra(EXTRA_PACKET_ID);
String type = intent.getStringExtra(EXTRA_TYPE);
final String to = intent.getStringExtra(EXTRA_TO);
if ("probe".equals(type)) {
// probing is actually looking into the roster
final Roster roster = getRoster();
if (to == null) {
for (RosterEntry entry : roster.getEntries()) {
broadcastPresence(roster, entry, id);
}
// broadcast our own presence
broadcastMyPresence(id);
}
else {
queueTask(new Runnable() {
@Override
public void run() {
try {
broadcastPresence(roster, JidCreate.bareFrom(to), id);
}
catch (XmppStringprepException e) {
Log.w(TAG, "error parsing JID: " + e.getCausingString(), e);
// report it because it's a big deal
ReportingManager.logException(e);
throw new IllegalArgumentException(e);
}
}
});
}
}
else {
// FIXME isn't this somewhat the same as createPresence?
String show = intent.getStringExtra(EXTRA_SHOW);
Presence p = new Presence(type != null ? Presence.Type.valueOf(type) : Presence.Type.available);
p.setStanzaId(id);
if (to != null)
p.setTo(to);
if (intent.hasExtra(EXTRA_PRIORITY))
p.setPriority(intent.getIntExtra(EXTRA_PRIORITY, 0));
String status = intent.getStringExtra(EXTRA_STATUS);
if (!TextUtils.isEmpty(status))
p.setStatus(status);
if (show != null)
p.setMode(Presence.Mode.valueOf(show));
sendPacket(p);
}
}
return false;
}