/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright 2003-2007 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.muc;
import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.PacketInterceptor;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.FromMatchesFilter;
import org.jivesoftware.smack.filter.MessageTypeFilter;
import org.jivesoftware.smack.filter.PacketExtensionFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Registration;
import org.jivesoftware.smackx.Form;
import org.jivesoftware.smackx.NodeInformationProvider;
import org.jivesoftware.smackx.ServiceDiscoveryManager;
import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.jivesoftware.smackx.packet.DiscoverItems;
import org.jivesoftware.smackx.packet.MUCAdmin;
import org.jivesoftware.smackx.packet.MUCInitialPresence;
import org.jivesoftware.smackx.packet.MUCOwner;
import org.jivesoftware.smackx.packet.MUCUser;
/**
* A MultiUserChat is a conversation that takes place among many users in a virtual
* room. A room could have many occupants with different affiliation and roles.
* Possible affiliatons are "owner", "admin", "member", and "outcast". Possible roles
* are "moderator", "participant", and "visitor". Each role and affiliation guarantees
* different privileges (e.g. Send messages to all occupants, Kick participants and visitors,
* Grant voice, Edit member list, etc.).
*
* @author Gaston Dombiak, Larry Kirschner
*/
public class MultiUserChat {
private final static String discoNamespace = "http://jabber.org/protocol/muc";
private final static String discoNode = "http://jabber.org/protocol/muc#rooms";
private static Map<Connection, List<String>> joinedRooms =
new WeakHashMap<Connection, List<String>>();
private Connection connection;
private String room;
private String subject;
private String nickname = null;
private boolean joined = false;
private Map<String, Presence> occupantsMap = new ConcurrentHashMap<String, Presence>();
private final List<InvitationRejectionListener> invitationRejectionListeners =
new ArrayList<InvitationRejectionListener>();
private final List<SubjectUpdatedListener> subjectUpdatedListeners =
new ArrayList<SubjectUpdatedListener>();
private final List<UserStatusListener> userStatusListeners =
new ArrayList<UserStatusListener>();
private final List<ParticipantStatusListener> participantStatusListeners =
new ArrayList<ParticipantStatusListener>();
private PacketFilter presenceFilter;
private List<PacketInterceptor> presenceInterceptors = new ArrayList<PacketInterceptor>();
private PacketFilter messageFilter;
private RoomListenerMultiplexor roomListenerMultiplexor;
private ConnectionDetachedPacketCollector messageCollector;
private List<PacketListener> connectionListeners = new ArrayList<PacketListener>();
static {
Connection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(final Connection connection) {
// Set on every established connection that this client supports the Multi-User
// Chat protocol. This information will be used when another client tries to
// discover whether this client supports MUC or not.
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(discoNamespace);
// Set the NodeInformationProvider that will provide information about the
// joined rooms whenever a disco request is received
ServiceDiscoveryManager.getInstanceFor(connection).setNodeInformationProvider(
discoNode,
new NodeInformationProvider() {
public List<DiscoverItems.Item> getNodeItems() {
List<DiscoverItems.Item> answer = new ArrayList<DiscoverItems.Item>();
Iterator<String> rooms=MultiUserChat.getJoinedRooms(connection);
while (rooms.hasNext()) {
answer.add(new DiscoverItems.Item(rooms.next()));
}
return answer;
}
public List<String> getNodeFeatures() {
return null;
}
public List<DiscoverInfo.Identity> getNodeIdentities() {
return null;
}
@Override
public List<PacketExtension> getNodePacketExtensions() {
return null;
}
});
}
});
}
/**
* Creates a new multi user chat with the specified connection and room name. Note: no
* information is sent to or received from the server until you attempt to
* {@link #join(String) join} the chat room. On some server implementations,
* the room will not be created until the first person joins it.<p>
*
* Most XMPP servers use a sub-domain for the chat service (eg chat.example.com
* for the XMPP server example.com). You must ensure that the room address you're
* trying to connect to includes the proper chat sub-domain.
*
* @param connection the XMPP connection.
* @param room the name of the room in the form "roomName@service", where
* "service" is the hostname at which the multi-user chat
* service is running. Make sure to provide a valid JID.
*/
public MultiUserChat(Connection connection, String room) {
this.connection = connection;
this.room = room.toLowerCase();
init();
}
/**
* Returns true if the specified user supports the Multi-User Chat protocol.
*
* @param connection the connection to use to perform the service discovery.
* @param user the user to check. A fully qualified xmpp ID, e.g. jdoe@example.com.
* @return a boolean indicating whether the specified user supports the MUC protocol.
*/
public static boolean isServiceEnabled(Connection connection, String user) {
tr
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
使用openfire作为IM服务器,spark作为pc端,本实例作为安卓客户端进行聊天交流,注意本代码是安卓端,其他组件可以上相关网站下载,按照步骤搭建好环境之后,使用本代码的apk安装在安卓上,可以通过本客户端与spark好友聊天,通过本代码,你可以学习如何使用smack库的api接口
资源推荐
资源详情
资源评论
收起资源包目录
openfire+spark+安卓的聊天解决方案 (1858个子文件)
jarlist.cache 120B
MultiUserChat.class 44KB
AgentSession.class 30KB
XmppTool.class 28KB
BOSHClient.class 27KB
XMPPConnection.class 23KB
PacketParserUtils.class 22KB
Roster.class 20KB
DNSSEC.class 19KB
AbstractHashedMap.class 18KB
Base64.class 18KB
Workgroup.class 18KB
Socks5BytestreamManager.class 17KB
EntityCapsManager.class 16KB
BOSHConnection.class 15KB
VCard.class 15KB
Name.class 15KB
Cache.class 14KB
AdHocCommandManager.class 14KB
StringUtils.class 14KB
Record.class 14KB
ServiceDiscoveryManager.class 13KB
Node.class 13KB
Connection.class 13KB
FileTransferNegotiator.class 13KB
MUCRoom.class 13KB
Lookup.class 12KB
PacketReader.class 12KB
ConfigureForm.class 12KB
DigestMD5SaslClient.class 12KB
Message.class 12KB
ResolverConfig.class 12KB
Zone.class 11KB
ZoneTransferIn.class 11KB
SASLAuthentication.class 11KB
ConnectionConfiguration.class 11KB
PubSubManager.class 11KB
AbstractReferenceMap.class 11KB
Tokenizer.class 10KB
Subject.class 10KB
InBandBytestreamManager.class 10KB
Packet.class 10KB
TSIG.class 10KB
LoginContext.class 9KB
MultipleRecipientManager.class 9KB
MyHome.class 9KB
Message.class 9KB
SimpleResolver.class 9KB
Gateway.class 9KB
PrivacyListManager.class 9KB
Master.class 9KB
OutgoingFileTransfer.class 9KB
PingManager.class 8KB
Form.class 8KB
ConfigureProviderManager.class 8KB
ChatManager.class 8KB
Sasl.class 8KB
LOCRecord.class 8KB
SmackConfiguration.class 8KB
Socks5BytestreamRequest.class 8KB
Address.class 8KB
AgentRoster.class 8KB
ServerTrustManager.class 8KB
OfflineMessageManager.class 7KB
ProviderManager.class 7KB
Cache.class 7KB
FaultTolerantNegotiator.class 7KB
LeafNode.class 7KB
InBandBytestreamSession.class 7KB
MessageEventManager.class 7KB
SASLFacebookConnect.class 7KB
VCard$VCardWriter.class 7KB
APLRecord.class 7KB
AccountManager.class 6KB
Type.class 6KB
VCardProvider$VCardReader.class 6KB
BookmarkManager.class 6KB
Bookmarks.class 6KB
FileTransferManager.class 6KB
Subject$SecureSet.class 6KB
DigestChallenge.class 6KB
DiscoverInfo.class 6KB
SubscribeForm.class 6KB
ChatStateManager.class 6KB
BOSHPacketReader.class 6KB
NSEC3Record.class 6KB
GatewayManager.class 6KB
UserSearch.class 6KB
XHTMLText.class 6KB
IncomingFileTransfer.class 6KB
Privacy.class 6KB
Header.class 6KB
RosterEntry.class 6KB
SimpleDirectoryPersistentCache.class 6KB
CMSessionParams.class 6KB
RosterGroup.class 6KB
DeliveryReceiptManager.class 6KB
PrivateCredentialPermission.class 6KB
AdHocCommandData.class 6KB
ChatActivity.class 6KB
共 1858 条
- 1
- 2
- 3
- 4
- 5
- 6
- 19
资源评论
- qq_407285302017-11-26怎么用啊?下载了解压后没有安装的文件啊
linux_good_kvm
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功