本文整理汇总了Java中org.jivesoftware.smackx.muc.MultiUserChat.getRoom方法的典型用法代码示例。如果您正苦于以下问题:Java MultiUserChat.getRoom方法的具体用法?Java MultiUserChat.getRoom怎么用?Java MultiUserChat.getRoom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jivesoftware.smackx.muc.MultiUserChat
的用法示例。
在下文中一共展示了MultiUserChat.getRoom方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendRoomInvite
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
/**
* Send invites to clients for joining multi user chat room
*
* @param muc
* @param userList
* @param inviteMessage
*/
public void sendRoomInvite(MultiUserChat muc, ArrayList<String> userList, String inviteMessage) {
if (muc != null && muc.getRoom() != null && !muc.getRoom().isEmpty()) {
if (userList != null && !userList.isEmpty()) {
for (String user : userList) {
try {
muc.invite(user, inviteMessage);
} catch (NotConnectedException e) {
e.printStackTrace();
}
}
logger.info(userList.size() + " clients were invited to room(" + muc.getRoom() + ")");
}
} else {
logger.info("There is no available room for invitation");
}
}
示例2: sendProjChromMsg
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
/**
* 发送信息到云同步室
*
* @param room 云同步室
* @param msg 将要发送的信息
*/
public void sendProjChromMsg(MultiUserChat room, Object msg) {
if (!room.isJoined())
return;
try {
Message message = new Message(room.getRoom(), Message.Type.groupchat);
message.setBody(SysUtil.getInstance().getDateAndTimeFormated());
message.setProperty(MSGCLOUD, msg);
room.sendMessage(message);
} catch (XMPPException e) {
e.printStackTrace();
}
}
示例3: write
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
/**
* Updates the web transcript and sends the message.
* @param message the message to send.
*/
public void write(String message) {
// If the user doesn't have a chat session, notify them.
if (chatSession == null) {
return;
}
// Notify user if the chat session has closed.
if (chatSession.isClosed() || !chatSession.isInGroupChat()) {
return;
}
// If the message isn't specified, do nothing.
if (message != null) {
try {
final MultiUserChat chat = chatSession.getGroupChat();
message = message.replaceAll("\r", " ");
// update the transcript:
String body = WebUtils.applyFilters(message);
String nickname = chat.getNickname();
chatSession.updateTranscript(nickname, body);
if (chat != null) {
final Message chatMessage = new Message();
chatMessage.setType(Message.Type.groupchat);
chatMessage.setBody(message);
String room = chat.getRoom();
chatMessage.setTo(room);
chat.sendMessage(chatMessage);
}
}
catch (XMPPException e) {
WebLog.logError("Error sending message:", e);
}
}
}
示例4: joinRoom
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
/**
* Joins the specified room and removes from queue.
*
* @param roomName the name of the room to join.
*/
public void joinRoom(String roomName) {
// Set the last check now
lastCheck = System.currentTimeMillis();
try {
groupChat = new MultiUserChat(connection, roomName);
if (name != null) {
try {
AndFilter presenceFilter = new AndFilter(new PacketTypeFilter(Presence.class), new FromContainsFilter(groupChat.getRoom()));
connection.addPacketListener(this, presenceFilter);
groupChat.join(name);
}
// Catch any join exceptions and attempt to join again
// using an altered name (since exception is most likely
// due to a conflict of names).
catch (XMPPException xe) {
String conflictName = name + " (Visitor)";
groupChat.join(conflictName);
nickname = conflictName;
}
}
else {
nickname = "Visitor";
groupChat.join(nickname);
}
groupChat.addParticipantListener(new PacketListener() {
public void processPacket(Packet packet) {
final Presence p = (Presence)packet;
final String from = p.getFrom();
String user = StringUtils.parseResource(from);
if (p.getType() != Presence.Type.available) {
lastAgent = user;
}
final Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
checkForEmptyRoom();
}
}, 5000);
}
});
messageEventManager = new MessageEventManager(connection);
messageEventManager.addMessageEventNotificationListener(this);
}
catch (Exception e) {
WebLog.logError("Error joining room:", e);
}
this.roomName = roomName;
listenForMessages(connection, groupChat);
}
示例5: sendMessage
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
/**
* Sends a message from a given <code>ChatSession</code> that is associated with
* a given chat id.
*
* @param chatID the chat id.
* @param message the message to send.
*/
public static void sendMessage(String chatID, String message) {
ChatSession chatSession = getChatSession(chatID);
// If the user doesn't have a chat session, notify them.
if (chatSession == null) {
return;
}
// Notify user if the chat session has closed.
if (chatSession.isClosed() || !chatSession.isInGroupChat()) {
return;
}
// If the message isn't specified, do nothing.
if (message != null) {
try {
final MultiUserChat chat = chatSession.getGroupChat();
message = message.replaceAll("\r", " ");
// Handle odd case of double spacing
if (message.endsWith("\n")) {
message = message.substring(0, message.length() - 1);
}
// update the transcript:
String body = WebUtils.applyFilters(message);
String nickname = chat.getNickname();
chatSession.updateTranscript(nickname, body);
if (chat != null) {
final Message chatMessage = new Message();
chatMessage.setType(Message.Type.groupchat);
chatMessage.setBody(message);
String room = chat.getRoom();
chatMessage.setTo(room);
chat.sendMessage(chatMessage);
}
}
catch (XMPPException e) {
WebLog.logError("Error sending message:", e);
}
}
}
示例6: removeStaleChats
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
private void removeStaleChats() {
final Iterator<ChatSession> chatSessions = new ArrayList<ChatSession>(getChatSessions()).iterator();
final long now = System.currentTimeMillis();
while (chatSessions.hasNext()) {
final ChatSession chatSession = chatSessions.next();
final long lastCheck = chatSession.getLastCheck();
if (chatSession.isClosed()) {
if (lastCheck < now - MAXIMUM_STALE_SESSION_LENGTH_IN_MS) {
removeChatSession(chatSession.getSessionID());
}
} else {
if (lastCheck != 0) {
// If the last time the user check for new messages is greater than timeOut,
// then we can assume the user has closed to window and has not explicitly closed the connection.
if (now - lastCheck > MAXIMUM_INACTIVE_TIME_IN_MS) {
// Close Chat Session
chatSession.close();
// Remove from cache
removeChatSession(chatSession.getSessionID());
}
// Warn the users that the browser client appears to be unresponsive
else if (!chatSession.isInactivityWarningSent() && now - lastCheck > INACTIVE_TIME_WARNING_IN_MS) {
final MultiUserChat chat = chatSession.getGroupChat();
if (chat != null) {
final String inactivityInMs = Long.toString(now - lastCheck);
final String inactivityInSecs = inactivityInMs.substring(0, inactivityInMs.length()-3);
try {
final Message chatMessage = new Message();
chatMessage.setType(Message.Type.groupchat);
chatMessage.setBody("The webchat client connection appears to unstable. No data has been received in the last " + inactivityInSecs + " seconds.");
String room = chat.getRoom();
chatMessage.setTo(room);
chat.sendMessage(chatMessage);
chatSession.setInactivityWarningSent(true);
} catch (XMPPException e) {
WebLog.logError("Error sending message:", e);
}
}
}
} else {
// Handle case where the user never joins a conversation and leaves the queue.
if (!chatSession.isInQueue() && (now - chatSession.getCreatedTimestamp() > MAXIMUM_INACTIVE_TIME_IN_MS)) {
chatSession.close();
// Remove from cache
removeChatSession(chatSession.getSessionID());
}
}
}
}
}