首页 > 代码库 > xmpp聊天室(5)

xmpp聊天室(5)

聊天室

 

[cpp] view plaincopyprint?
  1. //初始化聊天室  
  2. XMPPJID *roomJID = [XMPPJID jidWithString:ROOM_JID];    
  3.     
  4. xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:self jid:roomJID];    
  5.     
  6. [xmppRoom activate:xmppStream];    
  7. [xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];  

 

 

[cpp] view plaincopyprint?
  1. //创建聊天室成功  
  2. - (void)xmppRoomDidCreate:(XMPPRoom *)sender  
  3. {  
  4.     DDLogInfo(@"%@: %@", THIS_FILE, THIS_METHOD);  
  5. }  




 

[cpp] view plaincopyprint?
  1. //加入聊天室,使用昵称  
  2. [xmppRoom joinRoomUsingNickname:@"quack" history:nil];   

 

 

 

[cpp] view plaincopyprint?
  1. //获取聊天室信息  
  2. - (void)xmppRoomDidJoin:(XMPPRoom *)sender  
  3. {  
  4.     [xmppRoom fetchConfigurationForm];  
  5.     [xmppRoom fetchBanList];  
  6.     [xmppRoom fetchMembersList];  
  7.     [xmppRoom fetchModeratorsList];  
  8. }  

 

如果房间存在,会调用委托

[cpp] view plaincopyprint?
  1. // 收到禁止名单列表    
  2. - (void)xmppRoom:(XMPPRoom *)sender didFetchBanList:(NSArray *)items;    
  3. // 收到好友名单列表    
  4. - (void)xmppRoom:(XMPPRoom *)sender didFetchMembersList:(NSArray *)items;    
  5. // 收到主持人名单列表    
  6. - (void)xmppRoom:(XMPPRoom *)sender didFetchModeratorsList:(NSArray *)items;   

 

房间不存在,调用委托

 

 

[cpp] view plaincopyprint?
  1. - (void)xmppRoom:(XMPPRoom *)sender didNotFetchBanList:(XMPPIQ *)iqError;    
  2. - (void)xmppRoom:(XMPPRoom *)sender didNotFetchMembersList:(XMPPIQ *)iqError;    
  3. - (void)xmppRoom:(XMPPRoom *)sender didNotFetchModeratorsList:(XMPPIQ *)iqError;  


离开房间

 

 

[cpp] view plaincopyprint?
  1. [xmppRoom deactivate:xmppStream];    

 

[cpp] view plaincopyprint?
  1. //离开聊天室  
  2. - (void)xmppRoomDidLeave:(XMPPRoom *)sender  
  3. {  
  4.     DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD);  
  5. }  

 

其他代理

 

[cpp] view plaincopyprint?
    1. //新人加入群聊  
    2. - (void)xmppRoom:(XMPPRoom *)sender occupantDidJoin:(XMPPJID *)occupantJID  
    3. {  
    4.     DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD);  
    5. }  
    6. //有人退出群聊  
    7. - (void)xmppRoom:(XMPPRoom *)sender occupantDidLeave:(XMPPJID *)occupantJID  
    8. {  
    9.     DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD);  
    10. }  
    11. //有人在群里发言  
    12. - (void)xmppRoom:(XMPPRoom *)sender didReceiveMessage:(XMPPMessage *)message fromOccupant:(XMPPJID *)occupantJID  
    13. {  
    14.     DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD);  
    15. }