4 Replies Latest reply on Feb 2, 2012 5:53 AM by havefreetime

    How can I count the participants' number in TextChatApp? (using SharedObject, FMS)

    havefreetime Level 1

      Hi all.

       

      How can I count participants' number?

       

      If the 3st user enter the room, the 3st user have to know that how many users are in the room.

       

      How do I know how many users are in the room?

       

      Thanks in advanced.

       

      Kevin.

        • 1. Re: How can I count the participants' number in TextChatApp? (using SharedObject, FMS)
          Claudiu Ursica Level 4

          There is an acceptConnection() sor something like that on FMS, every time you do accept a connection increase a counter.

          It is up to you if you call all the clients to update by hand (custom method) as a result to the counter increase or just update the SharedObject which will synchronize with the subscribed users.

           

          C

          • 2. Re: How can I count the participants' number in TextChatApp? (using SharedObject, FMS)
            havefreetime Level 1

            Thanks Claudiu.

             

            Could you please explain  how to increase a counter in more detail?

             

            I can chat each other. But I still don't know how to count.

             

            Sorry. I'm new to Flex.

             

            Thanks.

             

            Kevin.

            • 3. Re: How can I count the participants' number in TextChatApp? (using SharedObject, FMS)
              Claudiu Ursica Level 4

              You have server side hooks for connections coming in or being closed (including here custom code for server disconnecting users for idle purposes).

               

               

              you need to keep track of the connections I don't remember now what FMS offers out of the box. Let's assume not much.

               

               

              When connection is coming in you can choose to accept or reject it. When you accept a connection you need to add it to your existing connections array or whatever data structure you use to keep track of them. Also you need to iterate to all connected users (clients) and call a custom method "userJoined()" on them to notify that a new user has joined.

               

               

              When a user leaves you need to remove the user from the collection and also notify that it left.

               

              on wowza you have stuff like :

               

               

              private HashSet();

               

               

              public void onConnect(IClient client, RequestFunction function,

                          AMFDataList params) {

                       }

               

               

              public void onDisconnect(IClient client) {

                  } 

               

              public void onConnectAccept(IClient client) {

                  _connectedClients.add(client); 

                  sendUserJoined();

                }

               

               

              /**

                   

              • @param client

                   */

                  public void onConnectReject(IClient client) {

                       _connectedClients.remove(client); 

                      sendUserLeft();

                  }

               

               

                  public void sendUserJoined(String userName)

                  {

                      Iterator it = _connectedClients.iterator();

                      while (it.hasNext()) { 

                          IClient each =  it.next();

                              each.call("userLeft", userName);

                          }   

                      }

                  }

               

               

               

              FMS has similar hooks. This is simplified but you have a rough idea. You can call clients with no parameters and then is up to client so call back for updates to the server if interested. You need to implement "userJoined" and userLeft client side also.

               

               

              C

              1 person found this helpful
              • 4. Re: How can I count the participants' number in TextChatApp? (using SharedObject, FMS)
                havefreetime Level 1

                Thanks Claudiu.

                 

                I found your solution.

                 

                http://forums.adobe.com/message/3885884#3885884

                 

                 

                I really really appriciated it.

                 

                Kevin