本文整理汇总了Java中org.jivesoftware.smackx.muc.packet.MUCUser类的典型用法代码示例。如果您正苦于以下问题:Java MUCUser类的具体用法?Java MUCUser怎么用?Java MUCUser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MUCUser类属于org.jivesoftware.smackx.muc.packet包,在下文中一共展示了MUCUser类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createOrJoin
import org.jivesoftware.smackx.muc.packet.MUCUser; //导入依赖的package包/类
/**
* Like {@link #create(String)}, but will return true if the room creation was acknowledged by
* the service (with an 201 status code). It's up to the caller to decide, based on the return
* value, if he needs to continue sending the room configuration. If false is returned, the room
* already existed and the user is able to join right away, without sending a form.
*
* @param nickname the nickname to use.
* @param password the password to use.
* @param history the amount of discussion history to receive while joining a room.
* @param timeout the amount of time to wait for a reply from the MUC service(in milliseconds).
* @return true if the room creation was acknowledged by the service, false otherwise.
* @throws XMPPErrorException if the room couldn't be created for some reason (e.g. 405 error if
* the user is not allowed to create the room)
* @throws NoResponseException if there was no response from the server.
*/
public synchronized boolean createOrJoin(String nickname, String password, DiscussionHistory history, long timeout)
throws NoResponseException, XMPPErrorException, SmackException {
if (joined) {
throw new IllegalStateException("Creation failed - User already joined the room.");
}
Presence presence = enter(nickname, password, history, timeout);
// Look for confirmation of room creation from the server
MUCUser mucUser = MUCUser.from(presence);
if (mucUser != null && mucUser.getStatus().contains(Status.ROOM_CREATED_201)) {
// Room was created and the user has joined the room
return true;
}
return false;
}
开发者ID:TTalkIM,项目名称:Smack,代码行数:32,代码来源:MultiUserChat.java
示例2: parseInvite
import org.jivesoftware.smackx.muc.packet.MUCUser; //导入依赖的package包/类
private static MUCUser.Invite parseInvite(XmlPullParser parser) throws XmlPullParserException, IOException {
boolean done = false;
MUCUser.Invite invite = new MUCUser.Invite();
invite.setFrom(parser.getAttributeValue("", "from"));
invite.setTo(parser.getAttributeValue("", "to"));
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("reason")) {
invite.setReason(parser.nextText());
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("invite")) {
done = true;
}
}
}
return invite;
}
开发者ID:TTalkIM,项目名称:Smack,代码行数:21,代码来源:MUCUserProvider.java
示例3: parseDecline
import org.jivesoftware.smackx.muc.packet.MUCUser; //导入依赖的package包/类
private static MUCUser.Decline parseDecline(XmlPullParser parser) throws XmlPullParserException, IOException {
boolean done = false;
MUCUser.Decline decline = new MUCUser.Decline();
decline.setFrom(parser.getAttributeValue("", "from"));
decline.setTo(parser.getAttributeValue("", "to"));
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("reason")) {
decline.setReason(parser.nextText());
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("decline")) {
done = true;
}
}
}
return decline;
}
开发者ID:TTalkIM,项目名称:Smack,代码行数:21,代码来源:MUCUserProvider.java
示例4: MultiUserChatManager
import org.jivesoftware.smackx.muc.packet.MUCUser; //导入依赖的package包/类
private MultiUserChatManager(XMPPConnection connection) {
super(connection);
// Listens for all messages that include a MUCUser extension and fire the invitation
// listeners if the message includes an invitation.
StanzaListener invitationPacketListener = new StanzaListener() {
public void processPacket(Stanza packet) {
final Message message = (Message) packet;
// Get the MUCUser extension
final MUCUser mucUser = MUCUser.from(message);
// Check if the MUCUser extension includes an invitation
if (mucUser.getInvite() != null) {
// Fire event for invitation listeners
final MultiUserChat muc = getMultiUserChat(packet.getFrom());
for (final InvitationListener listener : invitationsListeners) {
listener.invitationReceived(connection(), muc, mucUser.getInvite().getFrom(),
mucUser.getInvite().getReason(), mucUser.getPassword(), message);
}
}
}
};
connection.addAsyncStanzaListener(invitationPacketListener, INVITATION_FILTER);
}
开发者ID:TTalkIM,项目名称:Smack,代码行数:23,代码来源:MultiUserChatManager.java
示例5: Occupant
import org.jivesoftware.smackx.muc.packet.MUCUser; //导入依赖的package包/类
Occupant(Presence presence) {
MUCUser mucUser = (MUCUser) presence.getExtension("x",
"http://jabber.org/protocol/muc#user");
MUCItem item = mucUser.getItem();
this.jid = item.getJid();
this.affiliation = item.getAffiliation();
this.role = item.getRole();
// Get the nickname from the FROM attribute of the presence
this.nick = XmppStringUtils.parseResource(presence.getFrom());
}
开发者ID:TTalkIM,项目名称:Smack,代码行数:11,代码来源:Occupant.java
示例6: parse
import org.jivesoftware.smackx.muc.packet.MUCUser; //导入依赖的package包/类
/**
* Parses a MUCUser stanza(/packet) (extension sub-packet).
*
* @param parser the XML parser, positioned at the starting element of the extension.
* @return a PacketExtension.
* @throws IOException
* @throws XmlPullParserException
*/
@Override
public MUCUser parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
MUCUser mucUser = new MUCUser();
outerloop: while (true) {
switch (parser.next()) {
case XmlPullParser.START_TAG:
switch (parser.getName()) {
case "invite":
mucUser.setInvite(parseInvite(parser));
break;
case "item":
mucUser.setItem(MUCParserUtils.parseItem(parser));
break;
case "password":
mucUser.setPassword(parser.nextText());
break;
case "status":
String statusString = parser.getAttributeValue("", "code");
mucUser.addStatusCode(MUCUser.Status.create(statusString));
break;
case "decline":
mucUser.setDecline(parseDecline(parser));
break;
case "destroy":
mucUser.setDestroy(MUCParserUtils.parseDestroy(parser));
break;
}
break;
case XmlPullParser.END_TAG:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
}
}
return mucUser;
}
开发者ID:TTalkIM,项目名称:Smack,代码行数:47,代码来源:MUCUserProvider.java
示例7: handlePacket
import org.jivesoftware.smackx.muc.packet.MUCUser; //导入依赖的package包/类
private void handlePacket(Stanza packet) {
if (packet instanceof Message) {
Message msg = (Message)packet;
// Check to see if the user left the queue.
ExtensionElement pe = msg.getExtension("depart-queue", "http://jabber.org/protocol/workgroup");
ExtensionElement queueStatus = msg.getExtension("queue-status", "http://jabber.org/protocol/workgroup");
if (pe != null) {
fireQueueDepartedEvent();
}
else if (queueStatus != null) {
QueueUpdate queueUpdate = (QueueUpdate)queueStatus;
if (queueUpdate.getPosition() != -1) {
fireQueuePositionEvent(queueUpdate.getPosition());
}
if (queueUpdate.getRemaingTime() != -1) {
fireQueueTimeEvent(queueUpdate.getRemaingTime());
}
}
else {
// Check if a room invitation was sent and if the sender is the workgroup
MUCUser mucUser = (MUCUser)msg.getExtension("x", "http://jabber.org/protocol/muc#user");
MUCUser.Invite invite = mucUser != null ? mucUser.getInvite() : null;
if (invite != null && workgroupJID.equals(invite.getFrom())) {
String sessionID = null;
Map<String, List<String>> metaData = null;
pe = msg.getExtension(SessionID.ELEMENT_NAME,
SessionID.NAMESPACE);
if (pe != null) {
sessionID = ((SessionID)pe).getSessionID();
}
pe = msg.getExtension(MetaData.ELEMENT_NAME,
MetaData.NAMESPACE);
if (pe != null) {
metaData = ((MetaData)pe).getMetaData();
}
WorkgroupInvitation inv = new WorkgroupInvitation(connection.getUser(), msg.getFrom(),
workgroupJID, sessionID, msg.getBody(),
msg.getFrom(), metaData);
fireInvitationEvent(inv);
}
}
}
}
开发者ID:TTalkIM,项目名称:Smack,代码行数:50,代码来源:Workgroup.java
示例8: enter
import org.jivesoftware.smackx.muc.packet.MUCUser; //导入依赖的package包/类
/**
* Enter a room, as described in XEP-45 7.2.
*
* @param nickname
* @param password
* @param history
* @param timeout
* @return the returned presence by the service after the client send the initial presence in order to enter the room.
* @throws NotConnectedException
* @throws NoResponseException
* @throws XMPPErrorException
* @see <a href="http://xmpp.org/extensions/xep-0045.html#enter">XEP-45 7.2 Entering a Room</a>
*/
private Presence enter(String nickname, String password, DiscussionHistory history,
long timeout) throws NotConnectedException, NoResponseException,
XMPPErrorException {
StringUtils.requireNotNullOrEmpty(nickname, "Nickname must not be null or blank.");
// We enter a room by sending a presence packet where the "to"
// field is in the form "[email protected]/nickname"
Presence joinPresence = new Presence(Presence.Type.available);
joinPresence.setTo(room + "/" + nickname);
// Indicate the the client supports MUC
MUCInitialPresence mucInitialPresence = new MUCInitialPresence();
if (password != null) {
mucInitialPresence.setPassword(password);
}
if (history != null) {
mucInitialPresence.setHistory(history.getMUCHistory());
}
joinPresence.addExtension(mucInitialPresence);
// Wait for a presence packet back from the server.
StanzaFilter responseFilter = new AndFilter(FromMatchesFilter.createFull(room + "/"
+ nickname), new StanzaTypeFilter(Presence.class));
// Setup the messageListeners and presenceListeners *before* the join presence is send.
connection.addSyncStanzaListener(messageListener, fromRoomGroupchatFilter);
connection.addSyncStanzaListener(presenceListener, new AndFilter(fromRoomFilter,
StanzaTypeFilter.PRESENCE));
connection.addSyncStanzaListener(subjectListener, new AndFilter(fromRoomFilter,
MessageWithSubjectFilter.INSTANCE));
connection.addSyncStanzaListener(declinesListener, new AndFilter(new StanzaExtensionFilter(MUCUser.ELEMENT,
MUCUser.NAMESPACE), new NotFilter(MessageTypeFilter.ERROR)));
connection.addPacketInterceptor(presenceInterceptor, new AndFilter(new ToFilter(room),
StanzaTypeFilter.PRESENCE));
messageCollector = connection.createPacketCollector(fromRoomGroupchatFilter);
Presence presence;
try {
presence = connection.createPacketCollectorAndSend(responseFilter, joinPresence).nextResultOrThrow(timeout);
}
catch (NoResponseException | XMPPErrorException e) {
// Ensure that all callbacks are removed if there is an exception
removeConnectionCallbacks();
throw e;
}
this.nickname = nickname;
joined = true;
// Update the list of joined rooms
multiUserChatManager.addJoinedRoom(room);
return presence;
}
开发者ID:TTalkIM,项目名称:Smack,代码行数:66,代码来源:MultiUserChat.java
注:本文中的org.jivesoftware.smackx.muc.packet.MUCUser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论