use of org.jivesoftware.smackx.muc.MultiUserChat in project camel by apache.
the class XmppConsumer method doStart.
@Override
protected void doStart() throws Exception {
try {
connection = endpoint.createConnection();
} catch (SmackException e) {
if (endpoint.isTestConnectionOnStartup()) {
throw new RuntimeException("Could not connect to XMPP server.", e);
} else {
LOG.warn(e.getMessage());
if (getExceptionHandler() != null) {
getExceptionHandler().handleException(e.getMessage(), e);
}
scheduleDelayedStart();
return;
}
}
chatManager = ChatManager.getInstanceFor(connection);
chatManager.addChatListener(this);
OrFilter pubsubPacketFilter = new OrFilter();
if (endpoint.isPubsub()) {
//xep-0060: pubsub#notification_type can be 'headline' or 'normal'
pubsubPacketFilter.addFilter(new MessageTypeFilter(Type.headline));
pubsubPacketFilter.addFilter(new MessageTypeFilter(Type.normal));
connection.addPacketListener(this, pubsubPacketFilter);
}
if (endpoint.getRoom() == null) {
privateChat = chatManager.getThreadChat(endpoint.getChatId());
if (privateChat != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Adding listener to existing chat opened to " + privateChat.getParticipant());
}
privateChat.addMessageListener(this);
} else {
privateChat = ChatManager.getInstanceFor(connection).createChat(endpoint.getParticipant(), endpoint.getChatId(), this);
if (LOG.isDebugEnabled()) {
LOG.debug("Opening private chat to " + privateChat.getParticipant());
}
}
} else {
// add the presence packet listener to the connection so we only get packets that concerns us
// we must add the listener before creating the muc
final AndFilter packetFilter = new AndFilter(new PacketTypeFilter(Presence.class));
connection.addPacketListener(this, packetFilter);
muc = new MultiUserChat(connection, endpoint.resolveRoom(connection));
muc.addMessageListener(this);
DiscussionHistory history = new DiscussionHistory();
// we do not want any historical messages
history.setMaxChars(0);
muc.join(endpoint.getNickname(), null, history, SmackConfiguration.getDefaultPacketReplyTimeout());
if (LOG.isInfoEnabled()) {
LOG.info("Joined room: {} as: {}", muc.getRoom(), endpoint.getNickname());
}
}
this.startRobustConnectionMonitor();
super.doStart();
}
use of org.jivesoftware.smackx.muc.MultiUserChat in project opennms by OpenNMS.
the class XMPPNotificationManager method sendGroupChat.
/**
* send an xmpp message to a specified Chat Room.
*
* @param xmppChatRoom
* room to send message to.
* @param xmppMessage
* text to be sent in the body of the message
* @return true if message is sent, false otherwise
*/
public boolean sendGroupChat(String xmppChatRoom, String xmppMessage) {
MultiUserChat groupChat;
if (rooms.containsKey(xmppChatRoom)) {
groupChat = rooms.get(xmppChatRoom);
} else {
LOG.debug("Adding room: {}", xmppChatRoom);
groupChat = new MultiUserChat(xmpp, xmppChatRoom);
rooms.put(xmppChatRoom, groupChat);
}
if (!groupChat.isJoined()) {
LOG.debug("Joining room: {}", xmppChatRoom);
try {
groupChat.join(xmppUser);
} catch (XMPPException | NoResponseException | NotConnectedException e) {
LOG.error("XMPP Exception joining chat room ", e);
return false;
}
}
try {
groupChat.sendMessage(xmppMessage);
LOG.debug("XMPP Manager sent message to: {}", xmppChatRoom);
} catch (XMPPException | NotConnectedException e) {
LOG.error("XMPP Exception sending message to Chat room", e);
return false;
}
return true;
}
use of org.jivesoftware.smackx.muc.MultiUserChat in project Spark by igniterealtime.
the class GroupChatRoomListener method chatRoomOpened.
@Override
public void chatRoomOpened(ChatRoom room) {
if (!(room instanceof GroupChatRoom)) {
return;
}
GroupChatRoom groupChatRoom = (GroupChatRoom) room;
MultiUserChat chat = groupChatRoom.getMultiUserChat();
chat.addUserStatusListener(new UserStatusListener() {
public void kicked(String actor, String reason) {
}
public void voiceGranted() {
}
public void voiceRevoked() {
}
public void banned(String actor, String reason) {
}
public void membershipGranted() {
}
public void membershipRevoked() {
}
public void moderatorGranted() {
}
public void moderatorRevoked() {
}
public void ownershipGranted() {
}
public void ownershipRevoked() {
}
public void adminGranted() {
}
public void adminRevoked() {
}
});
}
use of org.jivesoftware.smackx.muc.MultiUserChat in project Spark by igniterealtime.
the class ConferenceUtils method createPrivateConference.
/**
* Creates a private conference.
*
* @param serviceName the service name to use for the private conference.
* @param message the message sent to each individual invitee.
* @param roomName the name of the room to create.
* @param jids a collection of the user JIDs to invite.
* @throws SmackException thrown if an error occurs during room creation.
*/
public static void createPrivateConference(String serviceName, String message, String roomName, Collection<String> jids) throws SmackException {
final String roomJID = XmppStringUtils.escapeLocalpart(roomName) + "@" + serviceName;
final MultiUserChat multiUserChat = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getMultiUserChat(roomJID);
final LocalPreferences pref = SettingsManager.getLocalPreferences();
final GroupChatRoom room = UIComponentRegistry.createGroupChatRoom(multiUserChat);
try {
// Attempt to create room.
multiUserChat.create(pref.getNickname());
} catch (XMPPException | SmackException e) {
throw new SmackException(e);
}
try {
// Since this is a private room, make the room not public and set user as owner of the room.
Form submitForm = multiUserChat.getConfigurationForm().createAnswerForm();
submitForm.setAnswer("muc#roomconfig_publicroom", false);
submitForm.setAnswer("muc#roomconfig_roomname", roomName);
final List<String> owners = new ArrayList<>();
owners.add(SparkManager.getSessionManager().getBareAddress());
submitForm.setAnswer("muc#roomconfig_roomowners", owners);
multiUserChat.sendConfigurationForm(submitForm);
} catch (XMPPException | SmackException e1) {
Log.error("Unable to send conference room chat configuration form.", e1);
}
ChatManager chatManager = SparkManager.getChatManager();
// Check if room already is open
try {
chatManager.getChatContainer().getChatRoom(room.getRoomname());
} catch (ChatRoomNotFoundException e) {
chatManager.getChatContainer().addChatRoom(room);
chatManager.getChatContainer().activateChatRoom(room);
}
for (String jid : jids) {
multiUserChat.invite(jid, message);
room.getTranscriptWindow().insertNotificationMessage(Res.getString("message.waiting.for.user.to.join", jid), ChatManager.NOTIFICATION_COLOR);
}
}
use of org.jivesoftware.smackx.muc.MultiUserChat in project Spark by igniterealtime.
the class ChatManager method createConferenceRoom.
/**
* Creates a new public Conference Room.
*
* @param roomName the name of the room.
* @param serviceName the service name to use (ex.conference.jivesoftware.com)
* @return the new ChatRoom created. If an error occured, null will be returned.
*/
public ChatRoom createConferenceRoom(String roomName, String serviceName) {
final MultiUserChat chatRoom = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getMultiUserChat(roomName + "@" + serviceName);
final GroupChatRoom room = UIComponentRegistry.createGroupChatRoom(chatRoom);
try {
LocalPreferences pref = SettingsManager.getLocalPreferences();
chatRoom.create(pref.getNickname());
// Send an empty room configuration form which indicates that we want
// an instant room
chatRoom.sendConfigurationForm(new Form(DataForm.Type.submit));
} catch (XMPPException | SmackException e1) {
Log.error("Unable to send conference room chat configuration form.", e1);
return null;
}
getChatContainer().addChatRoom(room);
return room;
}
Aggregations