4

我正在使用 Strophe.js 库在我的应用程序与 XMPP(Openfire)服务器之间进行通信。

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

这是我添加新用户的代码

var str1=$pres({'xmlns':'jabber:client','from':xxx@example.com,'to':yyy@example.com,'type':'subscribe'}).c('nick',{'xmlns':'http://jabber.org/protocol/nick'}).t(userName);
 connection.send(str1.tree());

我一天都提到 XMPP 扩展,但我找不到合适的结果

4

2 回答 2

5

您需要发送名册更新。 阅读 RFC 6121,第 2 节了解详细信息。您将发送此协议:

<iq from='juliet@example.com/balcony'
    id='rs1'
    type='set'>
   <query xmlns='jabber:iq:roster'>
     <item jid='yyy@example.com' name='nick'>
        <group>My Group</group>
     </item>         
   </query>
</iq>

使用类似的代码:

$iq({'type':'set'}).c('query',{'xmlns':Strophe.NS.ROSTER}) 
   .c('item', {'jid':'yyy@example.com','name':'nick'})
       .c('group').t('My Group')
于 2012-01-13T23:48:33.010 回答
0

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

XMPPRoomCoreDataStorage *rosterstorage =[[XMPPRoomCoreDataStorage alloc] init]; XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:rosterstorage jid:[XMPPJID jidWithString:@"MyFirstGroup@conference.test-desktop"] 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()];

然后

  • (void)xmppRoomDidJoin:(XMPPRoom *)sender

{

NSXMLElement *iq = [NSXMLElement elementWithName:@"iq"];

[iq addAttributeWithName:@"id" stringValue:[NSString stringWithFormat:@"inroom-cr%@",groupName]]; 
[iq addAttributeWithName:@"to" stringValue::@"MyFirstGroup@conference.test-desktop"];
[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];

}

于 2013-07-23T11:42:00.307 回答