Hi ,

I tried with some basic concepts in JAVA and I got succeed in the user
list maintenance in Red5 server. I have attached my source here.... :)

//////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////



package mydemo;

import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.IConnection;
import org.red5.server.api.IScope;
import org.red5.server.api.IClient;
import org.red5.server.api.Red5;
import org.red5.server.api.service.IServiceCapableConnection;
import org.red5.server.api.service.ServiceUtils;

public class Application extends ApplicationAdapter {

        List<String> MyUsersList = new ArrayList<String>();
        String UserNames[];
        int UserCount;
        String listitems = "";
        public void getUserlists() {
                listitems = "";
                Iterator<String> it = MyUsersList.iterator();
                while (it.hasNext()) {
                        String user = it.next();
                        if (user != "")
                                listitems += user + ",";
                }
                IConnection Iconn = Red5.getConnectionLocal();
                IScope scope = Iconn.getScope();
                Iterator<IConnection> itr = scope.getConnections();
                while (itr.hasNext()) {
                        IConnection conn = itr.next();
                        if (conn instanceof IServiceCapableConnection) {
                                ((IServiceCapableConnection) conn).invoke(
                                                "updateUsersListPannel", new 
Object[] { listitems });
                        }
                }

        }

        public void addToUserList(String newUser, String id) {
                boolean canadd = true;
                Iterator<String> it = MyUsersList.iterator();
                while (it.hasNext()) {
                        String existingUser = it.next();
                        if (existingUser.equals(newUser)) {
                                canadd = false;
                                return;
                        }
                }
                int idval = Integer.parseInt(id);
                if (canadd) {
                        MyUsersList.add(idval, newUser);
                        IConnection Iconn = Red5.getConnectionLocal();
                        IScope scope = Iconn.getScope();
                        Iterator<IConnection> itr = scope.getConnections();
                        while (itr.hasNext()) {
                                IConnection conn = itr.next();
                                if (conn instanceof IServiceCapableConnection) {
                                        ((IServiceCapableConnection) conn)
                                                        
.invoke("ShowNewUserEntry",
                                                                        new 
Object[] { newUser });
                                }
                        }
                }
        }

        @Override
        public boolean appStart(IScope room) {
                MyUsersList.removeAll(MyUsersList);
                return true;
        }

        @Override
        public boolean appConnect(IConnection conn, Object[] params) {
                addToUserList(params[0].toString(), conn.getClient().getId());
                return true;
        }

        public void appDisconnect(IConnection Iconn) {
                IClient client = Iconn.getClient();
                IScope scope = Iconn.getScope();
                String connid = client.getId();
                Iterator<IConnection> it = scope.getConnections();
                while (it.hasNext()) {
                        IConnection conn = it.next();
                        if (conn instanceof IServiceCapableConnection) {
                                ((IServiceCapableConnection) 
conn).invoke("QuitUser",
                                                new Object[] { MyUsersList
                                                                
.get(Integer.parseInt(connid)) });
                        }
                }
                MyUsersList.set(Integer.parseInt(connid), "");
                getUserlists();
        }

        public void sendMyLobbyMessage(String Msg, String MsgSender) {
                ServiceUtils.invokeOnAllConnections("sendMsgToLobby", new 
Object[] {
                                MsgSender, Msg });
        }
}

///////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////


I am using the LISTs concept is java. But, if anyone knows better idea
than this , keep posting to this forum......




Thanks and Regards,

Arun.A


-- 
a_arunonline
------------------------------------------------------------------------
a_arunonline's Profile: 12
View this thread: http://www.nixspot.com/red5/showthread.php?t=1101


_______________________________________________
Red5 mailing list
[email protected]
http://osflash.org/mailman/listinfo/red5_osflash.org

Reply via email to