本文整理汇总了Java中org.jivesoftware.smackx.muc.MultiUserChat.sendMessage方法的典型用法代码示例。如果您正苦于以下问题:Java MultiUserChat.sendMessage方法的具体用法?Java MultiUserChat.sendMessage怎么用?Java MultiUserChat.sendMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jivesoftware.smackx.muc.MultiUserChat
的用法示例。
在下文中一共展示了MultiUserChat.sendMessage方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMessage
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
public void sendMessage(String body, String chatJid, long timestamp) throws SmackException {
Random random = new Random(timestamp + body.length() + chatJid.length());
Log.d(TAG, "Sending message to : " + chatJid);
MultiUserChat chat = MultiUserChatManager.getInstanceFor(groupChatConnection)
.getMultiUserChat(chatJid);
chat.addMessageListener(this);
Message message = new Message();
QuickbloxChatExtension extension = new QuickbloxChatExtension();
extension.setProperty("date_sent", timestamp + "");
message.setStanzaId(StanzaIdUtil.newStanzaId());
message.setBody(body);
message.addExtension(extension);
message.setType(Message.Type.chat);
chat.sendMessage(message);
}
示例2: sendPublicMessage
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
public void sendPublicMessage(String body, String chatJid, long timestamp, String stanzaId) {
Log.d(TAG, "Sending message to : " + chatJid);
MultiUserChat mucChat = publicChats.get(chatJid);
QuickbloxChatExtension extension = new QuickbloxChatExtension();
extension.setProperty("date_sent", timestamp + "");
extension.setProperty("save_to_history", "1");
Message message = new Message(chatJid);
message.setStanzaId(stanzaId);
message.setBody(body);
message.setType(Message.Type.groupchat);
message.addExtension(extension);
try {
if (mucChat != null) {
mucChat.sendMessage(message);
}
} catch (SmackException.NotConnectedException ex) {
offlineMessages.add(message);
}
}
示例3: sendMessage
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
long sendMessage(TextMessage textMessage) throws Exception {
MultiUserChat muc = multichats.get(textMessage.getContactUid());
if (muc != null) {
Message m = muc.createMessage();
m.setBody(textMessage.getText());
muc.sendMessage(m);
return m.getPacketID().hashCode();
}
Chat chat = chats.get(textMessage.getContactUid());
if (chat == null) {
chat = getInternalService().getConnection().getChatManager().createChat(textMessage.getContactUid(), this);
chats.put(textMessage.getContactUid(), chat);
}
Message packet = getInternalService().getService().getEntityAdapter().textMessage2XMPPMessage(textMessage, chat.getThreadID(), chat.getParticipant(), Message.Type.chat);
chat.sendMessage(packet);
return packet.getPacketID().hashCode();
}
示例4: 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();
}
}
示例5: 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);
}
}
}
示例6: sendMessage
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
/**
* Send a message to a multi user chat
*
* @param chat the MultiUserChat to send the message to
* @param message the message to send
*/
private void sendMessage(MultiUserChat chat, String message) {
try {
chat.sendMessage(message);
} catch (XMPPException | SmackException.NotConnectedException ex) {
logger.error("Error sending message to room {}", chat.getNickname(), ex);
}
}
示例7: postDefaultMessage
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
private void postDefaultMessage(MultiUserChat chat, FirehoseMessage firehoseMessage) {
Message msg = chat.createMessage();
msg.setBody(MessageFormat.format("<{0}>: {1}", firehoseMessage.user, firehoseMessage.content));
XHTMLText xhtml = new XHTMLText(null, null);
xhtml.appendOpenSpanTag("color: #" + MiscUtils.toRGB(firehoseMessage.user));
xhtml.append(firehoseMessage.user);
xhtml.appendCloseSpanTag();
// xhtml.appendOpenStrongTag();
// xhtml.append(firehoseMessage.user);
// xhtml.appendCloseStrongTag();
xhtml.append(": ");
XMPPUtils.toXMPPXHTML(firehoseMessage.content, xhtml);
XHTMLManager.addBody(msg, xhtml.toString());
try {
chat.sendMessage(msg);
} catch (XMPPException e) {
logger.error(MessageFormat.format("Error publishing XHTML-enabled message to chatroom {0}. Message: {1}. Original message: {2}",
chat.getRoom(),
e.getMessage(),
firehoseMessage.toLogString()
));
try {
logger.info(
MessageFormat.format(
"Attempting to send plain XMPP message to chatroom {0}: {1}",
chat.getRoom(),
firehoseMessage.toLogString()
)
);
chat.sendMessage(firehoseMessage.user + ": " + firehoseMessage.content);
} catch (XMPPException e1) {
logger.error(
MessageFormat.format(
"Error publishing plain message to chatroom {0}. Message: {1}. Original message: {2}",
chat.getRoom(),
e1.getMessage(),
firehoseMessage.toLogString()
)
);
}
}
}
示例8: 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);
}
}
}
示例9: 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());
}
}
}
}
}
示例10: testSimpleUsingSmack
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
@Test
public void testSimpleUsingSmack() throws Exception {
try (KixmppServer server = new KixmppServer(new InetSocketAddress(SocketUtils.findAvailableTcpPort()), "testChat",
new InetSocketAddress(SocketUtils.findAvailableTcpPort()), new ConstNodeDiscovery())) {
Assert.assertNotNull(server.start().get(2, TimeUnit.SECONDS));
((InMemoryAuthenticationService) server.module(
SaslKixmppServerModule.class).getAuthenticationService())
.addUser("testUser", "testPassword");
server.module(MucKixmppServerModule.class).addService("conference")
.addRoom("someRoom");
XMPPConnection connection = new XMPPTCPConnection(
new ConnectionConfiguration("localhost", server
.getBindAddress().getPort(), server.getDomain()));
try {
connection.connect();
connection.login("testUser", "testPassword");
final LinkedBlockingQueue<Message> messages = new LinkedBlockingQueue<>();
PacketListener messageListener = new PacketListener() {
public void processPacket(Packet packet)
throws NotConnectedException {
messages.offer((Message) packet);
}
};
MultiUserChat chat = new MultiUserChat(connection,
"[email protected]");
chat.addMessageListener(messageListener);
chat.join("testNick");
chat.sendMessage("hello!");
Message message = messages.poll(2, TimeUnit.SECONDS);
Assert.assertNotNull(message);
if (null == message.getBody()
|| "".equals(message.getBody().trim())) {
message = messages.poll(2, TimeUnit.SECONDS);
Assert.assertNotNull(message);
Assert.assertEquals("hello!", message.getBody());
}
} finally {
connection.disconnect();
}
}
}
示例11: sendGroupChatMessage
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
private void sendGroupChatMessage(Connection conn, String dest, String username, String report,
BuildHealthNotifierTracker tracker) throws XMPPException {
MultiUserChat chat = new MultiUserChat(conn, dest);
chat.join(username);
chat.sendMessage(report);
chat.leave();
tracker.reportNotified("Sent XMPP notification to #" + dest);
}