Welcome, Guest
  • Author Topic: Private Message in FCS  (Read 2558 times)

    Brian Busche

    • Server what's that
    • *
    • Posts: 6
    • ~~
      • View Profile
      • Email
    Private Message in FCS
    « on: 07/26/03, 17:08 »
    I couldn't find a thread on this, though I'm suprised that nobody has asked.

    I want to create a function in server side actionscript that would allow my FCS chat application to target a single user with a message (private messaging).  It looks simple enough, using the call method, it should be something like this:

    function privateMessage(user, msg){
         user.call("someFunctionOnClient", null, msg);
    }

    However, the error that follows states that "user" has no methods.  Since call is a method of ClientObj, how do you create a ClientObj for every user in your application?
    « Last Edit: 07/26/03, 17:09 by Brian Busche »

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re:Private Message in FCS
    « Reply #1 on: 07/28/03, 11:00 »
    When user log into your app, you need to store a reference to the client name somewhere, and then retrieve to route a private message. application onConnect could be a good place I.e

    [script]
    application.onConnect = function(newClient, name) {
       // Give this new client the same name as the user name
       newClient.name=name;
       newClient.id=this.clientID;
       // Accept the new client's connection
       application.acceptConnection(newClient);
       //send unique ID
       newClient.call("setID", false, this.clientID)   
       //Make a reference   
       this.clients[this.clientID] = this.newClient;
       this.clientID++
    }
    [/script]

    Then you use this.clients array to route messages. Note that trough the setID method, each client stores his own ID, so is easy to route between each one.

    Also the in-built Client object have methods to walk trough conected users (check SSAS reference)

    Jorge


    Brian Busche

    • Server what's that
    • *
    • Posts: 6
    • ~~
      • View Profile
      • Email
    Re:Private Message in FCS
    « Reply #2 on: 07/28/03, 13:46 »
    Thanks for the reply, but can't you reference the appropriate client instance in application.clients with the newClient.name?  Seems redundant to create an additional ID reference to track this, unless I am not understanding you correctly.

    When a user is accepted, there is a reference to that user in application.clients that you can retrieve with newClient.name

    You can then conditionally use client.call() if the target name matches newClient.name
    « Last Edit: 07/28/03, 13:52 by Brian Busche »

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re:Private Message in FCS
    « Reply #3 on: 07/28/03, 15:12 »
    Yep, you're rigth. In my example, I use a special array because I'm creating different rooms, and under certain conditions (video or not video) I'm changing app, but need to keep user. Further, I need to store users in a DB, so that's the reason of my redundant array. By breaking my array, also i try to not walk the entire Client array to check properties.
    Anyway, as you understand how to walk the Client array, you have the answer:

    Quote
    You can then conditionally use client.call() if the target name matches newClient.name


    Jorge

    gtmak

    • Server what's that
    • *
    • Posts: 19
      • View Profile
      • Email
    Re:Private Message in FCS
    « Reply #4 on: 07/30/03, 03:41 »
    hi jorge can u help with private message
    i have done my simpleconnection chatroom and i want to create a private message.
    can u help me out.
    will the code below work in simple connection.



    application.onConnect = function(newClient, name) {
                 // Give this new client the same name as the user name
                 newClient.name=name;
                 newClient.id=this.clientID;
                 // Accept the new client's connection
                   application.acceptConnection(newClient);
                 //send unique ID
                 newClient.call("setID", false, this.clientID)  
                 //Make a reference  
                 this.clients[this.clientID] = this.newClient;
                 this.clientID++
               }
    ???