Vig*_*esh 3 xmpp ejabberd smack multiuserchat
从asmack迁移到smack 4.1 beta2.创建的muc房间不再持久.
MultiUserChatManager mucm=MultiUserChatManager.getInstanceFor(connection);
muc=mucm.getMultiUserChat(groupid+"@conference.localhost");
DiscussionHistory histroy=new DiscussionHistory();
histroy.setMaxStanzas(10);
muc.createOrJoin(username,null,histroy,SmackConfiguration.getDefaultPacketReplyTimeout());
muc.nextMessage();
Run Code Online (Sandbox Code Playgroud)
当用gajim创建时,房间是持久的.
编辑:这是我们之前使用的代码.默认情况下聊天室是持久的,
muc = new MultiUserChat(connection, groupid+"@conference.localhost");
if(!muc.isJoined())
{
DiscussionHistory histroy=new DiscussionHistory();
histroy.setMaxStanzas(10);
muc.join(username,null,histroy,SmackConfiguration.getDefaultPacketReplyTimeout());
muc.nextMessage(0);
}
Run Code Online (Sandbox Code Playgroud)
创建会议室时,您需要在MUC配置中设置muc#roomconfig_persistentroom为。true
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
Run Code Online (Sandbox Code Playgroud)
请注意,并非所有XMPP MUC服务都支持持久空间。有关更多信息,请参见:
您需要提交这样的表单来制作持久性组:
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();
}
}
Run Code Online (Sandbox Code Playgroud)