【问题标题】:how to create new group in xmpp server如何在 xmpp 服务器中创建新组
【发布时间】:2012-02-07 15:59:13
【问题描述】:

我正在使用 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 扩展,但我找不到合适的结果

【问题讨论】:

    标签: javascript jquery xmpp openfire strophe


    【解决方案1】:

    您需要发送名单更新。 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')
    

    【讨论】:

    • Hai Joe 在这种情况下,我无法将用户添加到特定组。,首先我想创建新组,然后才有可能。,哪个扩展将提供此功能
    • 基本 XMPP 中不存在空组。您可以单独存储一个空组列表,可能使用 PEP(XEP-0163:xmpp.org/extensions/xep-0163.html),或者,不使用私有存储(XEP-0049:xmpp.org/extensions/xep-0049.html)。对于其中任何一个,请使用您控制的新命名空间,但不要期望其他客户端能够看到空组。如果您对此有强烈的感觉,请编写一个新的 XEP,并将其提交给 XSF:xmpp.org/xmpp-protocols/xmpp-extensions/submitting-a-xep
    【解决方案2】:

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

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

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多