Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
279 views
in Technique[技术] by (71.8m points)

ios - XMPPFramework - Implement Group Chat (MUC)

I am working on the iOS chat client. Can anyone please help me with the Multi-User Chat?

I have implemented Robbiehanson's XMPPFramework.

Can anyone please let me know how to get list of group and create a group in server with this framework?

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

to get a list of rooms:

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

check for response in delegate method:

- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq{
    DDLogVerbose(@"%@", [iq description]);
    return NO;
}

to join or create room

XMPPRoomMemoryStorage * _roomMemory = [[XMPPRoomMemoryStorage alloc]init];
NSString* roomID = @"[email protected]";
XMPPJID * roomJID = [XMPPJID jidWithString:roomID];
XMPPRoom* xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:_roomMemory
                                             jid:roomJID
                                   dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:self.xmppStream];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom joinRoomUsingNickname:@"myNickname"
                        history:nil
                       password:nil];

check for response in XMPPRoom delegate methods:

- (void)xmppRoomDidCreate:(XMPPRoom *)sender{
    DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD);
}

- (void)xmppRoomDidJoin:(XMPPRoom *)sender{
    DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD);
}

update

to configure a room:

after:

[xmppRoom joinRoomUsingNickname:self.xmppStream.myJID.user
                        history:history
                       password:nil];

add:

[xmppRoom fetchConfigurationForm];

and check response in:

- (void)xmppRoom:(XMPPRoom *)sender didFetchConfigurationForm:(NSXMLElement *)configForm{
    DDLogVerbose(@"%@: %@ -> %@", THIS_FILE, THIS_METHOD, sender.roomJID.user);
}

Review the configForm object, and change as needed, then send it with [sender configureRoomUsingOptions:newConfig];

example: to change the configuration to make the room persistent you can add something like:

NSXMLElement *newConfig = [configForm copy];
NSArray* fields = [newConfig elementsForName:@"field"];
for (NSXMLElement *field in fields) {
    NSString *var = [field attributeStringValueForName:@"var"];
    if ([var isEqualToString:@"muc#roomconfig_persistentroom"]) {
        [field removeChildAtIndex:0];
        [field addChild:[NSXMLElement elementWithName:@"value" stringValue:@"1"]];
    }
}
[sender configureRoomUsingOptions:newConfig];

(i'm not familiar with NSXMLElement, so maybe there is a better way to change the value)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...