Xmpp 使用Android上的Prosody Server(aSmack)创建多用户组失败;“缺少房间创建的确认”;
我正在android上开发XMPP聊天应用程序,使用Xmpp 使用Android上的Prosody Server(aSmack)创建多用户组失败;“缺少房间创建的确认”;,xmpp,smack,multiuserchat,prosody-im,Xmpp,Smack,Multiuserchat,Prosody Im,我正在android上开发XMPP聊天应用程序,使用Prosody作为XMPP服务器。 我已经为创建多用户聊天室编写了代码,当我使用Openfire作为服务器时,该聊天室工作正常,但当我使用Prosody作为服务器时,它会给我错误,如下所示: 创建失败-缺少房间创建确认。 i、 e组已存在。但它对任何名称(新组名)都会抛出相同的错误 如果我替换muc.create(名称)与多个连接(名称)它创建组。但是,我无法配置组/房间属性 下面是我的韵律配置文件:- modules_enabled = {
Prosody
作为XMPP服务器
。
我已经为创建多用户聊天室编写了代码,当我使用Openfire
作为服务器时,该聊天室工作正常,但当我使用Prosody
作为服务器时,它会给我错误,如下所示:
创建失败-缺少房间创建确认。
i、 e组已存在。但它对任何名称(新组名)都会抛出相同的错误
如果我替换muc.create(名称)代码>与多个连接(名称)代码>它创建组。但是,我无法配置组/房间属性
下面是我的韵律配置文件:-
modules_enabled = {
-- Generally required
"roster"; -- Allow users to have a roster. Recommended ;)
"saslauth"; -- Authentication for clients and servers. Recommended if you want to log in.
--"tls"; -- Add support for secure TLS on c2s/s2s connections
"dialback"; -- s2s dialback support
"disco"; -- Service discovery
-- Not essential, but recommended
"private"; -- Private XML storage (for room bookmarks, etc.)
"vcard"; -- Allow users to set vCards
-- These are commented by default as they have a performance impact
--"privacy"; -- Support privacy lists
--"compression"; -- Stream compression
-- Nice to have
"version"; -- Replies to server version requests
"uptime"; -- Report how long server has been running
"time"; -- Let others know the time here on this server
"ping"; -- Replies to XMPP pings with pongs
"pep"; -- Enables users to publish their mood, activity, playing music and more
"register"; -- Allow users to register on this server using a client and change passwords
-- Admin interfaces
"admin_adhoc"; -- Allows administration via an XMPP client that supports ad-hoc commands
--"admin_telnet"; -- Opens telnet console interface on localhost port 5582
-- HTTP modules
"bosh"; -- Enable BOSH clients, aka "Jabber over HTTP"
"http_files"; -- Serve static files from a directory over HTTP
-- Other specific functionality
"groups"; -- Shared roster support
--"announce"; -- Send announcement to all online users
--"welcome"; -- Welcome users who register accounts
--"watchregistrations"; -- Alert admins of registrations
--"motd"; -- Send a message to users when they log in
--"legacyauth"; -- Legacy authentication. Only used by some old clients and bots.
};
allow_registration = true -- Allow users to register new accounts
VirtualHost "localhost"
---Set up a MUC (multi-user chat) room server on conference.example.com:
Component "conference.localhost" "muc"
我的组创建代码是:-
MultiUserChat muc = new MultiUserChat(xmppConnection, room);
// Create the room
SmackConfiguration.setPacketReplyTimeout(2000);
String name = xmppConnection.getUser();
System.out.println("name:- " + name);
String name1 = name.substring(0, name.lastIndexOf("@"));
System.out.println("name1:- " + name1);
System.out.println("group name:- " + grpName);
muc.create(name1);
// Get the the room's configuration form
Form form = muc.getConfigurationForm();
// Create a new form to submit based on the original form
Form submitForm = form.createAnswerForm();
// Add default answers to the form to submit
for (Iterator<FormField> fields = form.getFields(); fields.hasNext();) {
FormField field = (FormField) fields.next();
if (!FormField.TYPE_HIDDEN.equals(field.getType()) && field.getVariable() != null) {
// Sets the default value as the answer
submitForm.setDefaultAnswer(field.getVariable());
}
}
// muc.sendConfigurationForm(submitForm);
Form f = new Form(Form.TYPE_SUBMIT);
try {
muc.sendConfigurationForm(f);
} catch (XMPPException xe) {
System.out.println( "Error on sendConfigurationForm:- " + xe);
}
// Sets the new owner of the room
List<String> owners = new ArrayList<String>();
owners.add(xmppConnection.getUser());
submitForm.setAnswer("muc#roomconfig_roomowners", owners);
submitForm.setAnswer("muc#roomconfig_persistentroom", true);
muc.sendConfigurationForm(submitForm);
MultiUserChat muc=新的MultiUserChat(xmppConnection,room);
//创建房间
SmackConfiguration.setPacketReplyTimeout(2000);
String name=xmppConnection.getUser();
System.out.println(“名称:-”+名称);
字符串name1=name.substring(0,name.lastIndexOf(“@”);
System.out.println(“name1:-”+name1);
System.out.println(“组名:-”+grpName);
muc.create(名称1);
//获取房间的配置表
Form Form=muc.getConfigurationForm();
//基于原始表单创建要提交的新表单
Form submitForm=Form.createAnswerForm();
//向要提交的表单添加默认答案
for(迭代器字段=form.getFields();fields.hasNext();){
FormField=(FormField)fields.next();
如果(!FormField.TYPE_HIDDEN.equals(field.getType())&&field.getVariable()!=null){
//将默认值设置为答案
submitForm.setDefaultAnswer(field.getVariable());
}
}
//muc.sendConfigurationForm(submitForm);
表格f=新表格(表格类型\提交);
试一试{
muc.sendConfigurationForm(f);
}捕获(XMPPException xe){
System.out.println(“sendConfigurationForm:-”+xe上的错误);
}
//设置房间的新所有者
列表所有者=新的ArrayList();
添加(xmppConnection.getUser());
submitForm.setAnswer(“muc#roomconfig_roomowners”,所有者);
submitForm.setAnswer(“muc#roomconfig_persistentroom”,true);
muc.sendConfigurationForm(submitForm);
我哪里出错了?这是由prosody的MUC插件的非标准行为造成的。基本上,它的行为就像一个MUC房间已经存在,即使事实并非如此
你必须有可能:
- 在这种情况下,使用Smack(自4.0起)将成功。另见
- 将韵律的
restrict\u room\u creation
设置为true
,将使韵律的行为符合XEP-45中的规定
由于要配置房间,唯一的选项是更改prosody的restrict\u room\u creation
设置
请注意,还有一个问题将在Smack 4.1中修复,但我不认为这个问题与此相关,这些信息只是为了完整性。
java代码的不必要缩进使其难以阅读,请修复此问题。