當前位置: 首頁>>代碼示例>>Java>>正文


Java Presence.setFrom方法代碼示例

本文整理匯總了Java中org.jivesoftware.smack.packet.Presence.setFrom方法的典型用法代碼示例。如果您正苦於以下問題:Java Presence.setFrom方法的具體用法?Java Presence.setFrom怎麽用?Java Presence.setFrom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jivesoftware.smack.packet.Presence的用法示例。


在下文中一共展示了Presence.setFrom方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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");
    }
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:28,代碼來源:XMPPConnector.java

示例2: getAllPresences

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
 * Returns a List of Presence objects for all of a user's current presences if no presence information is available,
 * such as when you are not subscribed to the user's presence updates.
 *
 * @param bareJid an XMPP ID, e.g. [email protected]
 * @return a List of Presence objects for all the user's current presences, or an unavailable presence if no
 *         presence information is available.
 */
public List<Presence> getAllPresences(String bareJid) {
    Map<String, Presence> userPresences = presenceMap.get(getMapKey(bareJid));
    List<Presence> res;
    if (userPresences == null) {
        // Create an unavailable presence if none was found
        Presence unavailable = new Presence(Presence.Type.unavailable);
        unavailable.setFrom(bareJid);
        res = new ArrayList<>(Arrays.asList(unavailable));
    } else {
        res = new ArrayList<>(userPresences.values().size());
        for (Presence presence : userPresences.values()) {
            res.add(presence.clone());
        }
    }
    return res;
}
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:25,代碼來源:Roster.java

示例3: 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);


    }
 
開發者ID:saveendhiman,項目名稱:XMPPSample_Studio,代碼行數:40,代碼來源:XMPP.java

示例4: sendSubscriptionRequest

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
 * This method sends a subscription request to the sender.
 *
 * @param presence
 *            The presence used for sender and receiver information.
 * @throws NotConnectedException
 */
private void sendSubscriptionRequest(Presence presence) throws NotConnectedException {
    int priority = CommunoteRuntime.getInstance().getConfigurationManager()
            .getApplicationConfigurationProperties()
            .getProperty(ApplicationPropertyXmpp.PRIORITY, 100);
    Presence subscription = new Presence(Presence.Type.subscribe);
    subscription.setPriority(priority);
    subscription.setFrom(presence.getTo());
    subscription.setTo(presence.getFrom());
    presence.setType(Presence.Type.subscribed);
    presence.setFrom(subscription.getFrom());
    presence.setTo(subscription.getTo());
    connection.sendPacket(presence);
    connection.sendPacket(subscription);
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:22,代碼來源:XMPPPresencePacketListener.java

示例5: login

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
 * This method lets you send the presence direct to the gateway. Type, To and From
 * are modified.
 * @param presence the presence used to login to gateway
 */
public void login(Presence presence){
	presence.setType(Presence.Type.available);
	presence.setTo(entityJID);
	presence.setFrom(connection.getUser());
	connection.sendPacket(presence);
}
 
開發者ID:CJC-ivotten,項目名稱:androidPN-client.,代碼行數:12,代碼來源:Gateway.java

示例6: logout

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
 * This method logs you out from this gateway by sending an unavailable presence
 * to directly to this gateway.
 */
public void logout(){
	Presence presence = new Presence(Presence.Type.unavailable);
	presence.setTo(entityJID);
	presence.setFrom(connection.getUser());
	connection.sendPacket(presence);
}
 
開發者ID:CJC-ivotten,項目名稱:androidPN-client.,代碼行數:11,代碼來源:Gateway.java

示例7: processPacket

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public void processPacket(Packet packet) {
	if(packet instanceof Presence){
		Presence presence = (Presence)packet;
		if(entityJID.equals(presence.getFrom()) && 
				roster.contains(presence.getFrom()) &&
				presence.getType().equals(Presence.Type.subscribe)){
			Presence response = new Presence(Presence.Type.subscribed);
			response.setTo(presence.getFrom());
			response.setFrom(StringUtils.parseBareAddress(connection.getUser()));
			connection.sendPacket(response);
		}
	}
	
}
 
開發者ID:CJC-ivotten,項目名稱:androidPN-client.,代碼行數:15,代碼來源:Gateway.java

示例8: broadcastMyPresence

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
 * A special method to broadcast our own presence.
 */
private void broadcastMyPresence(String id) {
    Presence presence = createPresence(null);
    presence.setFrom(mConnection.getUser());

    Intent i = PresenceListener.createIntent(this, presence, null);
    i.putExtra(EXTRA_FINGERPRINT, getMyFingerprint());
    i.putExtra(EXTRA_SUBSCRIBED_FROM, true);
    i.putExtra(EXTRA_SUBSCRIBED_TO, true);

    // to keep track of request-reply
    i.putExtra(EXTRA_PACKET_ID, id);
    mLocalBroadcastManager.sendBroadcast(i);
}
 
開發者ID:kontalk,項目名稱:androidclient,代碼行數:17,代碼來源:MessageCenterService.java

示例9: logout

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
 * This method logs you out from this gateway by sending an unavailable
 * presence to directly to this gateway.
 */
public void logout() {
	Presence presence = new Presence(Presence.Type.unavailable);
	presence.setTo(entityJID);
	presence.setFrom(connection.getUser());
	connection.sendPacket(presence);
}
 
開發者ID:ikantech,項目名稱:xmppsupport_v2,代碼行數:11,代碼來源:Gateway.java

示例10: processPacket

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public void processPacket(Packet packet) {
	if (packet instanceof Presence) {
		Presence presence = (Presence) packet;
		if (entityJID.equals(presence.getFrom())
				&& roster.contains(presence.getFrom())
				&& presence.getType().equals(Presence.Type.subscribe)) {
			Presence response = new Presence(Presence.Type.subscribed);
			response.setTo(presence.getFrom());
			response.setFrom(StringUtils.parseBareAddress(connection
					.getUser()));
			connection.sendPacket(response);
		}
	}

}
 
開發者ID:ikantech,項目名稱:xmppsupport_v2,代碼行數:16,代碼來源:Gateway.java

示例11: login

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
 * This method lets you send the presence direct to the gateway. Type, To
 * and From are modified.
 * 
 * @param presence
 *            the presence used to login to gateway
 */
public void login(Presence presence) {
	presence.setType(Presence.Type.available);
	presence.setTo(entityJID);
	presence.setFrom(connection.getUser());
	connection.sendPacket(presence);
}
 
開發者ID:ikantech,項目名稱:xmppsupport_v2,代碼行數:14,代碼來源:Gateway.java


注:本文中的org.jivesoftware.smack.packet.Presence.setFrom方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。