how to create persistent muc room in smack 4.1 beta2

痞子三分冷 提交于 2019-12-03 18:22:06
saurabh dixit

You need to submit form like this for making a persistent group:

private void setConfig(MultiUserChat multiUserChat) {
    try {
        Form form = multiUserChat.getConfigurationForm();
        Form submitForm = form.createAnswerForm();
        for (Iterator<FormField> fields = submitForm.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);
        submitForm.setAnswer("muc#roomconfig_persistentroom", true);
        multiUserChat.sendConfigurationForm(submitForm);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

You need to set muc#roomconfig_persistentroom to true in the MUC configuration from when creating the room.

MultiuserChat muc = manager.getMultiUserChat("myroom@muc.example.org");
muc.create("myNick");
// room is now created by locked
Form form = muc.getConfigurationForm();
Form answerForm = form.createAnswerForm();
answerForm.setAnswer("muc#roomconfig_persistentroom", true);
muc.sendConfigurationForm(answerForm);
// sending the configuration form unlocks the room

Note that not all XMPP MUC services support persistent rooms. For more information see:

In smack 4.1.1, The answers given by @saurabh dixit throw an exception. Please check this thread on ignite website Correct implementation for persistent rooms smack 4.1.1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!