Unable to create persistent chat room smack 4.1.1

Development environment:

Client: smack 4.1.1

Server: openfire 3.9.3

Code:

String roomId = “test003”;
String name=“test_group_chat”;
String desc = “the test group chat”;
String nick=“test”;

try {

MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(XmppConnectionManager.getInstance().getConnection());
MultiUserChat muc = manager.getMultiUserChat(StringUtils.getGroupRootFullId(roomId));
muc.create(nick);

// User1 (which is the room owner) configures the room as a moderated room
Form form = muc.getConfigurationForm();
Form answerForm = form.createAnswerForm();
answerForm.setAnswer(“muc#roomconfig_roomname”, name);
answerForm.setAnswer(“muc#roomconfig_roomdesc”, desc);
answerForm.setAnswer(“muc#roomconfig_presencebroadcast”, “moderator”);
answerForm.setAnswer(“muc#roomconfig_whois”, “moderator”);
answerForm.setAnswer(“muc#roomconfig_publicroom”, “1”);
// answerForm.setAnswer(“muc#roomconfig_moderatedroom”, “1”);
answerForm.setAnswer(“muc#roomconfig_maxusers”, “500”);
answerForm.setAnswer(“muc#roomconfig_persistentroom”, “1”);
muc.sendConfigurationForm(answerForm);
muc.join(nick);

} catch (XMPPException e) {

e.printStackTrace();
}catch (SmackException.NoResponseException e) {

e.printStackTrace();
} catch (SmackException.NotConnectedException e) {

e.printStackTrace();
}catch (SmackException e) {

e.printStackTrace();
}

Chat rooms created successfully, but the name, description settings fail, chat room is not permanent

{

String roomId = “test003”;
String name=“test_group_chat”;
String desc = “the test group chat”;
String nick=“test”;

try {

//获取房间管理对象
MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(XmppConnectionManager.getInstance().getConnection());
//创建一个房间
MultiUserChat muc = manager.getMultiUserChat(StringUtils.getGroupRootFullId(roomId));
muc.create(nick);

// User1 (which is the room owner) configures the room as a moderated room
Form form = muc.getConfigurationForm();

Form answerForm = form.createAnswerForm();
//向提交的表单添加默认答复,获取房间的默认设置菜单
for(FormField field : form.getFields() ){

if(!FormField.Type.hidden.name().equals(field.getType()) && field.getVariable() != null) {

answerForm.setDefaultAnswer(field.getVariable());
}

}

//muc#
//房间名称
answerForm.setAnswer(FormField.FORM_TYPE, “http://jabber.org/protocol/muc#roomconfig”);
//设置房间名称
answerForm.setAnswer(“muc#roomconfig_roomname”,name);
//设置房间描述
answerForm.setAnswer(“muc#roomconfig_roomdesc”, desc);
//是否允许修改主题
answerForm.setAnswer(“muc#roomconfig_changesubject”, true);

//设置房间最大用户数
List maxusers = new ArrayList();
maxusers.add(“100”);
answerForm.setAnswer(“muc#roomconfig_maxusers”, maxusers);

List cast_values = new ArrayList();
cast_values.add(“moderator”);
cast_values.add(“participant”);
cast_values.add(“visitor”);
answerForm.setAnswer(“muc#roomconfig_presencebroadcast”, cast_values);
//设置为公共房间
answerForm.setAnswer(“muc#roomconfig_publicroom”, true);
//设置为永久房间
answerForm.setAnswer(“muc#roomconfig_persistentroom”, true);
//允许修改昵称
answerForm.setAnswer(“x-muc#roomconfig_canchangenick”, true);
//允许用户登录注册房间
answerForm.setAnswer(“x-muc#roomconfig_registration”, true);

muc.sendConfigurationForm(answerForm);
muc.join(nick);

} catch (XMPPException e) {

e.printStackTrace();
}catch (SmackException.NoResponseException e) {

e.printStackTrace();
} catch (SmackException.NotConnectedException e) {

e.printStackTrace();
}catch (SmackException e) {

e.printStackTrace();
}

}

1 Like