XMPP Room
启用XMPPRoom模块
// Configure xmppRoom
XMPPJID *roomJID = [XMPPJID jidWithString:ROOM_JID];
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:self jid:roomJID];
[xmppRoom activate:xmppStream];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
// Start connection process
NSError *err = nil;
if (![xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&err])
{
DDLogError(@"MUCTesting: Cannot connect: %@", err);
}
连接认证
- (void)xmppStreamDidConnect:(XMPPStream *)sender
{
DDLogInfo(@"%@: %@", THIS_FILE, THIS_METHOD);
[xmppStream authenticateWithPassword:XMPP_PASSWORD error:nil];
}
认证成功,使用quack昵称加入ROOM_JID房间
- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender
{
DDLogInfo(@"%@: %@", THIS_FILE, THIS_METHOD);
[xmppRoom joinRoomUsingNickname:@"quack" history:nil];
}
- (void)xmppRoomDidJoin:(XMPPRoom *)sender
{
DDLogInfo(@"%@: %@", THIS_FILE, THIS_METHOD);
[xmppRoom fetchConfigurationForm];
[xmppRoom fetchBanList];
[xmppRoom fetchMembersList];
[xmppRoom fetchModeratorsList];
}
如果房间存在,会调用委托
// 收到禁止名单列表
- (void)xmppRoom:(XMPPRoom *)sender didFetchBanList:(NSArray *)items;
// 收到好友名单列表
- (void)xmppRoom:(XMPPRoom *)sender didFetchMembersList:(NSArray *)items;
// 收到主持人名单列表
- (void)xmppRoom:(XMPPRoom *)sender didFetchModeratorsList:(NSArray *)items;
房间不存在,调用委托
- (void)xmppRoom:(XMPPRoom *)sender didNotFetchBanList:(XMPPIQ *)iqError;
- (void)xmppRoom:(XMPPRoom *)sender didNotFetchMembersList:(XMPPIQ *)iqError;
- (void)xmppRoom:(XMPPRoom *)sender didNotFetchModeratorsList:(XMPPIQ *)iqError;
离开房间
[xmppRoom deactivate:xmppStream];