Skip navigation
6568 Views 12 Replies Latest reply: Jul 23, 2010 12:03 AM by Squall867 RSS
Mike Chambers Bronze 13 posts since
Aug 13, 2008
Currently Being Moderated

Aug 14, 2008 11:06 AM

Simple Example of Joining a Room?

Does anyone have a simple example of joining a room? assuming that I know the room name?

 

Also, are there any docs for the project? All I can find are the old AS2 docs, which appear to be out of date.

 

mike

  • Mitchell Hashimoto Bronze 7 posts since
    Aug 7, 2008
    Currently Being Moderated
    Aug 14, 2008 2:46 PM (in response to Mike Chambers)
    Re: Simple Example of Joining a Room?

    I've been working with XIFF quite a bit lately, but here is an example:

     

     

    xmpp = new XMPPSocketConnection();
    room = new Room(xmpp);
    xmpp.username = "username";
    xmpp.password = "password";
    xmpp.server   = "jabber.server.com";
    xmpp.connect("standard");
    

     

     

    Then after receiving the login event:

     

     

    room.roomJID = new JID("someroom@conference.jabber.server.com");
    room.join();
    

     

     

    Then that will fire a RoomEvent.ROOM_JOIN on a successful connect.

      • Mitchell Hashimoto Bronze 7 posts since
        Aug 7, 2008
        Currently Being Moderated
        Aug 14, 2008 2:22 PM (in response to Mike Chambers)
        Re: Simple Example of Joining a Room?

        public function join( createReserved:Boolean = false, joinPresenceExtensions:Array = null ):Boolean
        

         

        Notice the "= false" and "= null" ?

         

        They are optional arguments. Just leave them blank.

          • Mitchell Hashimoto Bronze 7 posts since
            Aug 7, 2008
            Currently Being Moderated
            Aug 14, 2008 2:46 PM (in response to Mike Chambers)
            Re: Simple Example of Joining a Room?

            Oh! I'm so sorry! I posted the wrong code... Here you go

             

             

            room.roomJID = new JID("default@conference.jabber.citrusbyte.com");
            room.join();
            

             

            EDIT: I also edited my above post to fix this...

              • Philip Double Bronze 14 posts since
                Jul 23, 2008
                Currently Being Moderated
                Aug 20, 2008 6:51 AM (in response to Mike Chambers)
                Re: Simple Example of Joining a Room?

                Hi Mitchel,

                I saw the advice that you gave to Mike Chambers and was hoping that  you'd be able to expand upon that a bit if you have a moment.  In  creating a chat room in the way that you outlined does indeed create a  room but all entries in the room are attributed to the JID...

                For instance, if I create a chat room called  allchat@conference.jabber.org, log several users in, all of their input  shows up like:

                allchat [14:33] : what up?
                allchat [14:33] : not much just waiting for the dealeo to begin....
                allchat [14:34] : but how do I add my username instead of this crap....


                How do I go about having different users enter a room as themselves?  I.E. if I have a user named 'billybob' and a user named 'philisajerk'  how do I get the output to appear like:

                philisajerk [14:33] : what up?
                billybob[14:33] : not much just waiting for the dealeo to begin....
                philisajerk[14:34] : but how do I add my username instead of this crap....

                 

                The code that I'm using to create the room after establishing a connection and logging in is as follows:

                room= new Room(connection);
                room.roomJID = new JID("allchat@conference.example.com");
                room.addEventListener(RoomEvent.ROOM_JOIN, onRoomJoin);
                room.join();

                Any input would be appreciated because this is driving me bonkers....

                Thanks,
                Phil

  • Squall867 Bronze 47 posts since
    May 30, 2010
    Currently Being Moderated
    Jul 17, 2010 11:08 AM (in response to Mike Chambers)
    Re: Simple Example of Joining a Room?

    And if I want to get some information about a room before actually join? Like room name, subject, ecc.

    • Mark Walters KeyContributor 144 posts since
      Feb 5, 2009
      Currently Being Moderated
      Jul 22, 2010 2:13 PM (in response to Squall867)
      Re: Simple Example of Joining a Room?

      You can get a list of rooms by sending an IQ to your chat server:

       

      var browser:Browser = new Browser( connection );
      
      browser.getServiceItems( chatServer, onGetServiceItems );

       

      This list will have each room's name and jid.

       

      To get the subject and number of room occupants, if your server supports it, you can then send an IQ to each room:

       

      private function onGetServiceItems( iq:IQ ):void
      {
           var extensions:Array = iq.getAllExtensions();
           var disco:ItemDiscoExtension = extensions.length > 0 ? extensions[ 0 ] : null;
           
           if( disco )
           {
                if( disco.items.length > 0 )
                {
                     var browser:Browser = new Browser( connection );
                     browser.getNodeInfo( chatServer, new UnescapedJID( disco.items[ 0 ].jid ).node, onGetRoomInfo );
                }
           }
      }
      

       

      Note that this will only return subject and number of room occupants if your chat server is configured to do that.

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points