Saturday, August 25, 2007

Adding client information with every client in Red5

In Red5 forum, I have seen so many times, developers are asking for custom client id to identify a client. Below I will try to explain how can one add additional client information with every client connected to your application.

First we will create a client object--

public class Client{
String clientId = null;
String clienName = null;
String clientRole = null;

public String getRole(){
return clientRole;
}
public String getName(){
return clientName;
}
public String getId(){
return clientId;
}
public void setRole(String role){
clientRole = role;
}
public void setName(String name){
clientName = name;
}
public void setId(String id){
clientId = id;
}
}

Now we are ready with our client object, We will add this client object with the IClient in Red5 like below

public boolean roomConnect(IConnection iconnection, Object params[]){
if(!super.roomConnect(iconnection, params)){
log.info((new StringBuilder()).append("Application failed to connect room: ").append(iconnection.getScope().getName()).toString());
return false;
}
else{
log.info((new StringBuilder()).append("Application room connect initiated for room ").append(iconnection.getScope().getName()).append(": ").toString());

//We will add our client information right here
Client client = new Client();
client.setId(params[0].toString());
client.setName(params[1].toString());
client.setRole(params[2].toString());
iconnection.getClient().setAttribute("client", client);

return true
}
}

public boolean roomJoin(IClient iclient, IScope iscope){

/*Here you can see how to access your client information throughout the application*/

Client client = ((Client)iclient.getAttribute("client"));
String clientName = client.getName();
String clientId = client.getId();
String clientRole = client.getRole();

return true;
}

This way you can have your own client id's names and roles for different clients.

To create new Red5 application follow my previous post here.

Daily Technology Tips

Catch me at Mashable

PayPal

Sign up for PayPal and start accepting credit card payments instantly.

Blog Explosion


Bloglines

Blogrush


BlogsByCategory.com