如何在xmpp服务器中创建新组

发布于 2024-12-26 06:28:30 字数 626 浏览 3 评论 0原文

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

我想添加用户和组, 我怎样才能创建新群组? 如何通过添加好友查询提及群组名称?

这是我添加新用户的代码

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 扩展,但我找不到正确的结果

Am using Strophe.js library for communication between my application with XMPP(Openfire) server.

I want add user with group,
How can i create new group?
How can i mention group name with add buddy query?

This is my code for adding new user

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());

I refer XMPP extension over day but i cant find proper result

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沙与沫 2025-01-02 06:28:30

您需要发送名册更新。 阅读 RFC 6121 第 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')

You need to send a roster update. Read RFC 6121, Section 2 for details. You'll be sending this protocol:

<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>

With code something like:

$iq({'type':'set'}).c('query',{'xmlns':Strophe.NS.ROSTER}) 
   .c('item', {'jid':'[email protected]','name':'nick'})
       .c('group').t('My Group')
亣腦蒛氧 2025-01-02 06:28:30

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

XMPPRoomCoreDataStorage *rosterstorage =[[XMPPRoomCoreDataStorage alloc] init];
XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:rosterstorage jid:[XMPPJID jidWithString:@"[电子邮件受保护]"]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::@"[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];

}

I have made this Using below code.

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()];

Then

  • (void)xmppRoomDidJoin:(XMPPRoom *)sender

{

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];

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文