2012-01-11 42 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]; 

}