本文整理匯總了Java中org.jivesoftware.smack.packet.Presence.setTo方法的典型用法代碼示例。如果您正苦於以下問題:Java Presence.setTo方法的具體用法?Java Presence.setTo怎麽用?Java Presence.setTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jivesoftware.smack.packet.Presence
的用法示例。
在下文中一共展示了Presence.setTo方法的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: 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: removeContact
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public void removeContact(String jidString)
throws SmackException.NotLoggedInException, InterruptedException,
SmackException.NotConnectedException, XMPPException.XMPPErrorException,
SmackException.NoResponseException, XmppStringprepException {
Roster roster = Roster.getInstanceFor(XMPPSession.getInstance().getXMPPConnection());
if (!roster.isLoaded()) {
roster.reloadAndWait();
}
BareJid jid = JidCreate.bareFrom(jidString);
roster.removeEntry(roster.getEntry(jid));
Presence presence = new Presence(Presence.Type.unsubscribe);
presence.setTo(JidCreate.from(jidString));
XMPPSession.getInstance().sendStanza(presence);
}
示例4: enableUser
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* This method sends a friend request to the user if he isn't already in the bots {@link Roster}
* . {@inheritDoc}
*/
@Override
public void enableUser(String username) {
if (!connection.isConnected()) {
return;
}
Roster roster = connection.getRoster();
if (roster != null && roster.getEntry(username) != null) {
return;
}
try {
String clientId = ClientAndChannelContextHolder.getClient().getClientId();
Presence subscribe = new Presence(Presence.Type.subscribe);
subscribe.setFrom(sender);
subscribe.setTo(username + "." + clientId + XMPPPatternUtils.getUserSuffix());
connection.sendPacket(subscribe);
Presence subscribed = new Presence(Presence.Type.subscribed);
subscribed.setFrom(sender);
subscribed.setTo(username + "." + clientId + XMPPPatternUtils.getUserSuffix());
connection.sendPacket(subscribed);
} catch (NotConnectedException e) {
LOG.debug("Could not send friendship request because XMPP connector is disconnected");
}
}
示例5: testDirectPresence
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* Will a user recieve a message from another after only sending the user a directed presence,
* or will Wildfire intercept for offline storage?
*
* User1 becomes lines. User0 never sent an available presence to the server but
* instead sent one to User1. User1 sends a message to User0. Should User0 get the
* message?
*/
public void testDirectPresence() {
getConnection(1).sendStanza(new Presence(Presence.Type.available));
Presence presence = new Presence(Presence.Type.available);
presence.setTo(getBareJID(1));
getConnection(0).sendStanza(presence);
PacketCollector collector = getConnection(0)
.createPacketCollector(new MessageTypeFilter(Message.Type.chat));
try {
getConnection(1).getChatManager().createChat(getBareJID(0), null).sendMessage("Test 1");
}
catch (XMPPException e) {
e.printStackTrace();
fail(e.getMessage());
}
Message message = (Message) collector.nextResult(2500);
assertNotNull("Message not recieved from remote user", message);
}
示例6: 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();
}
示例7: leave
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* Leave the chat room.
* @throws NotConnectedException
*/
public synchronized void leave() throws NotConnectedException {
// If not joined already, do nothing.
if (!joined) {
return;
}
// We leave a room by sending a presence packet where the "to"
// field is in the form "[email protected]/nickname"
Presence leavePresence = new Presence(Presence.Type.unavailable);
leavePresence.setTo(room + "/" + nickname);
connection.sendStanza(leavePresence);
// Reset occupant information.
occupantsMap.clear();
nickname = null;
joined = false;
userHasLeft();
}
示例8: changeNickname
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* Changes the occupant's nickname to a new nickname within the room. Each room occupant
* will receive two presence packets. One of type "unavailable" for the old nickname and one
* indicating availability for the new nickname. The unavailable presence will contain the new
* nickname and an appropriate status code (namely 303) as extended presence information. The
* status code 303 indicates that the occupant is changing his/her nickname.
*
* @param nickname the new nickname within the room.
* @throws XMPPErrorException if the new nickname is already in use by another occupant.
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
*/
public void changeNickname(String nickname) throws NoResponseException, XMPPErrorException, NotConnectedException {
StringUtils.requireNotNullOrEmpty(nickname, "Nickname must not be null or blank.");
// Check that we already have joined the room before attempting to change the
// nickname.
if (!joined) {
throw new IllegalStateException("Must be logged into the room to change nickname.");
}
// We change the nickname by sending a presence packet where the "to"
// field is in the form "[email protected]/nickname"
// We don't have to signal the MUC support again
Presence joinPresence = new Presence(Presence.Type.available);
joinPresence.setTo(room + "/" + nickname);
// Wait for a presence packet back from the server.
StanzaFilter responseFilter =
new AndFilter(
FromMatchesFilter.createFull(room + "/" + nickname),
new StanzaTypeFilter(Presence.class));
PacketCollector response = connection.createPacketCollectorAndSend(responseFilter, joinPresence);
// Wait up to a certain number of seconds for a reply. If there is a negative reply, an
// exception will be thrown
response.nextResultOrThrow();
this.nickname = nickname;
}
示例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.
* @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);
}
示例10: leave
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* Leave the chat room.
*/
public synchronized void leave() {
// If not joined already, do nothing.
if (!joined) {
return;
}
// We leave a room by sending a presence packet where the "to"
// field is in the form "[email protected]/nickname"
Presence leavePresence = new Presence(Presence.Type.unavailable);
leavePresence.setTo(room + "/" + nickname);
// Invoke presence interceptors so that extra information can be dynamically added
for (PacketInterceptor packetInterceptor : presenceInterceptors) {
packetInterceptor.interceptPacket(leavePresence);
}
connection.sendPacket(leavePresence);
// Reset occupant information.
occupantsMap.clear();
nickname = null;
joined = false;
userHasLeft();
}
示例11: 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);
}
示例12: subscribeToUser
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* Sends a subscription request to the username answers are handled by the method
*
* @param uname
* @param groupname
*/
protected void subscribeToUser(final String uname, final String groupname) {
final Presence presence = new Presence(Presence.Type.subscribe);
presence.setTo(uname + "@" + jabberServer);
try {
connection.sendPacket(presence);
final RosterPacket rosterPacket = new RosterPacket();
rosterPacket.setType(IQ.Type.SET);
final RosterPacket.Item item = new RosterPacket.Item(uname + "@" + jabberServer, uname);
item.addGroupName(groupname);
item.setItemType(RosterPacket.ItemType.both);
rosterPacket.addRosterItem(item);
connection.sendPacket(rosterPacket);
} catch (final RuntimeException e) {
log.warn("Error while trying to send Instant Messaging packet.", e);
}
}
示例13: leave
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* Leave the chat room.
*/
public synchronized void leave() {
// If not joined already, do nothing.
if (!joined) {
return;
}
// We leave a room by sending a presence packet where the "to"
// field is in the form "[email protected]/nickname"
Presence leavePresence = new Presence(Presence.Type.unavailable);
leavePresence.setTo(room + "/" + nickname);
// Invoke presence interceptors so that extra information can be
// dynamically added
for (PacketInterceptor packetInterceptor : presenceInterceptors) {
packetInterceptor.interceptPacket(leavePresence);
}
connection.sendPacket(leavePresence);
// Reset occupant information.
occupantsMap.clear();
nickname = null;
joined = false;
userHasLeft();
}
示例14: addUserHaveGroup
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* 添加好友 有分組
* @param xmppConnection
* @param userName 用戶名
* @param name 備注名
* @param groupName 分組名
* @return
*/
public static boolean addUserHaveGroup(XMPPConnection xmppConnection,String userName, String name, String groupName) {
try {
Presence subscription = new Presence(Presence.Type.subscribed);
subscription.setTo(userName);
userName += "@" + xmppConnection.getServiceName();
xmppConnection.sendPacket(subscription);
xmppConnection.getRoster().createEntry(userName, name, new String[] { groupName });
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
示例15: addUserHaveGroup
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* 添加好友 有分組
* @param xmppConnection
* @param userName 用戶名
* @param name 備注名
* @param groupName 分組名
* @return
*/
public static boolean addUserHaveGroup(XMPPConnection xmppConnection, String userName, String name, String groupName) {
try {
Presence subscription = new Presence(Presence.Type.subscribed);
subscription.setTo(userName);
userName += "@" + xmppConnection.getServiceName();
xmppConnection.sendPacket(subscription);
xmppConnection.getRoster().createEntry(userName, name, new String[]{groupName});
return true;
} catch (Exception e) {
Log.e("addUser", e.getMessage());
e.printStackTrace();
return false;
}
}