red5 chat revisited

April 28th, 2008 Posted in red5

As I continue to dig deeper into red5 I figured I would play around more with the chat demo…considering I need to build a complex communication tool for a client anyway….what better way to learn…

I’ve modified the code a little more by playing around with functionality, adding features like tool tips, user list, user icons, clearing the history, and a bit of skinning. I’m still trying to figure out how to add emo’s, sound, and user colour options.

I won’t go into all the code for the features I added, just the important chat stuff. I found a really great tool tip on google code you can grab it here, also a thank
you to Nick La of ndesign studios for the icons.

You can view the demo here.
bssChat2

We are still using the same connection method to red5

var nc:NetConnection = new NetConnection();
nc.connect("rtmp://localhost/oflaDemo");
var remote_so:SharedObject = SharedObject.getRemote("chat", nc.uri, false);
remote_so.connect(nc);

I have added a welcome screen that asks the user to enter a name. This way I can display a unique user list and easily add the user name to the output display. We create a var called username and datatype it as a string. We will build an array out of this later. The login window is inside an mc called login with the name field and submit button. When the submit buttton is clicked we will pass the name var to the user array and display it in the userlist. We will also add an icon to the name in the display list only.

var username:String;
Login.Name.setFocus();

function login():Void{
	ChatInput.setFocus();
	username = Login.Name.text;
	if (username == ""){username = "anonymous";}
	if (remote_so.data.users == undefined){
		remote_so.data.users = username;
	}else{
		remote_so.data.users += "," + username;
	}
	Login._visible = false;
}
Login.Submit.onRelease = login;

We will wrap all key events and messages into eventListers, it’s easier this way and it condenses the code.

keyListener = new Object();
keyListener.onKeyDown = function (){
if(Key.getAscii() == 13 && Login._visible == false){
sendMessage();
}else if(Key.getAscii() == 13){
login();
}
}

Key.addListener(keyListener);

Enter.onRelease = sendMessage;

function sendMessage(){
if (remote_so.data.chatText == undefined){
remote_so.data.chatText =  "" + username + ": " + ChatInput.text;
}else{

remote_so.data.chatText = "" + username + ": " + ChatInput.text;
}
ChatInput.text = "";
}

For the onSync function we call the list and pass the user names to an array and display them in the userlist. we will also pass the chatText to the output and set the scrollbar positions.

remote_so.onSync = function(list){
	if (remote_so.data.chatText != undefined){
		ChatOutput.text += remote_so.data.chatText;
		ChatOutput.vPosition = ChatOutput.maxVPosition;
	}
	var userArray:Array = remote_so.data.users.split(",");
	Userlist.dataProvider = userArray;
}

That’s all…not bad eh! For the skinning I just used some basic setStyles. I hope this helped.

5 Responses to “red5 chat revisited”

  1. Nacho Says:

    Other problem.
    You must use flush function to change the so value.
    Example: remote_so.data.flush();

    See you…


  2. Nacho Says:

    Problems:
    You must use a server side code to erase disconected users from the list, if not disconnected users will be showing on list.
    It’s better to connect users in login.
    Email me for more info. Excuse me for my poor english.


  3. kevin Says:

    Hi,
    Any chance to give away your source files?
    Thanks.


  4. webmaster Says:

    Kevin,

    I have not spent anytime on the chat tool recently, been very busy with other projects. There is still a lot of work to be done.

    All the existing source is in the post. if you have anymore questions let me know brendan (a) backspacestudios dot com


  5. Markus Says:

    hi bros happy that their is a site where we can talk about the red5 chat guys, can someone please, help me to make a room list with List Component.

    Hope yes
    bye


Leave a Reply