Question

Am en utilisant la bibliothèque Strophe.js pour la communication entre mon application avec le serveur XMPP (Openfire).

Je veux ajouter un utilisateur avec le groupe, Comment puis-je créer un nouveau groupe? Comment puis-je mentionner le nom du groupe avec d'ajouter la requête de contacts?

Ceci est mon code pour ajouter un nouvel utilisateur

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

Je me réfère l'extension XMPP sur le jour, mais je ne peux pas trouver bon résultat

Était-ce utile?

La solution

Vous devez envoyer une mise à jour de liste. Lire RFC 6121, Section 2 pour plus de détails. Vous enverrez ce protocole:

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

Avec le code quelque chose comme:

$iq({'type':'set'}).c('query',{'xmlns':Strophe.NS.ROSTER}) 
   .c('item', {'jid':'yyy@example.com','name':'nick'})
       .c('group').t('My Group')

Autres conseils

J'ai fait cela en utilisant le code ci-dessous.

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

Ensuite

  • (void) xmppRoomDidJoin: (XMPPRoom *) expéditeur

{

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

}

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top