4

I am trying to auto-join rooms using XEP-0048 - Bookmarks (http://xmpp.org/extensions/xep-0048.html).

I am using RobbieHanson XMPPFramework, ejabberd v13.x So far, I have been able to add bookmark to the room using the following code :

-(void) createBookmarkforRoom:(NSString *)roomJid {
    NSXMLElement *nick = [NSXMLElement elementWithName:@"nick" stringValue:@"Marge"];

    NSXMLElement *conference = [DDXMLNode elementWithName:@"conference"];
    [conference addAttributeWithName:@"name" stringValue:@"BookmarkName"];
    [conference addAttributeWithName:@"autojoin" stringValue:@"true"];
    [conference addAttributeWithName:@"jid" stringValue:roomJid];

    [conference addChild:nick];

    NSXMLElement *storage =[DDXMLNode elementWithName:@"storage"];
    [storage addAttributeWithName:@"xmlns" stringValue:@"storage:bookmarks"];

    [storage addChild:conference];

    NSDictionary *options = [NSDictionary dictionaryWithObjects:@[@"pubsub#persist_items",@"pubsub#access_model"]
                                                    forKeys:@[@"true",@"whitelist"]];

    [self.publishSubscribeModule publishToNode:@"storage:bookmarks"
                                     entry:(NSXMLElement *)storage
                                withItemID:(NSString *)@"current"
                                   options:(NSDictionary *)options];

}

The following xml is successfully sent :

<iq type="set" id="2749368B-E365-45D6-A4B0-2F79DC6F4747">
   <pubsub xmlns="http://jabber.org/protocol/pubsub">
      <publish node="storage:bookmarks">
         <item id="current">
            <storage xmlns="storage:bookmarks">
               <conference name="BookmarkName" autojoin="true" jid="testroom@conference.mydomain.com">
                  <nick>Marge</nick>
               </conference>
            </storage>
         </item>
      </publish>
      <publish-options>
         <x xmlns="jabber:x:data" type="submit">
            <field var="FORM_TYPE" type="hidden">
               <value>http://jabber.org/protocol/pubsub#publish-options</value>
            </field>
            <field var="true">
               <value>pubsub#persist_items</value>
            </field>
            <field var="whitelist">
               <value>pubsub#access_model</value>
            </field>
         </x>
      </publish-options>
   </pubsub>
</iq>

And I receive :

<iq xmlns="jabber:client" from="marge@mydomain.com" to="marge@mydomain.com/41045582821403862604272126" id="2749368B-E365-45D6-A4B0-2F79DC6F4747" type="result">
   <pubsub xmlns="http://jabber.org/protocol/pubsub">
      <publish node="storage:bookmarks">
         <item id="current" />
      </publish>
   </pubsub>
</iq>

When I try to fetch bookmarks using the following code :

-(void)requestBookmarks {
    DDXMLElement *pubsub = [DDXMLElement elementWithName:@"pubsub" xmlns:@"http://jabber.org/protocol/pubsub"];

    DDXMLElement *items = [DDXMLElement elementWithName:@"items"];
    [items addAttributeWithName:@"node" stringValue:@"storage:bookmarks"];

    [pubsub addChild:items];

    XMPPIQ *iqBookmark = [XMPPIQ iqWithType:@"get" elementID:@"retrievebookmark10" child:pubsub];
    [self.stream sendElement:iqBookmark];
}

It sends the following xml :

<iq type="get" id="retrievebookmark10">
    <pubsub xmlns="http://jabber.org/protocol/pubsub">
        <items node="storage:bookmarks"/>
    </pubsub>
</iq>

and I receive :

<iq xmlns="jabber:client" from="marge@mydomain.com" to="marge@mydomain.com/41045582821403862604272126" id="retrievebookmark10" type="result">
    <pubsub xmlns="http://jabber.org/protocol/pubsub">
        <items node="storage:bookmarks">
            <item id="current">
                <storage xmlns="storage:bookmarks">
                    <conference name="BookmarkName" autojoin="true" jid="testroom@conference.mydomain.com">
                        <nick>Marge</nick>
                    </conference>
                </storage>
            </item>
        </items>
    </pubsub>
</iq>

So it seems that I can successfully store bookmarks and retrieve them. But, when I try to talk in the room testroom@conference.mydomain.com without manually joining it I get a error saying that I have to join the room before I can talk in the room. If I join the room (manually), every things works fine.

On the server-side, I used the mod_pubsub module with the following options :

  mod_pubsub:
   access_createnode: pubsub_createnode
    ## reduces resource comsumption, but XEP incompliant
   ignore_pep_from_offline: true
    ## XEP compliant, but increases resource comsumption
    ## ignore_pep_from_offline: false
   last_item_cache: false
   plugins:
     - "flat"
     - "hometree"
     - "pep" # pep requires mod_caps

I am wondering why do I have to manually join bookmarked with "auto-join = true" rooms. Any clue ?

Caroline
  • 396
  • 2
  • 10

1 Answers1

2

Autojoining bookmarked rooms is entirely a client-side feature - the client is supposed to retrieve the bookmarks at startup, and explicitly join the rooms marked as "auto-join".

legoscia
  • 39,593
  • 22
  • 116
  • 167
  • Can you please help via Coding , how can i autojoin ? In my code, room already created from backend.. please help , thanks in advance.. – Suresh Jagnani Nov 09 '15 at 12:12
  • You could post that as a new question, showing a minimal code example, the XMPP traffic it generates, and any error messages you get. – legoscia Nov 09 '15 at 13:05
  • legoscia : yes i understand but mainly issue is : when i disconnect form XMPP (when out of the app), at that time user leave from room and when re-connect XMPP not auto join connect the room. On backend side room auto created, i dont create the room inside app. is that any help please.. thank your so much in Advance.. – Suresh Jagnani Nov 09 '15 at 14:53
  • That sounds like a good topic for a new question. Include the code that you use to join the rooms, and the XMPP traffic it generates. There should be some clues in there. – legoscia Nov 09 '15 at 16:21
  • See basically i have diff kind of auto group from backend like diff kind of game and which game i select i am available in that room like chess etc.. And room created default..and So when i connect XMPP i need to join that room , i have that room id from backend api. – Suresh Jagnani Nov 10 '15 at 07:33
  • That sounds good. The room JID should be all you need to join the room. If you encounter any problems, you could post a question about that. – legoscia Nov 10 '15 at 08:41
  • Thanks for your reply, i did join the room first time, but when i disconnect from XMPP i need to again join the room, so one user available in more then 50 Groups, so its not possible to join again n again when user open the app and connect with XMPP. – Suresh Jagnani Nov 10 '15 at 08:46
  • if any solution then please provide it, Thanks a lot for your all kinds of reply and such help.. – Suresh Jagnani Nov 10 '15 at 16:21
  • If you post that as a question, more people will be able to see it than here in a comment thread. – legoscia Nov 11 '15 at 12:45
  • Please reply here : http://stackoverflow.com/questions/33730066/how-can-i-implement-auto-join-for-xmpp-room-in-ios – Suresh Jagnani Nov 16 '15 at 07:13
  • legoscia : any help ? – Suresh Jagnani Nov 19 '15 at 14:41