use of org.jivesoftware.smack.MessageListener in project Smack by igniterealtime.
the class MultiUserChatIntegrationTest method mucTest.
@SmackIntegrationTest
public void mucTest() throws Exception {
EntityBareJid mucAddress = getRandomRoom("smack-inttest-message");
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
final String mucMessage = "Smack Integration Test MUC Test Message " + randomString;
final ResultSyncPoint<String, Exception> resultSyncPoint = new ResultSyncPoint<>();
mucAsSeenByTwo.addMessageListener(new MessageListener() {
@Override
public void processMessage(Message message) {
String body = message.getBody();
if (mucMessage.equals(body)) {
resultSyncPoint.signal(body);
}
}
});
createMuc(mucAsSeenByOne, "one-" + randomString);
mucAsSeenByTwo.join(Resourcepart.from("two-" + randomString));
mucAsSeenByOne.sendMessage(mucMessage);
try {
resultSyncPoint.waitForResult(timeout);
} catch (TimeoutException e) {
throw new AssertionError("Failed to receive presence", e);
} finally {
tryDestroy(mucAsSeenByOne);
}
}
use of org.jivesoftware.smack.MessageListener in project ecf by eclipse.
the class ECFConnection method sendMessage.
protected void sendMessage(ID receiver, Message aMsg) throws IOException {
synchronized (this) {
if (!isConnected())
throw new IOException("not connected");
try {
if (receiver == null)
throw new IOException("receiver cannot be null for xmpp instant messaging");
else if (receiver instanceof XMPPID) {
final XMPPID rcvr = (XMPPID) receiver;
aMsg.setType(Message.Type.chat);
final String receiverName = rcvr.getFQName();
final Chat localChat = connection.getChatManager().createChat(receiverName, new MessageListener() {
public void processMessage(Chat chat, Message message) {
}
});
localChat.sendMessage(aMsg);
} else if (receiver instanceof XMPPRoomID) {
final XMPPRoomID roomID = (XMPPRoomID) receiver;
aMsg.setType(Message.Type.groupchat);
final String to = roomID.getMucString();
aMsg.setTo(to);
connection.sendPacket(aMsg);
} else
throw new IOException("receiver must be of type XMPPID or XMPPRoomID");
} catch (final XMPPException e) {
final IOException result = new IOException("XMPPException in sendMessage: " + e.getMessage());
result.setStackTrace(e.getStackTrace());
throw result;
}
}
}
Aggregations