XMPPFramework - How to create a MUC room and invite users?

前端 未结 3 2064
有刺的猬
有刺的猬 2020-11-29 01:31

I am using Robbiehanson\'s iOS XMPPFramework. I am trying to create a MUC room and invite a user to the group chat room but it is not working.

I am using the followi

相关标签:
3条回答
  • 2020-11-29 02:10

    Check the latest XMPPMUCLight & XMPPRoomLight its similar to Whatsapp and other today's trends social app rooms that don't get destroyed or members kicked when offline or no one in room.

    Refer this documentation & mod from MongooseIM

    0 讨论(0)
  • 2020-11-29 02:11

    I have the feeling that the first thing to do after alloc-init is to attach it to your xmppStream, so it can use xmppStream to send/receive messages.

    More exactly:

    XMPPRoom *room = [[XMPPRoom alloc] initWithRoomName:@"user101@conference.jabber.org/room" nickName:@"room"];
    [room activate:[self xmppStream]];
    
    //other things (create/config/...)
    
    0 讨论(0)
  • 2020-11-29 02:15

    After exploring various solutions, I've decided to compile and share my implementation here:

    1. Create an XMPP Room:

      XMPPRoomMemoryStorage *roomStorage = [[XMPPRoomMemoryStorage alloc] init];
      
      /** 
       * Remember to add 'conference' in your JID like this:
       * e.g. uniqueRoomJID@conference.yourserverdomain
       */
      
      XMPPJID *roomJID = [XMPPJID jidWithString:@"chat@conference.shakespeare"];
      XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:roomStorage
                                                             jid:roomJID
                                                   dispatchQueue:dispatch_get_main_queue()];
      
      [xmppRoom activate:[self appDelegate].xmppStream];
      [xmppRoom addDelegate:self 
              delegateQueue:dispatch_get_main_queue()];
      
      [xmppRoom joinRoomUsingNickname:[self appDelegate].xmppStream.myJID.user 
                              history:nil 
                             password:nil];
      
    2. Check if room is successfully created in this delegate:

      - (void)xmppRoomDidCreate:(XMPPRoom *)sender
      
    3. Check if you've joined the room in this delegate:

      - (void)xmppRoomDidJoin:(XMPPRoom *)sender
      
    4. After room is created, fetch room configuration form:

      - (void)xmppRoomDidJoin:(XMPPRoom *)sender {
          [sender fetchConfigurationForm];
      }
      
    5. Configure your room

      /**
       * Necessary to prevent this message: 
       * "This room is locked from entry until configuration is confirmed."
       */
      
      - (void)xmppRoom:(XMPPRoom *)sender didFetchConfigurationForm:(NSXMLElement *)configForm 
      {
          NSXMLElement *newConfig = [configForm copy];
          NSArray *fields = [newConfig elementsForName:@"field"];
      
          for (NSXMLElement *field in fields) 
          {
              NSString *var = [field attributeStringValueForName:@"var"];
              // Make Room Persistent
              if ([var isEqualToString:@"muc#roomconfig_persistentroom"]) {
                  [field removeChildAtIndex:0];
                  [field addChild:[NSXMLElement elementWithName:@"value" stringValue:@"1"]];
              }
          }
      
          [sender configureRoomUsingOptions:newConfig];
      }
      

      References: XEP-0045: Multi-User Chat, Implement Group Chat

    6. Invite users

      - (void)xmppRoomDidJoin:(XMPPRoom *)sender 
      {
          /** 
           * You can read from an array containing participants in a for-loop 
           * and send multiple invites in the same way here
           */
      
          [sender inviteUser:[XMPPJID jidWithString:@"keithoys"] withMessage:@"Greetings!"];
      }
      

    There, you've created a XMPP multi-user/group chat room, and invited a user. :)

    0 讨论(0)
提交回复
热议问题