如何在xmpp中获取给定用户加入的房间列表



我正在使用xmpp-ejabbard开发聊天应用程序。我想开发一个类似whats应用程序的XMPP群聊。XMPP群聊设置是在我的XMPP服务器上完成的。我正在成功创建房间&加入房间。但我想要我加入的房间。我正在使用以下iq从服务器获取组列表

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

从上面的代码中,我从服务器上获得了组的列表,但我想要我已经加入的组的列表或我收到邀请的组。

创建代码&加入房间如下

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

如果有人有解决方案,请回答问题。感谢

您可以使用这个:(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")

或者你可以使用这个:

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)

最新更新