本文整理汇总了Java中org.xmpp.packet.Presence.setTo方法的典型用法代码示例。如果您正苦于以下问题:Java Presence.setTo方法的具体用法?Java Presence.setTo怎么用?Java Presence.setTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmpp.packet.Presence
的用法示例。
在下文中一共展示了Presence.setTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: route
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* 路由这个Presence包
*
* @param packet
*/
public void route(Presence packet) {
if (packet == null) {
throw new NullPointerException();
}
ClientSession session = sessionManager.getSession(packet.getFrom());
if (session == null || session.getStatus() != Session.STATUS_CONNECTED) {
handle(packet);
} else {
packet.setTo(session.getAddress());
packet.setFrom((JID) null);
packet.setError(PacketError.Condition.not_authorized);
session.process(packet);
}
}
示例2: presenceSubscriptionRequired
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Requests the pubsub service to unsubscribe from the presence of the user. If the service
* was not subscribed to the user's presence or any node still requires to be subscribed to
* the user presence then do nothing.
*
* @param service the PubSub service this action is to be performed for.
* @param node the node that originated the unsubscription request.
* @param user the JID of the affiliate to unsubscribe from his presence.
*/
public static void presenceSubscriptionRequired(PubSubService service, Node node, JID user) {
Map<String, String> fullPresences = service.getBarePresences().get(user.toString());
if (fullPresences == null || fullPresences.isEmpty()) {
Presence subscription = new Presence(Presence.Type.subscribe);
subscription.setTo(user);
subscription.setFrom(service.getAddress());
service.send(subscription);
// Sending subscription requests based on received presences may generate
// that a sunscription request is sent to an offline user (since offline
// presences are not stored in the service's "barePresences"). However, this
// not optimal algorithm shouldn't bother the user since the user's server
// should reply when already subscribed to the user's presence instead of
// asking the user to accept the subscription request.
}
}
示例3: broadcastPresenceOfOtherResource
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Sends the presences of other connected resources to the resource that just connected.
*
* @param session the newly created session.
*/
private void broadcastPresenceOfOtherResource(LocalClientSession session) {
if (!SessionManager.isOtherResourcePresenceEnabled()) {
return;
}
Presence presence;
// Get list of sessions of the same user
JID searchJID = new JID(session.getAddress().getNode(), session.getAddress().getDomain(), null);
List<JID> addresses = routingTable.getRoutes(searchJID, null);
for (JID address : addresses) {
if (address.equals(session.getAddress())) {
continue;
}
// Send the presence of an existing session to the session that has just changed
// the presence
ClientSession userSession = routingTable.getClientRoute(address);
presence = userSession.getPresence().createCopy();
presence.setTo(session.getAddress());
session.process(presence);
}
}
示例4: broadcastPresenceToOtherResources
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Broadcasts presence updates from the originating user's resource to any of the user's
* existing available resources (if any).
*
* @param originatingResource the full JID of the session that sent the presence update.
* @param presence the presence.
*/
public void broadcastPresenceToOtherResources(JID originatingResource, Presence presence) {
// RFC 6121 4.4.2 says we always send to the originating resource.
// Also RFC 6121 4.2.2 for updates.
presence.setTo(originatingResource);
routingTable.routePacket(originatingResource, presence, false);
if (!SessionManager.isOtherResourcePresenceEnabled()) {
return;
}
// Get list of sessions of the same user
JID searchJID = new JID(originatingResource.getNode(), originatingResource.getDomain(), null);
List<JID> addresses = routingTable.getRoutes(searchJID, null);
for (JID address : addresses) {
if (!originatingResource.equals(address)) {
// Send the presence of the session whose presence has changed to
// this user's other session(s)
presence.setTo(address);
routingTable.routePacket(address, presence, false);
}
}
}
示例5: sendPresence
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Sends the current presence to the session user.
*
* @param to JID to send presence updates to.
*/
public void sendPresence(JID to) {
// TODO: Should figure out best way to handle unknown here.
Presence p = new Presence();
p.setTo(to);
p.setFrom(jid);
getManager().getSession().getTransport().setUpPresencePacket(p, presence);
if (verboseStatus != null && verboseStatus.length() > 0) {
p.setStatus(verboseStatus);
}
if (avatarSet && avatar != null) {
Element vcard = p.addChildElement("x", NameSpace.VCARD_TEMP_X_UPDATE);
vcard.addElement("photo").addCDATA(avatar.getXmppHash());
vcard.addElement("hash").addCDATA(avatar.getXmppHash());
}
getManager().sendPacket(p);
}
示例6: cleanupDirectedPresences
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
private void cleanupDirectedPresences(NodeID nodeID) {
// Remove traces of directed presences sent from node that is gone to entities hosted in this JVM
Map<String, Collection<String>> senders = nodePresences.remove(nodeID);
if (senders != null) {
for (Map.Entry<String, Collection<String>> entry : senders.entrySet()) {
String sender = entry.getKey();
Collection<String> receivers = entry.getValue();
for (String receiver : receivers) {
try {
Presence presence = new Presence(Presence.Type.unavailable);
presence.setFrom(sender);
presence.setTo(receiver);
XMPPServer.getInstance().getPresenceRouter().route(presence);
}
catch (PacketException e) {
logger.error("Failed to cleanup directed presences", e);
}
}
}
}
}
示例7: setAvatar
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Sets the current avatar for this contact.
*
* @param avatar Avatar instance to associate with this contact.
*/
public void setAvatar(Avatar avatar) {
boolean triggerUpdate = false;
if ( (avatar != null && this.avatar == null) ||
(avatar == null && this.avatar != null) ||
(avatar != null && !this.avatar.getXmppHash().equals(avatar.getXmppHash()))) {
triggerUpdate = true;
}
this.avatar = avatar;
this.avatarSet = true;
if (triggerUpdate) {
Presence p = new Presence();
p.setTo(getManager().getSession().getJID());
p.setFrom(jid);
getManager().getSession().getTransport().setUpPresencePacket(p, presence);
if (!verboseStatus.equals("")) {
p.setStatus(verboseStatus);
}
Element vcard = p.addChildElement("x", NameSpace.VCARD_TEMP_X_UPDATE);
if (avatar != null) {
vcard.addElement("photo").addCDATA(avatar.getXmppHash());
vcard.addElement("hash").addCDATA(avatar.getXmppHash());
}
getManager().sendPacket(p);
}
}
示例8: setPresenceAndStatus
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Convenience routine to set both presence and verbose status at the same time.
*
* @param newpresence New presence to set to.
* @param newstatus New verbose status.
*/
public void setPresenceAndStatus(PresenceType newpresence, String newstatus) {
Log.debug("Updating status ["+newpresence+","+newstatus+"] for "+this);
if (newpresence == null) {
newpresence = PresenceType.unknown;
}
if (newstatus == null) {
newstatus = "";
}
if (newpresence.equals(PresenceType.unavailable)) {
newstatus = "";
}
if ((!presence.equals(newpresence) && newpresence != PresenceType.unknown) || !verboseStatus.equals(newstatus)) {
Presence p = new Presence();
p.setTo(getManager().getSession().getJID());
p.setFrom(jid);
getManager().getSession().getTransport().setUpPresencePacket(p, newpresence);
if (!newstatus.equals("")) {
p.setStatus(newstatus);
}
if (avatarSet && avatar != null) {
Element vcard = p.addChildElement("x", NameSpace.VCARD_TEMP_X_UPDATE);
vcard.addElement("photo").addCDATA(avatar.getXmppHash());
vcard.addElement("hash").addCDATA(avatar.getXmppHash());
}
getManager().sendPacket(p);
}
presence = newpresence;
verboseStatus = newstatus;
lastActivityTimestamp = new Date().getTime();
lastActivityEvent = verboseStatus;
}
示例9: createEntry
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Creates a new roster entry and presence subscription. The server will
* asynchronously update the roster with the subscription status.
*
* @param user
* the user. (e.g. [email protected])
* @param name
* the nickname of the user.
* @param groups
* the list of group names the entry will belong to, or
* <tt>null</tt> if the the roster entry won't belong to a group.
* @throws XMPPException
* if an XMPP exception occurs.
* @throws IllegalStateException
* if connection is not logged in or logged in anonymously
*/
public void createEntry(String user, String name, String[] groups)
throws XMPPException {
if (!connection.isAuthenticated()) {
throw new IllegalStateException("Not logged in to server.");
}
if (connection.isAnonymous()) {
throw new IllegalStateException(
"Anonymous users can't have a roster.");
}
// Create and send roster entry creation packet.
Roster rosterPacket = new Roster();
rosterPacket.setType(IQ.Type.set);
rosterPacket.addItem(new JID(user), name, null, null,
Arrays.asList(groups));
// Wait up to a certain number of seconds for a reply from the server.
PacketCollector collector = connection
.createPacketCollector(new PacketIDFilter(rosterPacket.getID()));
connection.sendPacket(rosterPacket);
IQ response = (IQ) collector.nextResult(SmackConfiguration
.getPacketReplyTimeout());
collector.cancel();
if (response == null) {
throw new XMPPException("No response from the server.");
}
// If the server replied with an error, throw an exception.
else if (response.getType() == IQ.Type.error) {
throw new XMPPException(response.getError());
}
// Create a presence subscription packet and send.
Presence presencePacket = new Presence(Presence.Type.subscribe);
presencePacket.setTo(user);
connection.sendPacket(presencePacket);
}
示例10: sendStatusOfAllAgents
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Sends the presence of each available agent in the workgroup to this agent.
*
* @param workgroup the workgroup whose agents' presences will be sent to this agent.
*/
private void sendStatusOfAllAgents(Workgroup workgroup) {
for (AgentSession agentSession : workgroup.getAgentSessions()) {
if (!agentSession.getJID().equals(address)) {
Presence statusPacket = agentSession.getPresence().createCopy();
statusPacket.setFrom(agentSession.getJID());
statusPacket.setTo(address);
// Add the agent-status element
agentSession.getAgentStatus(statusPacket,workgroup);
workgroup.send(statusPacket);
}
}
}
示例11: handleDeregister
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Processes an IQ-register request that is expressing the wish to
* deregister from a gateway.
*
* @param packet the IQ-register stanza.
*/
private void handleDeregister(final IQ packet) {
final IQ result = IQ.createResultIQ(packet);
if (packet.getChildElement().elements().size() != 1) {
Log.debug("Cannot process this stanza - exactly one"
+ " childelement of <remove> expected:" + packet.toXML());
final IQ error = IQ.createResultIQ(packet);
error.setError(Condition.bad_request);
parent.sendPacket(error);
return;
}
final JID from = packet.getFrom();
final JID to = packet.getTo();
// Tell the end user the transport went byebye.
final Presence unavailable = new Presence(Presence.Type.unavailable);
unavailable.setTo(from);
unavailable.setFrom(to);
this.parent.sendPacket(unavailable);
try {
deleteRegistration(from);
}
catch (UserNotFoundException e) {
Log.debug("Error cleaning up contact list of: " + from);
result.setError(Condition.registration_required);
}
parent.sendPacket(result);
}
示例12: contactRemovedMe
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Someone removed us from their contact list.
*/
public void contactRemovedMe(MsnMessenger messenger, MsnContact friend) {
Log.debug("MSN: Contact removed me: "+ friend.getFriendlyName());
Presence p = new Presence();
p.setType(Presence.Type.unsubscribe);
p.setTo(getSession().getJID());
p.setFrom(getSession().getTransport().convertIDToJID(friend.getEmail().toString()));
getSession().getTransport().sendPacket(p);
}
示例13: sendSubscribeRequest
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
private void sendSubscribeRequest(JID sender, JID recipient, boolean isSubscribe) {
Presence presence = new Presence();
presence.setFrom(sender);
presence.setTo(recipient);
if (isSubscribe) {
presence.setType(Presence.Type.subscribe);
}
else {
presence.setType(Presence.Type.unsubscribe);
}
routingTable.routePacket(recipient, presence, false);
}
示例14: sendStatus
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void sendStatus(JID recipient) {
try {
Presence queueStatus = getStatusPresence();
queueStatus.setTo(recipient);
workgroup.send(queueStatus);
}
catch (Exception e) {
Log.error(e.getMessage(), e);
}
}
示例15: contactRejectionReceived
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* @see org.openymsg.network.event.SessionAdapter#contactRejectionReceived(org.openymsg.network.event.SessionFriendRejectedEvent)
*/
public void contactRejectionReceived(SessionFriendRejectedEvent event) {
// TODO: Is this correct? unsubscribed for a rejection?
Log.debug(event.toString());
Presence p = new Presence(Presence.Type.unsubscribed);
p.setTo(getSession().getJID());
p.setFrom(getSession().getTransport().convertIDToJID(event.getFrom()));
getSession().getTransport().sendPacket(p);
}