Groups | Blog | Home
all groups > macromedia flash flashcom > march 2005 >

macromedia flash flashcom : Targeting individual users


tauceti
3/26/2005 5:55:27 PM
Hello,

I'm working on a chat app and would like to add private messaging. I'm trying
to find a way that a user sends the message to the server and in turn the
server forwards in to just the targeted user. I'm trying to remain secure so I
would like to avoid broadcasting the message to everyone and having Flash
filter out messages not targeted to it.

My current setup has users identified by their ID which is "u" + uniqueNumber
where uniqueNumber is an FCS app variable incremented with every login (same as
the chat examples that come with FCS)

Functions are prototyped as follows:

// Client
function sendPrivMsg ( ) {
var msg = chat_in_txt.text;
chat_in_txt.text = "";
app.my_nc.call ( "sendPrivMsg", null, msg, users_list.selectedItem.id );
}

function recvPrivMsg ( msg, from ) {
chat_out_txt.text += "[Private] " + msg;
}

// FCS main.asc
newClient.sendPrivMsg = function ( msg, to ) {
// Private Messaging
msg = this.first_name + ": " + msg + "\n";
trace ( "... sendPrivMsg()\n= to: " + to + ", msg: " + msg );
trace ( "... My ID is " + this.id ); // Prints the senders ID
if ( this.id == to ) {
// This doesn't work
trace ( "... Passing message on. my ID = " + this.id );
}
}


Thanks
tauceti
3/26/2005 7:30:15 PM
Well, I figured it out.

On the server side:
Application.onAppStart ( ) {
// ...
this.userHandler = new Object ( );
// ...
}

Application.onConnect ( client ) {
// ...
// client.id = unique identifier
this.userHandler[client.id] = client;
// ...
}

Client.prototype.sendPrivMsg ( msg, to ) {
application.userHandler[to].send ( "recvPrivMsg", null, msg, to );
application.userHandler[this.id].send ( "recvPrivMsg", null, msg, to );
}

application.onDisconnect ( client ) {
// ...
delete this.userHandler[client.id];
// ...
}

On the client side:
my_nc.recvPrivMsg = function ( msg, from ) {
trace ( "[" + from + "] " + msg );
}

function sendPrivMsg ( msg, to ) {
my_nc.call ( "sendPrivMsg", null, msg, to );
}

Hope that helps someone.
Seth
AddThis Social Bookmark Button