Reputation: 304
I am developing the chat application using xmpp ejabberd. I want to develop an XMPP group chat similar to whats app. XMPP group chat setup is done on my XMPP server. I am successfully creating the room & joining the room. But I want the rooms in which I have joined. I am using the following iq for fetching the list of groups from server
NSString* server = @"conference.test.com";
XMPPJID *serverJID = [XMPPJID jidWithString:server];
XMPPIQ *iq = [XMPPIQ iqWithType:@"get" to:serverJID];
[iq addAttributeWithName:@"from" stringValue:[[APP_DELEGATE xmppStream] myJID].full];
NSXMLElement *query = [NSXMLElement elementWithName:@"query"];
[query addAttributeWithName:@"xmlns" stringValue:@"http://jabber.org/protocol/disco#items"];
[iq addChild:query];
[[APP_DELEGATE xmppStream] sendElement:iq];
from the above code I am getting the list of groups from my server but I want the list of groups which I have joined or the groups from which I got the invitation.
Code for create & join the room is as follows
-(void) CreateRoom:(NSString *)roomJid {
static dispatch_once_t queueCreationGuard;
static dispatch_queue_t queue;
dispatch_once(&queueCreationGuard, ^{
queue = dispatch_queue_create("com.something.myapp.backgroundQueue", 0);
});
XMPPRoomMemoryStorage *roomStorage = [[XMPPRoomMemoryStorage alloc] init];
XMPPJID *roomJID = [XMPPJID jidWithString:roomJid];
XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:roomStorage jid:roomJID dispatchQueue:queue];
[xmppRoom activate:[self xmppStream]];
[xmppRoom addDelegate:self
delegateQueue:queue];
NSXMLElement *history = [NSXMLElement elementWithName:@"history"];
[history addAttributeWithName:@"maxstanzas" stringValue:@"0"];
[xmppRoom joinRoomUsingNickname:[self xmppStream].myJID.user
history:history
password:nil];
}
- (void)xmppRoomDidCreate:(XMPPRoom *)sender
{
NSLog(@"Room Created");
}
- (void)xmppRoomDidJoin:(XMPPRoom *)sender
{
NSLog(@"Room Joined");
}
If anyone have solution please answer the question. Thanks
Upvotes: 0
Views: 1577
Reputation: 1709
You can use this: (Swift 3.0)
var muc = XMPPMUC(dispatchQueue: DispatchQueue.main)
muc?.activate(stream) //Here stream is the XMPPStream
muc?.addDelegate(self, delegateQueue: DispatchQueue.main)
muc?.discoverRooms(forServiceNamed: "conference.localhost")
OR you can use this:
let xmlstring: String = String("<query xmlns='http://jabber.org/protocol/disco#items'/>")
let newQuery = try! DDXMLElement(xmlString: xmlstring)
let newIq = XMPPIQ(type: "get", to: XMPPJID(string:"conference.localhost"), elementID: stream.generateUUID(), child: newQuery)
stream.send(newIq)
Upvotes: 1