XMPPFramework - 如何创建MUC房间并邀请用户?

发布于 2024-11-25 13:37:23 字数 887 浏览 3 评论 0原文

我正在使用 Robbiehanson 的 iOS XMPPFramework。我正在尝试创建一个 MUC 房间并邀请用户加入群聊房间,但它不起作用。

我使用以下代码:

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

用户 [email protected] 应该收到邀请消息但什么也没有发生。

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

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 following code:

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

The user [email protected] should receive the invite message but nothing is happening.

Any help will be appreciated. :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

生寂 2024-12-02 13:37:23

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

  1. 创建 XMPP Room:

    XMPPRoomMemoryStorage *roomStorage = [[XMPPRoomMemoryStorage alloc] init];
    
    /** 
     * 请记住在您的 JID 中添加“会议”,如下所示:
     * 例如 [电子邮件受保护]
     */
    
    XMPPJID *roomJID = [XMPPJID jidWithString:@"[电子邮件受保护]"] ;
    XMPPRoom *xmppRoom = [[XMPPRoom 分配] initWithRoomStorage:roomStorage
                                                           jid:房间JID
                                                 调度队列:dispatch_get_main_queue()];
    
    [xmppRoom activate:[self appDelegate].xmppStream];
    [xmppRoom addDelegate:self 
            delegateQueue:dispatch_get_main_queue()];
    
    [xmppRoom joinRoomUsingNickname:[self appDelegate].xmppStream.myJID.user 
                            历史:无 
                           密码:无];
    
  2. 检查该委托中是否成功创建房间:

    - (void)xmppRoomDidCreate:(XMPPRoom *)发送者
    
  3. 检查您是否已加入此委托中的房间:

    - (void)xmppRoomDidJoin:(XMPPRoom *)发送者
    
  4. 创建房间后,获取房间配置表单:

    - (void)xmppRoomDidJoin:(XMPPRoom *)sender {
        [发件人获取配置表单];
    }
    
  5. 配置你的房间

    <前><代码>/**
    * 防止此消息所必需的:
    *“在确认配置之前,该房间将被锁定,无法进入。”
    */

    - (void)xmppRoom:(XMPPRoom *)发送者 didFetchConfigurationForm:(NSXMLElement *)configForm
    {
    NSXMLElement *newConfig = [configForm 副本];
    NSArray *fields = [newConfig elementsForName:@"field"];

    for (NSXMLElement *字段中的字段)
    {
    NSString *var = [字段 attributeStringValueForName:@"var"];
    // 使空间持久化
    if ([var isEqualToString:@"muc#roomconfig_persistentroom"]) {
    [字段removeChildAtIndex:0];
    [字段 addChild:[NSXMLElement elementWithName:@"value" stringValue:@"1"]];
    }
    }

    [发送者configureRoomUsingOptions:newConfig];
    }

    参考文献:XEP-0045:多用户聊天,< a href="https://stackoverflow.com/questions/19268629/xmpp-ios-chat-c​​lient-implement-group-chat">实施组聊天

  6. 邀请用户

    - (void)xmppRoomDidJoin:(XMPPRoom *)发送者 
    {
        /** 
         * 您可以从包含 for 循环参与者的数组中读取 
         * 并在此处以相同方式发送多个邀请
         */
    
        [发件人邀请用户:[XMPPJID jidWithString:@“keithoys”] withMessage:@“问候!”];
    }
    

在这里,您创建了一个 XMPP 多用户/群组聊天室,并邀请了一位用户。 :)

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. [email protected]
     */
    
    XMPPJID *roomJID = [XMPPJID jidWithString:@"[email protected]"];
    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. :)

枕头说它不想醒 2024-12-02 13:37:23

我感觉alloc-init之后要做的第一件事就是将它附加到你的xmppStream,这样它就可以使用xmppStream发送/接收消息。

更准确地说:

XMPPRoom *room = [[XMPPRoom alloc] initWithRoomName:@"[email protected]/room" nickName:@"room"];
[room activate:[self xmppStream]];

//other things (create/config/...)

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:@"[email protected]/room" nickName:@"room"];
[room activate:[self xmppStream]];

//other things (create/config/...)
坏尐絯℡ 2024-12-02 13:37:23

检查最新的XMPPMUCLight & XMPPRoomLight 与 Whatsapp 和其他当今流行的社交应用程序房间类似,离线或房间里无人时不会被破坏或成员被踢。

请参阅此文档 & 来自 MongooseIM 的模组

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文