本文整理汇总了Java中org.jivesoftware.smackx.packet.MUCUser类的典型用法代码示例。如果您正苦于以下问题:Java MUCUser类的具体用法?Java MUCUser怎么用?Java MUCUser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MUCUser类属于org.jivesoftware.smackx.packet包,在下文中一共展示了MUCUser类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.jivesoftware.smackx.packet.MUCUser; //导入依赖的package包/类
/**
* Initializes the listeners to detect received room invitations and to detect when the
* connection gets closed. As soon as a room invitation is received the invitations
* listeners will be fired. When the connection gets closed the monitor will remove
* his listeners on the connection.
*/
private void init() {
// Listens for all messages that include a MUCUser extension and fire the invitation
// listeners if the message includes an invitation.
invitationFilter =
new PacketExtensionFilter("x", "http://jabber.org/protocol/muc#user");
invitationPacketListener = new PacketListener() {
public void processPacket(Packet packet) {
// Get the MUCUser extension
MUCUser mucUser =
(MUCUser) packet.getExtension("x", "http://jabber.org/protocol/muc#user");
// Check if the MUCUser extension includes an invitation
if (mucUser.getInvite() != null &&
((Message) packet).getType() != Message.Type.error) {
// Fire event for invitation listeners
fireInvitationListeners(packet.getFrom(), mucUser.getInvite().getFrom(),
mucUser.getInvite().getReason(), mucUser.getPassword(), (Message) packet);
}
}
};
connection.addPacketListener(invitationPacketListener, invitationFilter);
// Add a listener to detect when the connection gets closed in order to
// cancel/release this monitor
connection.addConnectionListener(this);
}
示例2: Occupant
import org.jivesoftware.smackx.packet.MUCUser; //导入依赖的package包/类
Occupant(Presence presence) {
super();
MUCUser mucUser = (MUCUser) presence.getExtension("x",
"http://jabber.org/protocol/muc#user");
MUCUser.Item 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 = StringUtils.parseResource(presence.getFrom());
}
示例3: getMUCUserExtension
import org.jivesoftware.smackx.packet.MUCUser; //导入依赖的package包/类
/**
* Returns the MUCUser packet extension included in the packet or <tt>null</tt> if none.
*
* @param packet the packet that may include the MUCUser extension.
* @return the MUCUser found in the packet.
*/
private MUCUser getMUCUserExtension(Packet packet) {
if (packet != null) {
// Get the MUC User extension
return (MUCUser) packet.getExtension("x", "http://jabber.org/protocol/muc#user");
}
return null;
}
示例4: Occupant
import org.jivesoftware.smackx.packet.MUCUser; //导入依赖的package包/类
Occupant(Presence presence) {
super();
MUCUser mucUser = (MUCUser) presence.getExtension("x",
"http://jabber.org/protocol/muc#user");
MUCUser.Item 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 = StringUtils.parseResource(presence.getFrom());
}
示例5: getMUCUserExtension
import org.jivesoftware.smackx.packet.MUCUser; //导入依赖的package包/类
/**
* Returns the MUCUser packet extension included in the packet or
* <tt>null</tt> if none.
*
* @param packet
* the packet that may include the MUCUser extension.
* @return the MUCUser found in the packet.
*/
private MUCUser getMUCUserExtension(Packet packet) {
if (packet != null) {
// Get the MUC User extension
return (MUCUser) packet.getExtension("x",
"http://jabber.org/protocol/muc#user");
}
return null;
}
示例6: init
import org.jivesoftware.smackx.packet.MUCUser; //导入依赖的package包/类
/**
* Initializes the listeners to detect received room invitations and to
* detect when the connection gets closed. As soon as a room invitation
* is received the invitations listeners will be fired. When the
* connection gets closed the monitor will remove his listeners on the
* connection.
*/
private void init() {
// Listens for all messages that include a MUCUser extension and
// fire the invitation
// listeners if the message includes an invitation.
invitationFilter = new PacketExtensionFilter("x",
"http://jabber.org/protocol/muc#user");
invitationPacketListener = new PacketListener() {
public void processPacket(Packet packet) {
// Get the MUCUser extension
MUCUser mucUser = (MUCUser) packet.getExtension("x",
"http://jabber.org/protocol/muc#user");
// Check if the MUCUser extension includes an invitation
if (mucUser.getInvite() != null
&& ((Message) packet).getType() != Message.Type.error) {
// Fire event for invitation listeners
fireInvitationListeners(packet.getFrom(), mucUser
.getInvite().getFrom(), mucUser.getInvite()
.getReason(), mucUser.getPassword(),
(Message) packet);
}
}
};
connection.addPacketListener(invitationPacketListener,
invitationFilter);
// Add a listener to detect when the connection gets closed in order
// to
// cancel/release this monitor
connection.addConnectionListener(this);
}
示例7: getJidFromMUCPresence
import org.jivesoftware.smackx.packet.MUCUser; //导入依赖的package包/类
public static String getJidFromMUCPresence(Presence presence) {
Collection<PacketExtension> extensions = presence.getExtensions();
for (PacketExtension pe : extensions) {
if (pe instanceof MUCUser) {
final MUCUser mucUser = (MUCUser) pe;
String fullJid = mucUser.getItem().getJid();
String userJid = StringUtils.parseBareAddress(fullJid);
return userJid;
}
}
return null;
}
示例8: create
import org.jivesoftware.smackx.packet.MUCUser; //导入依赖的package包/类
/**
* Creates the room according to some default configuration, assign the requesting user
* as the room owner, and add the owner to the room but not allow anyone else to enter
* the room (effectively "locking" the room). The requesting user will join the room
* under the specified nickname as soon as the room has been created.<p>
*
* To create an "Instant Room", that means a room with some default configuration that is
* available for immediate access, the room's owner should send an empty form after creating
* the room. {@link #sendConfigurationForm(Form)}<p>
*
* To create a "Reserved Room", that means a room manually configured by the room creator
* before anyone is allowed to enter, the room's owner should complete and send a form after
* creating the room. Once the completed configutation form is sent to the server, the server
* will unlock the room. {@link #sendConfigurationForm(Form)}
*
* @param nickname the nickname to use.
* @throws XMPPException if the room couldn't be created for some reason
* (e.g. room already exists; user already joined to an existant room or
* 405 error if the user is not allowed to create the room)
*/
public synchronized void create(String nickname) throws XMPPException {
if (nickname == null || nickname.equals("")) {
throw new IllegalArgumentException("Nickname must not be null or blank.");
}
// If we've already joined the room, leave it before joining under a new
// nickname.
if (joined) {
throw new IllegalStateException("Creation failed - User already joined the room.");
}
// We create a room by sending a presence packet to [email protected]/nick
// and signal support for MUC. The owner will be automatically logged into the room.
Presence joinPresence = new Presence(Presence.Type.available);
joinPresence.setTo(room + "/" + nickname);
// Indicate the the client supports MUC
joinPresence.addExtension(new MUCInitialPresence());
// Invoke presence interceptors so that extra information can be dynamically added
for (PacketInterceptor packetInterceptor : presenceInterceptors) {
packetInterceptor.interceptPacket(joinPresence);
}
// Wait for a presence packet back from the server.
PacketFilter responseFilter =
new AndFilter(
new FromMatchesFilter(room + "/" + nickname),
new PacketTypeFilter(Presence.class));
PacketCollector response = connection.createPacketCollector(responseFilter);
// Send create & join packet.
connection.sendPacket(joinPresence);
// Wait up to a certain number of seconds for a reply.
Presence presence =
(Presence) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
response.cancel();
if (presence == null) {
throw new XMPPException("No response from server.");
}
else if (presence.getError() != null) {
throw new XMPPException(presence.getError());
}
// Whether the room existed before or was created, the user has joined the room
this.nickname = nickname;
joined = true;
userHasJoined();
// Look for confirmation of room creation from the server
MUCUser mucUser = getMUCUserExtension(presence);
if (mucUser != null && mucUser.getStatus() != null) {
if ("201".equals(mucUser.getStatus().getCode())) {
// Room was created and the user has joined the room
return;
}
}
// We need to leave the room since it seems that the room already existed
leave();
throw new XMPPException("Creation failed - Missing acknowledge of room creation.");
}
示例9: handlePacket
import org.jivesoftware.smackx.packet.MUCUser; //导入依赖的package包/类
private void handlePacket(Packet packet) {
if (packet instanceof Message) {
Message msg = (Message)packet;
// Check to see if the user left the queue.
PacketExtension pe = msg.getExtension("depart-queue", "http://jabber.org/protocol/workgroup");
PacketExtension 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 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);
}
}
}
}
示例10: handlePacket
import org.jivesoftware.smackx.packet.MUCUser; //导入依赖的package包/类
private void handlePacket(Packet packet) {
if (packet instanceof Message) {
Message msg = (Message)packet;
// Check to see if the user left the queue.
PacketExtension pe = msg.getExtension("depart-queue", "http://jabber.org/protocol/workgroup");
PacketExtension 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);
}
}
}
}
示例11: handlePacket
import org.jivesoftware.smackx.packet.MUCUser; //导入依赖的package包/类
private void handlePacket(Packet packet) {
if (packet instanceof Message) {
Message msg = (Message) packet;
// Check to see if the user left the queue.
PacketExtension pe = msg.getExtension("depart-queue",
"http://jabber.org/protocol/workgroup");
PacketExtension 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 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);
}
}
}
}
示例12: handlePresencePacket
import org.jivesoftware.smackx.packet.MUCUser; //导入依赖的package包/类
/**
* Handle all presence packets being sent to this Group Chat Room.
*
* @param packet
* the presence packet.
*/
private void handlePresencePacket(Packet packet) {
Presence presence = (Presence) packet;
if (presence.getError() != null) {
return;
}
final String from = presence.getFrom();
final String nickname = StringUtils.parseResource(from);
MUCUser mucUser = (MUCUser) packet.getExtension("x",
"http://jabber.org/protocol/muc#user");
String code = "";
if (mucUser != null) {
code = mucUser.getStatus() != null ? mucUser.getStatus().getCode()
: "";
Destroy destroy = mucUser.getDestroy();
if (destroy != null) {
String reason = destroy.getReason();
JOptionPane.showMessageDialog(this,
Res.getString("message.room.destroyed", reason),
Res.getString("title.room.destroyed"),
JOptionPane.INFORMATION_MESSAGE);
leaveChatRoom();
return;
}
}
if (presence.getType() == Presence.Type.unavailable
&& !"303".equals(code)) {
if (currentUserList.contains(from)) {
if (showPresenceMessages) {
getTranscriptWindow().insertNotificationMessage(
Res.getString("message.user.left.room", nickname),
ChatManager.NOTIFICATION_COLOR);
scrollToBottom();
}
currentUserList.remove(from);
}
} else {
if (!currentUserList.contains(from)) {
currentUserList.add(from);
getChatInputEditor().setEnabled(true);
if (showPresenceMessages) {
getTranscriptWindow()
.insertNotificationMessage(
Res.getString("message.user.joined.room",
nickname),
ChatManager.NOTIFICATION_COLOR);
scrollToBottom();
}
}
}
}