2012-01-11 44 views
4

我正在使用Strophe.js库进行应用程序与XMPP(Openfire)服务器之间的通信。如何在xmpp服务器中创建新组

我想添加用户组, 如何创建新组? 我如何提及添加好友查询的组名?

这是我添加新用户

var str1=$pres({'xmlns':'jabber:client','from':[email protected],'to':[email protected],'type':'subscribe'}).c('nick',{'xmlns':'http://jabber.org/protocol/nick'}).t(userName); 
connection.send(str1.tree()); 

代码我指XMPP扩展了一天,但我不能找到正确的结果

回答

5

您需要发送名册更新。 Read RFC 6121, Section 2了解详情。您要发送此协议:

<iq from='[email protected]/balcony' 
    id='rs1' 
    type='set'> 
    <query xmlns='jabber:iq:roster'> 
    <item jid='[email protected]' name='nick'> 
     <group>My Group</group> 
    </item>   
    </query> 
</iq> 

随着代码是这样的:

$iq({'type':'set'}).c('query',{'xmlns':Strophe.NS.ROSTER}) 
    .c('item', {'jid':'[email protected]','name':'nick'}) 
     .c('group').t('My Group') 
+1

海乔在这种情况下,我不能将用户添加到特定的组,首先我要创建新组则只有其可能的,其中扩展将提供此 – 2012-01-30 06:45:33

+2

有没有这样的事,作为一个基于XMPP的空组。您可以分别存储空组的列表,也许使用PEP(XEP-0163:http://xmpp.org/extensions/xep-0163.html),或者如果没有该私有存储(XEP-0049:http:// xmpp.org/extensions/xep-0049.html)。对于其中任何一个,请使用您控制的新名称空间,但不要期望其他客户端能够看到空组。如果您对此感到强烈,请编写一个新的XEP,并将其提交给XSF:http://xmpp.org/xmpp-protocols/xmpp-extensions/submitting-a-xep/ – 2012-01-31 05:56:20

0

我做这个使用下面的代码。

XMPPRoomCoreDataStorage * rosterstorage = [[XMPPRoomCoreDataStorage alloc] init];XMPPRoom * xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:rosterstorage jid:[XMPPJID jidWithString:@“[email protected]”] dispatchQueue:dispatch_get_main_queue()];

[xmppRoom activate:[[self appDelegate]xmppStream]]; 
[xmppRoom joinRoomUsingNickname:@"DeveloperQ" history:nil]; 

[[[self appDelegate] xmppStream] addDelegate:self delegateQueue:dispatch_get_main_queue()]; 
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()]; 

然后

  • (无效)xmppRoomDidJoin:(XMPPRoom *)发件人

{

NSXMLElement * IQ = [NSXMLElement elementWithName:@ “IQ”];

[iq addAttributeWithName:@"id" stringValue:[NSString stringWithFormat:@"inroom-cr%@",groupName]]; 
[iq addAttributeWithName:@"to" stringValue::@"[email protected]"]; 
[iq addAttributeWithName:@"type" stringValue:@"set"]; 
NSXMLElement *query = [NSXMLElement elementWithName:@"query" xmlns:XMPPMUCOwnerNamespaceName]; 
NSXMLElement *xelem = [NSXMLElement elementWithName:@"x" xmlns:@"jabber:x:data"]; 
[xelem addAttributeWithName:@"type" stringValue:@"submit"]; 
[query addChild:xelem]; 
[iq addChild:query]; 
[[[self appDelegate] xmppStream] sendElement:iq]; 

}