我正在尝试使用 XMPP(smack) 创建多用户聊天。创建房间后,当我尝试加入聊天室时,ofmucmember 中没有已加入成员的条目。
房间代码的创建如下:
public void createMultiUserChatRoom(String roomName, String nickName) {
MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(connection);
MultiUserChat multiUserChat = multiUserChatManager.getMultiUserChat(roomName+"@conference.localhost");
try {
multiUserChat.create(nickName);
Form form = multiUserChat.getConfigurationForm();
Form submitForm = form.createAnswerForm();
List<FormField> formFieldList = submitForm.getFields();
for (FormField formField : formFieldList) {
if(!FormField.Type.hidden.equals(formField.getType()) && formField.getVariable() != null) {
submitForm.setDefaultAnswer(formField.getVariable());
}
}
submitForm.setAnswer("muc#roomconfig_persistentroom", true);
submitForm.setAnswer("muc#roomconfig_publicroom", true);
submitForm.setAnswer("muc#roomconfig_enablelogging", true);
submitForm.setAnswer("x-muc#roomconfig_reservednick", false);
submitForm.setAnswer("x-muc#roomconfig_canchangenick", false);
submitForm.setAnswer("x-muc#roomconfig_registration", false);
submitForm.setAnswer("muc#roomconfig_passwordprotectedroom", false);
submitForm.setAnswer("muc#roomconfig_roomname", roomName);
submitForm.setAnswer("muc#roomconfig_whois", Arrays.asList("none"));
multiUserChat.sendConfigurationForm(submitForm);
} catch (Exception e) {
e.printStackTrace();
}
}
加入创建的房间代码如下:
public void joinMultiUserChatRoom(String userName, String roomName) {
MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(connection);
MultiUserChat multiUserChat = manager.getMultiUserChat(roomName + "@conference.localhost");
DiscussionHistory history = new DiscussionHistory();
history.setMaxStanzas(0);
try {
multiUserChat.join(userName);
multiUserChat.sendMessage(userName +" : You have joined the group : " + roomName);
Presence presence = multiUserChat.getOccupantPresence(roomName + "@conference.localhost/" + userName);
presence.setMode(Presence.Mode.available);
connection.sendStanza(presence);
} catch (Exception e) {
e.printStackTrace();
}
}
服务器响应:
<message to="admin@localhost/Smack" id="h7axM-14" type="groupchat" from="team6@conference.localhost/roy"><body>roy : You have joined the group : team6</body><x xmlns="jabber:x:delay" stamp="20160623T12:15:50" from="team6@conference.localhost/roy"/></message>
presence :<presence to='admin@localhost/Smack' id='WR9Dy-12'><x xmlns='http://jabber.org/protocol/muc#user'><item affiliation='owner' jid='admin@localhost/Smack' role='moderator'></item></x><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.igniterealtime.org/projects/smack' ver='NfJ3flI83zSdUDzCEICtbypursw='/></presence>
我没有收到任何错误。谁能告诉我我错在哪里?
最佳答案
填写配置表单时,您需要填写以下部分:
<field
label='Room Admins'
type='jid-multi'
var='muc#roomconfig_roomadmins'>
<value>wiccarocks@shakespeare.lit</value>
<value>hecate@shakespeare.lit</value>
</field>
<field
label='Room Owners'
type='jid-multi'
var='muc#roomconfig_roomowners'/>
管理员和所有者保存在ofMucAffiliation表中,如果更新配置并且未提及现有管理员或所有者,则服务器假定其从属关系已更改为成员,因此会将条目移动到ofMucMember 表。
关于java - 在 XMPP 中向 MUC 添加成员(SMACK),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37991820/