use of org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException in project Smack by igniterealtime.
the class MultiUserChatManager method getHostedRooms.
/**
* Returns a List of HostedRooms where each HostedRoom has the XMPP address of the room and the room's name.
* Once discovered the rooms hosted by a chat service it is possible to discover more detailed room information or
* join the room.
*
* @param serviceName the service that is hosting the rooms to discover.
* @return a collection of HostedRooms.
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
* @throws NotAMucServiceException
*/
public List<HostedRoom> getHostedRooms(DomainBareJid serviceName) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotAMucServiceException {
if (!providesMucService(serviceName)) {
throw new NotAMucServiceException(serviceName);
}
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection());
DiscoverItems discoverItems = discoManager.discoverItems(serviceName);
List<DiscoverItems.Item> items = discoverItems.getItems();
List<HostedRoom> answer = new ArrayList<HostedRoom>(items.size());
for (DiscoverItems.Item item : items) {
answer.add(new HostedRoom(item));
}
return answer;
}
use of org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException in project Smack by igniterealtime.
the class MucBookmarkAutojoinManager method autojoinBookmarkedConferences.
public void autojoinBookmarkedConferences() {
List<BookmarkedConference> bookmarkedConferences;
try {
bookmarkedConferences = bookmarkManager.getBookmarkedConferences();
} catch (NotConnectedException | InterruptedException e) {
LOGGER.log(Level.FINER, "Could not get MUC bookmarks", e);
return;
} catch (NoResponseException | XMPPErrorException e) {
LOGGER.log(Level.WARNING, "Could not get MUC bookmarks", e);
return;
}
final XMPPConnection connection = connection();
Resourcepart defaultNick = connection.getUser().getResourcepart();
for (BookmarkedConference bookmarkedConference : bookmarkedConferences) {
if (!bookmarkedConference.isAutoJoin()) {
continue;
}
Resourcepart nick = bookmarkedConference.getNickname();
if (nick == null) {
nick = defaultNick;
}
String password = bookmarkedConference.getPassword();
MultiUserChat muc = multiUserChatManager.getMultiUserChat(bookmarkedConference.getJid());
try {
MucCreateConfigFormHandle handle = muc.createOrJoinIfNecessary(nick, password);
if (handle != null) {
handle.makeInstant();
}
} catch (NotConnectedException | InterruptedException e) {
LOGGER.log(Level.FINER, "Could not autojoin bookmarked MUC", e);
// abort here
break;
} catch (NotAMucServiceException | NoResponseException | XMPPErrorException e) {
// Do no abort, just log,
LOGGER.log(Level.WARNING, "Could not autojoin bookmarked MUC", e);
}
}
}
use of org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException in project Smack by igniterealtime.
the class MultiUserChat method enter.
/**
* Enter a room, as described in XEP-45 7.2.
*
* @param conf the configuration used to enter the room.
* @return the returned presence by the service after the client send the initial presence in order to enter the room.
* @throws NotConnectedException
* @throws NoResponseException
* @throws XMPPErrorException
* @throws InterruptedException
* @throws NotAMucServiceException
* @see <a href="http://xmpp.org/extensions/xep-0045.html#enter">XEP-45 7.2 Entering a Room</a>
*/
private Presence enter(MucEnterConfiguration conf) throws NotConnectedException, NoResponseException, XMPPErrorException, InterruptedException, NotAMucServiceException {
final DomainBareJid mucService = room.asDomainBareJid();
if (!KNOWN_MUC_SERVICES.containsKey(mucService)) {
if (multiUserChatManager.providesMucService(mucService)) {
KNOWN_MUC_SERVICES.put(mucService, null);
} else {
throw new NotAMucServiceException(this);
}
}
// We enter a room by sending a presence packet where the "to"
// field is in the form "roomName@service/nickname"
Presence joinPresence = conf.getJoinPresence(this);
// Setup the messageListeners and presenceListeners *before* the join presence is send.
connection.addSyncStanzaListener(messageListener, fromRoomGroupchatFilter);
connection.addSyncStanzaListener(presenceListener, new AndFilter(fromRoomFilter, StanzaTypeFilter.PRESENCE));
connection.addSyncStanzaListener(subjectListener, new AndFilter(fromRoomFilter, MessageWithSubjectFilter.INSTANCE, new NotFilter(MessageTypeFilter.ERROR)));
connection.addSyncStanzaListener(declinesListener, DECLINE_FILTER);
connection.addPacketInterceptor(presenceInterceptor, new AndFilter(ToMatchesFilter.create(room), StanzaTypeFilter.PRESENCE));
messageCollector = connection.createStanzaCollector(fromRoomGroupchatFilter);
// Wait for a presence packet back from the server.
// @formatter:off
StanzaFilter responseFilter = new AndFilter(StanzaTypeFilter.PRESENCE, new OrFilter(// We use a bare JID filter for positive responses, since the MUC service/room may rewrite the nickname.
new AndFilter(FromMatchesFilter.createBare(getRoom()), MUCUserStatusCodeFilter.STATUS_110_PRESENCE_TO_SELF), // JID we send the join presence to.
new AndFilter(FromMatchesFilter.createFull(joinPresence.getTo()), new StanzaIdFilter(joinPresence), PresenceTypeFilter.ERROR)));
// @formatter:on
Presence presence;
try {
presence = connection.createStanzaCollectorAndSend(responseFilter, joinPresence).nextResultOrThrow(conf.getTimeout());
} catch (NotConnectedException | InterruptedException | NoResponseException | XMPPErrorException e) {
// Ensure that all callbacks are removed if there is an exception
removeConnectionCallbacks();
throw e;
}
// This presence must be send from a full JID. We use the resourcepart of this JID as nick, since the room may
// performed roomnick rewriting
this.nickname = presence.getFrom().asEntityFullJidIfPossible().getResourcepart();
joined = true;
// Update the list of joined rooms
multiUserChatManager.addJoinedRoom(room);
return presence;
}
Aggregations