final ResultSyncPoint<String, Exception> resultSyncPoint = new ResultSyncPoint<>(); mucAsSeenByTwo.addMessageListener(new MessageListener() { @Override public void processMessage(Message message) { MucCreateConfigFormHandle handle = mucAsSeenByOne.createOrJoin(Resourcepart.from("one-" + randomString)); if (handle != null) { handle.makeInstant(); mucAsSeenByTwo.join(Resourcepart.from("two-" + randomString)); mucAsSeenByOne.sendMessage(mucMessage); resultSyncPoint.waitForResult(timeout); mucAsSeenByOne.leave(); mucAsSeenByTwo.leave();
private MultiUserChat createNewMucAndAddToMap(EntityBareJid jid) { MultiUserChat multiUserChat = new MultiUserChat(connection(), jid, this); multiUserChats.put(jid, new WeakReference<MultiUserChat>(multiUserChat)); return multiUserChat; }
/** * Returns a list of <code>Occupant</code> with the room participants. * * @return a list of <code>Occupant</code> with the room participants. * @throws XMPPErrorException if you don't have enough privileges to get this information. * @throws NoResponseException if there was no response from the server. * @throws NotConnectedException * @throws InterruptedException */ public List<Occupant> getParticipants() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return getOccupants(MUCRole.participant); }
/** * Get a MamManager for the MAM archive of the given {@code MultiUserChat}. Note that not all MUCs support MAM, * hence it is recommended to use {@link #isSupported()} to check if MAM is supported by the MUC. * * @param multiUserChat the MultiUserChat to retrieve the MamManager for. * @return the MamManager for the given MultiUserChat. * @since 4.3.0 */ public static MamManager getInstanceFor(MultiUserChat multiUserChat) { XMPPConnection connection = multiUserChat.getXmppConnection(); Jid archiveAddress = multiUserChat.getRoom(); return getInstanceFor(connection, archiveAddress); }
/** * Joins the chat room using the specified nickname. If already joined * using another nickname, this method will first leave the room and then * re-join using the new nickname. The default connection timeout for a reply * from the group chat server that the join succeeded will be used. After * joining the room, the room will decide the amount of history to send. * * @param nickname the nickname to use. * @throws NoResponseException * @throws XMPPErrorException if an error occurs joining the room. In particular, a * 401 error can occur if no password was provided and one is required; or a * 403 error can occur if the user is banned; or a * 404 error can occur if the room does not exist or is locked; or a * 407 error can occur if user is not on the member list; or a * 409 error can occur if someone is already in the group chat with the same nickname. * @throws NoResponseException if there was no response from the server. * @throws NotConnectedException * @throws InterruptedException * @throws NotAMucServiceException */ public void join(Resourcepart nickname) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotAMucServiceException { MucEnterConfiguration.Builder builder = getEnterConfigurationBuilder(nickname); join(builder.build()); }
/** * Create or join a MUC if it is necessary, i.e. if not the MUC is not already joined. * * @param nickname the required nickname to use. * @param password the optional password required to join * @return A {@link MucCreateConfigFormHandle} if the room was created while joining, or {@code null} if the room was just joined. * @throws NoResponseException * @throws XMPPErrorException * @throws NotConnectedException * @throws InterruptedException * @throws NotAMucServiceException */ public MucCreateConfigFormHandle createOrJoinIfNecessary(Resourcepart nickname, String password) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotAMucServiceException { if (isJoined()) { return null; } MucEnterConfiguration mucEnterConfiguration = getEnterConfigurationBuilder(nickname).withPassword( password).build(); try { return createOrJoin(mucEnterConfiguration); } catch (MucAlreadyJoinedException e) { return null; } }
public MultiUserChat joinChannelWithoutHashing(String name, String password) { MultiUserChat chat = new MultiUserChat(this, name); chatRooms.put(name, chat); try { chat.join(getUsername(), password); return chat; } catch (XMPPException.XMPPErrorException | SmackException e) { throw new IllegalStateException(e); } }
muc = new MultiUserChat(connection, room); muc.join(pseudo, "", history, 4000); muc.addMessageListener(this);
// Create a MultiUserChat using a XMPPConnection for a room MultiUserChat muc2 = new MultiUserChat(connection, "myFirstName@conference."+"Your HOST/Domain"); // User2 joins the new room // The room service will decide the amount of history to send muc2.join("testbot2");
} 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); groupChat.sendMessage(xmppMessage); LOG.debug("XMPP Manager sent message to: {}", xmppChatRoom); } catch (XMPPException | NotConnectedException e) {
userHasJoined(); MUCUser mucUser = getMUCUserExtension(presence); if (mucUser != null && mucUser.getStatus() != null) { if ("201".equals(mucUser.getStatus().getCode())) { leave(); throw new XMPPException("Creation failed - Missing acknowledge of room creation.");
@SmackIntegrationTest public void mucJoinLeaveTest() throws XmppStringprepException, NotAMucServiceException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, MucNotJoinedException { EntityBareJid mucAddress = JidCreate.entityBareFrom(Localpart.from("smack-inttest-join-leave-" + randomString), mucService.getDomain()); MultiUserChat muc = mucManagerOne.getMultiUserChat(mucAddress); muc.join(Resourcepart.from("nick-one")); Presence reflectedLeavePresence = muc.leave(); MUCUser mucUser = MUCUser.from(reflectedLeavePresence); assertNotNull(mucUser); assertTrue(mucUser.getStatus().contains(MUCUser.Status.PRESENCE_TO_SELF_110)); }
@SmackIntegrationTest public void testMucBookmarksAutojoin(XMPPTCPConnection connection) throws InterruptedException, TestNotPossibleException, XMPPException, SmackException, IOException { final BookmarkManager bookmarkManager = BookmarkManager.getBookmarkManager(connection); if (!bookmarkManager.isSupported()) { throw new TestNotPossibleException("Private data storage not supported"); } final MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(connection); final Resourcepart mucNickname = Resourcepart.from("Nick-" + StringUtils.randomString(6)); final String randomMucName = StringUtils.randomString(6); final DomainBareJid mucComponent = multiUserChatManager.getMucServiceDomains().get(0); final MultiUserChat muc = multiUserChatManager.getMultiUserChat(JidCreate.entityBareFrom( Localpart.from(randomMucName), mucComponent)); MucCreateConfigFormHandle handle = muc.createOrJoin(mucNickname); if (handle != null) { handle.makeInstant(); } muc.leave(); bookmarkManager.addBookmarkedConference("Smack Inttest: " + testRunId, muc.getRoom(), true, mucNickname, null); connection.disconnect(); connection.connect().login(); // MucBookmarkAutojoinManager is also able to do its task automatically // after every login, it's not deterministic when this will be finished. // So we trigger it manually here. MucBookmarkAutojoinManager.getInstanceFor(connection).autojoinBookmarkedConferences(); assertTrue(muc.isJoined()); // If the test went well, leave the MUC muc.leave(); }
public MultiUserChat joinChannel(String channelName, ChatType type, String password) { try { channelName = channelName.toLowerCase(); MultiUserChat room = new MultiUserChat(this, getChatRoomJID(channelName, type, password, password==null)); chatRooms.put(channelName, room); if (password == null) { try { room.join(getUsername()); room.sendRegistrationForm(room.getRegistrationForm()); } catch (NoResponseException e) { //throw new IllegalStateException("Could not join room", e); } } else { room.join(getUsername(), password); } return room; } catch (Exception e) { throw new IllegalStateException(e); } }
MultiUserChat muc = new MultiUserChat(connection, "roomname@<server>"); muc.create("nickname1"); Form form = muc.getConfigurationForm(); Form submitForm = form.createAnswerForm(); for (Iterator fields = form.getFields();fields.hasNext();){ FormField field = (FormField) fields.next(); if(!FormField.TYPE_HIDDEN.equals(field.getType()) && field.getVariable()!= null){ submitForm.setDefaultAnswer(field.getVariable()); } } submitForm.setAnswer("muc#roomconfig_publicroom", true); muc.sendConfigurationForm(submitForm); muc.join("nickname1"); }catch (Exception e) { e.printStackTrace(); }
private void join(MultiUserChat chat) { try { assert connection.isConnected(); assert connection.isAuthenticated(); chat.addParticipantListener(new PresenceIndicator.PresenceListener()); chat.addParticipantListener(new PresenceListener()); chat.join(getUserName()); } catch (XMPPException ex) { XMPPLOG.log(Level.INFO, "Cannot join " + chat.getRoom(), ex); } }
muc.join(Resourcepart.from(nickname)); muc.sendMessage("Goodbye cruel World!");
MultiUserChat muc = new MultiUserChat(XMPP.getInstance().getConnection(getActivity()), groupname); try { muc.create(StringUtils.parseName(XMPP.getInstance().getConnection(getActivity()).getUser())); muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT)); } catch (XMPPException e) { } catch (NoResponseException e) { e.printStackTrace(); } catch (SmackException e) { e.printStackTrace(); } for (int i = 0; i < alSelectedContacts.size(); i++) { Log.e("tag", "group chating purpose1 ::" + alSelectedContacts.get(i).get("id")); try { muc.invite((alSelectedContacts.get(i).get("id") + "_user") + "@" + XMPP.HOST, alSelectedContacts.get(i).get("id") + "_user"); } catch (NotConnectedException e) { e.printStackTrace(); } } try { muc.sendMessage("New group created"); } catch (NotConnectedException e1) { e1.printStackTrace(); } catch (XMPPException e1) { e1.printStackTrace(); }