XMPPFramework - 如何创建MUC会议室并邀请用户? [英] XMPPFramework - How to create a MUC room and invite users?

查看:153
本文介绍了XMPPFramework - 如何创建MUC会议室并邀请用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Robbiehanson的iOS XMPPFramework。我正在尝试创建一个MUC会议室并邀请用户加入群聊室,但它无法正常工作。

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.

我使用以下代码:

XMPPRoom *room = [[XMPPRoom alloc] initWithRoomName:@"user101@conference.jabber.org/room" nickName:@"room"];
[room createOrJoinRoom];
[room sendInstantRoomConfig];
[room setInvitedUser:@"ABC@jabber.org"];
[room activate:[self xmppStream]];    
[room inviteUser:jid1 withMessage:@"hello please join."];
[room sendMessage:@"HELLO"];

用户ABC@jabber.org应该收到邀请信息但没有任何事情发生。

The user ABC@jabber.org should receive the invite message but nothing is happening.

任何帮助将不胜感激。 :)

Any help will be appreciated. :)

推荐答案

在探索各种解决方案之后,我决定在这里编译和分享我的实现:

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


  1. 创建XMPP会议室:

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


  • 检查此代表是否成功创建了房间:

  • Check if room is successfully created in this delegate:

    - (void)xmppRoomDidCreate:(XMPPRoom *)sender
    


  • 检查您是否已加入此代表中的房间:

  • Check if you've joined the room in this delegate:

    - (void)xmppRoomDidJoin:(XMPPRoom *)sender
    


  • 创建房间后,获取房间配置表格:

  • After room is created, fetch room configuration form:

    - (void)xmppRoomDidJoin:(XMPPRoom *)sender {
        [sender fetchConfigurationForm];
    }
    


  • 配置房间

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

    参考文献: XEP-0045:多用户聊天实施群聊

    邀请用户

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


  • 在那里,你' ve创建了一个XMPP多用户/组聊天室,并邀请了一位用户。 :)

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

    这篇关于XMPPFramework - 如何创建MUC会议室并邀请用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆