使用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扩展,但我找不到合适的结果
答案 0 :(得分:5)
您需要发送名册更新。 Read RFC 6121, Section 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')
答案 1 :(得分: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()];
然后
{
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];
}