2

I am developing a chat application in iphone using XMPPFramework. Everything is working great but stuck at the point. I want to retrieve a list of all public rooms but there is no method found in XMPPFramework. So can someone help me out to solve this issue?

Charles
  • 50,943
  • 13
  • 104
  • 142
Biraj Zalavadia
  • 28,348
  • 10
  • 61
  • 77

2 Answers2

1

Here is the code to get list of all room

NSString* server = @"chat.shakespeare.lit"; //or whatever the server address for muc is
XMPPJID *servrJID = [XMPPJID jidWithString:server];
XMPPIQ *iq = [XMPPIQ iqWithType:@"get" to:servJID];
[iq addAttributeWithName:@"from" stringValue:[xmppStream myJID].full];
NSXMLElement *query = [NSXMLElement elementWithName:@"query"];
[query addAttributeWithName:@"xmlns" stringValue:@"http://jabber.org/protocol/disco#items"];
[iq addChild:query];
[xmppStream sendElement:iq];

If you have code to get the room of specific user please share it

Satish
  • 1,012
  • 2
  • 15
  • 32
1

I use this code to query server directly, but I'm not sure that is the best way.

 XMPPIQ *iq = [[XMPPIQ alloc] initWithType:@"get"];
 NSString* conferenceHost = [NSString stringWithFormat:@"conference.%@", _xmppStream.hostName];
[iq addAttributeWithName:@"from" stringValue:conferenceHost];
[iq addAttributeWithName:@"to" stringValue:_host];
DDXMLElement *query = [DDXMLElement elementWithName:@"query" xmlns:@"http://jabber.org/protocol/disco#items"];
[iq addChild:query];
[_xmppStream sendElement:iq];

Hope this help someone.

By the way, if you adopt this solution, then you have to do some parse in delegate method:

 - (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq {
  }  

I thing the best way is to parse method once the connection has started:

- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence {
    /* parse */
}

Then you check

  [[sender] from] domain]

if contains "conference." then you can think that sender is a room and finally you can add to NSMutableArray, for instance. Also when a new room will be created, didReceivePresence will be called, so parser will add the new room.

So, you have:

NSMutableArray* rooms;

Your method will be:

-(NSMutableArray*)getRooms {
    return _rooms;
}  
Luca Davanzo
  • 21,000
  • 15
  • 120
  • 146