本文整理匯總了Java中org.jivesoftware.smack.packet.Presence類的典型用法代碼示例。如果您正苦於以下問題:Java Presence類的具體用法?Java Presence怎麽用?Java Presence使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Presence類屬於org.jivesoftware.smack.packet包,在下文中一共展示了Presence類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: AgentRoster
import org.jivesoftware.smack.packet.Presence; //導入依賴的package包/類
/**
* Constructs a new AgentRoster.
*
* @param connection an XMPP connection.
* @throws NotConnectedException
*/
AgentRoster(XMPPConnection connection, String workgroupJID) throws NotConnectedException {
this.connection = connection;
this.workgroupJID = workgroupJID;
entries = new ArrayList<String>();
listeners = new ArrayList<AgentRosterListener>();
presenceMap = new HashMap<String, Map<String, Presence>>();
// Listen for any roster packets.
StanzaFilter rosterFilter = new StanzaTypeFilter(AgentStatusRequest.class);
connection.addAsyncStanzaListener(new AgentStatusListener(), rosterFilter);
// Listen for any presence packets.
connection.addAsyncStanzaListener(new PresencePacketListener(),
new StanzaTypeFilter(Presence.class));
// Send request for roster.
AgentStatusRequest request = new AgentStatusRequest();
request.setTo(workgroupJID);
connection.sendStanza(request);
}
示例2: 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;
}
示例3: addUI
import org.jivesoftware.smack.packet.Presence; //導入依賴的package包/類
@Override
public void addUI(JComponent mainPanel, GridBagConstraints labelConstraints, GridBagConstraints editConstraints) {
addToPanel(mainPanel, labelConstraints, 0, 0, new JLabel("Type: ", JLabel.RIGHT));
addToPanel(mainPanel, editConstraints, 1, 0, type = new JComboBox<>());
type.addItem(Presence.Type.available);
type.addItem(Presence.Type.unavailable);
type.addItem(Presence.Type.subscribe);
type.addItem(Presence.Type.unsubscribe);
addToPanel(mainPanel, labelConstraints, 0, 1, new JLabel("Status: ", JLabel.RIGHT));
addToPanel(mainPanel, editConstraints, 1, 1, mode = new JComboBox<>());
mode.addItem(Presence.Mode.available);
mode.addItem(Presence.Mode.away);
mode.addItem(Presence.Mode.chat);
mode.addItem(Presence.Mode.dnd);
mode.addItem(Presence.Mode.xa);
addToPanel(mainPanel, labelConstraints, 0, 2, new JLabel("Text: ", JLabel.RIGHT));
addToPanel(mainPanel, editConstraints, 1, 2, text = new JTextField(20));
addToPanel(mainPanel, labelConstraints, 0, 3, new JLabel("Recipient: ", JLabel.RIGHT));
addToPanel(mainPanel, editConstraints, 1, 3, recipient = new JTextField(20));
}
示例4: 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);
}
示例5: getFullThingJidOrNotify
import org.jivesoftware.smack.packet.Presence; //導入依賴的package包/類
EntityFullJid getFullThingJidOrNotify() {
EntityBareJid thingJid = settings.getThingJid();
IoTProvisioningManager ioTProvisioningManager = IoTProvisioningManager.getInstanceFor(xmppConnection);
if (!ioTProvisioningManager.iAmFriendOf(thingJid)) {
withMainActivity((ma) -> Toast.makeText(ma, "Can not perform action. Not befriended with thing", Toast.LENGTH_LONG).show());
return null;
}
Presence presence = roster.getPresence(settings.getThingJid());
if (presence == null || !presence.isAvailable()) {
withMainActivity((ma) -> Toast.makeText(ma, "Can not perform action. Befriended with thing, but thing is not online/unavailable", Toast.LENGTH_LONG).show());
return null;
}
EntityFullJid fullOtherJid = presence.getFrom().asEntityFullJidIfPossible();
if (fullOtherJid == null) throw new IllegalStateException("Exepected full JID");
return fullOtherJid;
}
示例6: logoff
import org.jivesoftware.smack.packet.Presence; //導入依賴的package包/類
public void logoff() {
new Thread(new Runnable() {
@Override
public void run() {
try {
Presence presence = new Presence(Presence.Type.unavailable);
presence.setMode(Presence.Mode.away);
presence.setTo(JidCreate.from(SERVICE_NAME));
sendStanza(presence);
mReconnectionManager.disableAutomaticReconnection();
mXMPPConnection.disconnect();
stopService(MangostaApplication.getInstance());
} catch (Exception e) {
e.printStackTrace();
} finally {
clearInstance();
}
}
}).start();
}
示例7: sendPresenceAvailable
import org.jivesoftware.smack.packet.Presence; //導入依賴的package包/類
public void sendPresenceAvailable() {
if (mXMPPConnection.isAuthenticated()) {
new Thread(new Runnable() {
@Override
public void run() {
try {
Presence presence = new Presence(JidCreate.from(SERVICE_NAME), Presence.Type.available);
presence.setMode(Presence.Mode.available);
sendStanza(presence);
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
}
示例8: 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);
}
示例9: getStatusFromContact
import org.jivesoftware.smack.packet.Presence; //導入依賴的package包/類
public Presence.Type getStatusFromContact(String name) {
try {
HashMap<Jid, Presence.Type> buddies = getContacts();
for (Map.Entry<Jid, Presence.Type> pair : buddies.entrySet()) {
if (XMPPUtils.fromJIDToUserName(pair.getKey().toString()).equals(name)) {
return pair.getValue();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return Presence.Type.unavailable;
}
示例10: setPresence
import org.jivesoftware.smack.packet.Presence; //導入依賴的package包/類
/**
* 發送當前狀態
*
* @param status 狀態。內部類PRESENCE裏有兩種狀態 ONLINE 和 OFFLINE
*/
public void setPresence(final int status) {
//如果沒有連接,則返回
if (getConnection() == null) {
return;
}
//新線程裏發送狀態封包
new Thread() {
@Override
public void run() {
switch (status) {
case PRESENCE.ONLINE:
getConnection().sendPacket(
new Presence(Presence.Type.available));
break;
case PRESENCE.OFFLINE:
getConnection().sendPacket(
new Presence(Presence.Type.unavailable));
break;
default:
break;
}
}
}.start();
}
示例11: setStatus
import org.jivesoftware.smack.packet.Presence; //導入依賴的package包/類
/**
* sets the status
*
* @param available if true the status type will be set to available otherwise to unavailable
* @param status the status message
* @return true if setting the status was successful
*/
public boolean setStatus(boolean available, String status){
if (connection != null && connection.isConnected()){
// set the presence type
Presence presence = new Presence(available
? Presence.Type.available
: Presence.Type.unavailable);
presence.setStatus(status);
try{
connection.sendStanza(presence);
Log.d("DEBUG", "Success: Set status.");
return true;
}catch (Exception e){
System.err.println(e.toString());
Log.e("ERROR", "Error while setting status.");
return false;
}
}
Log.e("ERROR", "Setting status failed: No connection.");
return false;
}
示例12: presenceReceived
import org.jivesoftware.smack.packet.Presence; //導入依賴的package包/類
private void presenceReceived(Presence presence){
if (Presence.Type.available.equals(presence.getType()) &&
presence.getStatus() != null){
String from = presence.getFrom();
int index = from.indexOf('@');
if (index >= 0){
from = from.substring(0, index);
}
String status = presence.getStatus();
Intent intent = new Intent(Constants.PRESENCE_CHANGED);
intent.putExtra(Constants.BUDDY_ID, from);
intent.putExtra(Constants.PRESENCE_STATUS, status);
LocalBroadcastManager.getInstance(getApplicationContext())
.sendBroadcast(intent);
messageHistory.setOnline(from, status);
}
}
示例13: 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");
}
}
示例14: isAvailable
import org.jivesoftware.smack.packet.Presence; //導入依賴的package包/類
/**
* {@inheritDoc}
*
* @param username
* Has to be in the messagers format.
*/
@Override
public boolean isAvailable(String username) {
if (connection.isConnected()) {
Roster roster = connection.getRoster();
if (roster != null) {
Presence presence = roster.getPresence(username + XMPPPatternUtils.getUserSuffix());
return presence.isAvailable();
} else {
LOG.debug("XMPP connection did not return a roster for communote bot");
}
} else {
LOG.debug("Cannot check availability of user because XMPP connector is disconnected");
}
return false;
}
示例15: sendPriorityPresence
import org.jivesoftware.smack.packet.Presence; //導入依賴的package包/類
/**
* This method sends a {@link Presence} packet with the configured priority.
*/
private void sendPriorityPresence() {
if (!connection.isConnected()) {
return;
}
int priority = CommunoteRuntime.getInstance().getConfigurationManager()
.getApplicationConfigurationProperties()
.getProperty(ApplicationPropertyXmpp.PRIORITY, 100);
Presence presence = new Presence(Presence.Type.available);
presence.setPriority(priority);
try {
connection.sendPacket(presence);
} catch (NotConnectedException e) {
LOG.info("Could not send presence packet because XMPP connector is disconnected");
}
}