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


Java Presence.getType方法代碼示例

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


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

示例1: buddyCountOnline

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
 * Used by Velocity renderer
 * 
 * @return a String representing the online buddies out of the number of total buddies
 */
public String buddyCountOnline() {
    int onlineBuddyEntries = connection.getRoster().getEntryCount();
    final int allBuddies = onlineBuddyEntries;
    for (final Iterator l = connection.getRoster().getEntries().iterator(); l.hasNext();) {
        final RosterEntry entry = (RosterEntry) l.next();
        final Presence presence = connection.getRoster().getPresence(entry.getUser());
        if (presence.getType() == Presence.Type.unavailable) {
            onlineBuddyEntries--;
        }
    }
    // final string looks like e.g. "(3/5)"
    final StringBuilder sb = new StringBuilder(10);
    sb.append("(");
    sb.append(onlineBuddyEntries);
    sb.append("/");
    sb.append(allBuddies);
    sb.append(")");
    return sb.toString();
}
 
開發者ID:huihoo,項目名稱:olat,代碼行數:25,代碼來源:InstantMessagingClient.java

示例2: buddyCountOnlineForGroup

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
 * Used by Velocity renderer
 * 
 * @param groupname
 * @return a String representing the online buddies out of the number of total buddies for a single group like (3/5)
 */
protected String buddyCountOnlineForGroup(final String groupname) {
    final RosterGroup rosterGroup = connection.getRoster().getGroup(groupname);
    int buddyEntries = rosterGroup.getEntryCount();
    final int allBuddies = buddyEntries;
    for (final Iterator I = rosterGroup.getEntries().iterator(); I.hasNext();) {
        final RosterEntry entry = (RosterEntry) I.next();
        final Presence presence = connection.getRoster().getPresence(entry.getUser());
        if (presence.getType() == Presence.Type.unavailable) {
            buddyEntries--;
        }
    }
    // final string looks like e.g. "(3/5)"
    final StringBuilder sb = new StringBuilder(10);
    sb.append("(");
    sb.append(buddyEntries);
    sb.append("/");
    sb.append(allBuddies);
    sb.append(")");
    return sb.toString();
}
 
開發者ID:huihoo,項目名稱:olat,代碼行數:27,代碼來源:InstantMessagingClient.java

示例3: updatePresence

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public void updatePresence() {
	try {
		Connection connection = XmppConnectionUtils.getInstance()
				.getConnection();
		if (connection != null && connection.isConnected()
				&& connection.isAuthenticated()) {
			// 在線狀態獲取
			Presence presence = connection.getRoster().getPresence(mUserId);
			if (presence.getType() != Type.unavailable) {
				setPresence("online");
			} else {
				setPresence("unavailable");
			}
			saveToDatabase();
		}
	} catch (Exception e) {
		// TODO: handle exception
	}
}
 
開發者ID:ikantech,項目名稱:yiim_v2,代碼行數:20,代碼來源:XmppVcard.java

示例4: onVoiceBtnClick

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public void onVoiceBtnClick(View v) {
	if (!getXmppBinder().isAVCallOK()) {
		showProgressDialog(getString(R.string.err_call_check_net));
		getHandler().sendEmptyMessageDelayed(MSG_CHECK_NATWORK_TYPE, 200);
		return;
	}

	Presence pre = getXmppBinder().getXmppConnection().getRoster()
			.getPresence(mUserTo);
	if (pre.getType() != Presence.Type.unavailable) {
		Intent intent = new Intent(
				"com.ikantech.xmppsupoort.jingle.ACTION_CALL");
		intent.setData(Uri.parse("xmpp:" + pre.getFrom()));
		intent.putExtra("isCaller", true);
		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		startActivity(intent);
	} else {
		showMsgDialog(getString(R.string.err_call_user_not_online));
	}
}
 
開發者ID:ikantech,項目名稱:yiim_v2,代碼行數:21,代碼來源:BaseChatActivity.java

示例5: getInitialOnlineUsers

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
 * Get online users from roster and store in onlineUsers
 */
private void getInitialOnlineUsers() {
	Roster roster = Roster.getInstanceFor(connection);
	Collection<RosterEntry> entries = roster.getEntries();
	if (entries != null && !entries.isEmpty()) {
		for (RosterEntry entry : entries) {
			String jid = entry.getUser();
			Presence presence = roster.getPresence(jid);
			if (presence != null) {
				XMPPError xmppError = presence.getError();
				if (xmppError != null) {
					logger.error(xmppError.getDescriptiveText());
				} else {
					try {
						if (presence.getType() == Type.available) {
							onlineUsers.add(jid.substring(0, jid.indexOf('@')));
						} else if (presence.getType() == Type.unavailable) {
							onlineUsers.remove(jid.substring(0, jid.indexOf('@')));
						}
					} catch (Exception e) {
						logger.error(e.getMessage(), e);
					}
				}
			}
		}
	}
	logger.debug("Online users: {}", onlineUsers.toString());
}
 
開發者ID:Pardus-LiderAhenk,項目名稱:lider,代碼行數:31,代碼來源:OnlineRosterListener.java

示例6: processPacket

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
 * This only handles {@link Presence} packets with type "subscribe". {@inheritDoc}
 * 
 * @throws NotConnectedException
 */
@Override
public void processPacket(Packet packet) throws NotConnectedException {
    if (!(packet instanceof Presence)) {
        return;
    }
    Presence presence = (Presence) packet;
    switch (presence.getType()) {
    case subscribe:
        sendSubscriptionRequest(presence);
        break;
    }
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:18,代碼來源:XMPPPresencePacketListener.java

示例7: isAvailable

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
 * Returns true if the workgroup is available for receiving new requests. The workgroup will be
 * available only when agents are available for this workgroup.
 *
 * @return true if the workgroup is available for receiving new requests.
 * @throws XMPPErrorException 
 * @throws NoResponseException 
 * @throws NotConnectedException 
 */
public boolean isAvailable() throws NoResponseException, XMPPErrorException, NotConnectedException {
    Presence directedPresence = new Presence(Presence.Type.available);
    directedPresence.setTo(workgroupJID);
    StanzaFilter typeFilter = new StanzaTypeFilter(Presence.class);
    StanzaFilter fromFilter = FromMatchesFilter.create(workgroupJID);
    PacketCollector collector = connection.createPacketCollectorAndSend(new AndFilter(fromFilter,
            typeFilter), directedPresence);

    Presence response = (Presence)collector.nextResultOrThrow();
    return Presence.Type.available == response.getType();
}
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:21,代碼來源:Workgroup.java

示例8: interceptPacket

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public void interceptPacket(Packet packet) {
    Presence presence = (Presence) packet;
    // Check if user is joining a room
    if (Presence.Type.available == presence.getType() &&
            presence.getExtension("x", "http://jabber.org/protocol/muc") != null) {
        // Add extension that indicates that user wants to be a deaf occupant
        packet.addExtension(new DeafExtension());
    }
}
 
開發者ID:ice-coffee,項目名稱:EIM,代碼行數:10,代碼來源:DeafOccupantInterceptor.java

示例9: getStatus

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
 * 獲取狀態
 * 
 * @param presence
 * @return
 */
private StatusMode getStatus(Presence presence) {
	if (presence.getType() == Presence.Type.available) {
		if (presence.getMode() != null) {
			return StatusMode.valueOf(presence.getMode().name());
		}
		return StatusMode.available;
	}
	return StatusMode.offline;
}
 
開發者ID:victoryckl,項目名稱:XmppTest,代碼行數:16,代碼來源:SmackImpl.java

示例10: getUserPresence

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
 * Used by Velocity renderer
 * 
 * @param jid
 * @return get a presence for a specific user
 */
protected String getUserPresence(final String jid) {
    final Presence presence = connection.getRoster().getPresence(jid);
    String imageName = "offline"; // default
    // mode == null is equals available!!
    if (presence.getMode() == null && presence.getType() == Presence.Type.available) {
        imageName = Presence.Mode.available.toString();
    }
    if (presence.getMode() != null) {
        imageName = presence.getMode().toString();
    }
    return imageName;
}
 
開發者ID:huihoo,項目名稱:olat,代碼行數:19,代碼來源:InstantMessagingClient.java

示例11: processStanza

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
@Override
public void processStanza(Stanza packet) {
    try {
        Presence p = (Presence) packet;

        // presence subscription request
        if (p.getType() == Presence.Type.subscribe) {

            handleSubscribe(p);

        }

        /*
        else if (p.getType() == Presence.Type.unsubscribed) {
            // TODO can this even happen?
        }
        */

        else if (p.getType() == Presence.Type.available || p.getType() == Presence.Type.unavailable) {
            if (p.getType() == Presence.Type.unavailable) {
                // clear contact volatile state and cached data
                Contact.invalidateData(p.getFrom().toString());
            }

            handlePresence(p);

        }
    }
    catch (Exception e) {
        Log.e(MessageCenterService.TAG, "error parsing presence", e);
    }
}
 
開發者ID:kontalk,項目名稱:androidclient,代碼行數:33,代碼來源:PresenceListener.java

示例12: interceptPacket

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public void interceptPacket(Packet packet) {
	Presence presence = (Presence) packet;
	// Check if user is joining a room
	if (Presence.Type.available == presence.getType()
			&& presence.getExtension("x", "http://jabber.org/protocol/muc") != null) {
		// Add extension that indicates that user wants to be a deaf
		// occupant
		packet.addExtension(new DeafExtension());
	}
}
 
開發者ID:ikantech,項目名稱:xmppsupport_v2,代碼行數:11,代碼來源:DeafOccupantInterceptor.java

示例13: getImage

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
private void getImage(String requestAgent, String workgroup, HttpServletRequest request, HttpServletResponse response) {
    ChatManager chatManager = ChatManager.getInstance();

    boolean isOnline = WorkgroupStatus.isOnline(workgroup);
    final SettingsManager imageManager = SettingsManager.getInstance();

    final Roster roster = chatManager.getGlobalConnection().getRoster();
    final Presence presence = roster.getPresence(requestAgent);

    isOnline = isOnline && presence != null && presence.getType() == Presence.Type.available;

    if (!isOnline) {
        Object o = roster.getEntry(requestAgent);
        if (o == null) {
            try {
                roster.createEntry(requestAgent, requestAgent, null);
            }
            catch (XMPPException e) {
               WebLog.logError("Error creating new roster entry:", e);
            }
        }
    }

    byte[] image;
    if (isOnline) {
        image = imageManager.getImage("personalonline", workgroup, getServletContext());
    }
    else {
        image = imageManager.getImage("personaloffline", workgroup, getServletContext());
    }

    imageManager.writeBytesToStream(image, response);
}
 
開發者ID:igniterealtime,項目名稱:Fastpath-webchat,代碼行數:34,代碼來源:DynamicImageServlet.java

示例14: isAgentOnline

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
 * Checks the availability of the specified agent.
 *
 * @param agentJID the jid of the agent to check.
 * @return true if the agent is available to accept a request.
 */
public static boolean isAgentOnline(String agentJID) {
    ChatManager chatManager = ChatManager.getInstance();
    XMPPConnection globalConnection = chatManager.getGlobalConnection();

    Presence directedPresence = new Presence(Presence.Type.available);
    directedPresence.setProperty("anonymous", true);
    directedPresence.setTo(agentJID);
    PacketFilter typeFilter = new PacketTypeFilter(Presence.class);
    PacketFilter fromFilter = new FromContainsFilter(agentJID);
    PacketCollector collector = globalConnection.createPacketCollector(new AndFilter(fromFilter,
            typeFilter));

    globalConnection.sendPacket(directedPresence);

    Presence response = (Presence)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        return false;
    }
    if (response.getError() != null) {
        return false;
    }
    return Presence.Type.available == response.getType();
}
 
開發者ID:igniterealtime,項目名稱:Fastpath-webchat,代碼行數:33,代碼來源:WorkgroupStatus.java

示例15: processPacket

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
@Override
public void processPacket(Packet packet) {
    try {
        Presence p = (Presence) packet;

        // presence subscription request
        if (p.getType() == Presence.Type.subscribe) {

            handleSubscribe(p);

        }

        // presence subscription response
        else if (p.getType() == Presence.Type.subscribed) {

            handleSubscribed(p);

        }

        /*
        else if (p.getType() == Presence.Type.unsubscribed) {
            // TODO can this even happen?
        }
        */

        else {

            handlePresence(p);

        }
    }
    catch (Exception e) {
        Log.e(MessageCenterService.TAG, "error parsing presence", e);
    }
}
 
開發者ID:ShadiNachat,項目名稱:Chatting-App-,代碼行數:36,代碼來源:PresenceListener.java


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