Thanks for the kind words first of all. Secondly, I have looked at your code and I shall help you if I have spare time... just understand that my time is scarce right now.

Paul

On 10/18/06, Sanjeev <[EMAIL PROTECTED]> wrote:
Hello Every One.,

This is Kumar.

Iam trying the Red5 things from the last 3Months.
Red5 is truly Rocking..Thanks for all the Masters and the Supporters who
are making this a Big Deal in Communication Servers arena.


I am very new to Java and learning the things from Online tutorials and
trying my self go well with the Red5 coding.I have good Knowledge of the
FCS and FMS.I can make it go and i also made a chat Application in it.I
want to make it online but FCS is Luxury .so I got much interested in
the Red5.

The thing is Iam migrating to Red5 but cant make it work always
properly..I coded the things without any errors,but the result is not
coming.Can anyone go through the things  and  help me find  the pit
holes in my codes.
the chat is much like a conference..where one talks with the users
online and waiting in the Queue,i can talk with the one first in the
queue and disconnect him(ring a disconnect bell) and then connect with
new waiting in the queue(ring a connect bell).

Here is  the FCS part .asc file..

load ( "framework.asc" );
load ( "components/chat.asc");
load ( "components/avpresence.asc");

load ( "adminSettings.asc" );<-- contains the admin password and
username i got that..
load ( "strings.asc");<-- has an error message's string..

application. {
    trace("onAppStart");
    adminStatus_so = SharedObject.get("adminStatus", false);
    adminStatus_so.setProperty("adminIsIn", false);

    userList_so = SharedObject.get("userList", false);
    var list = new Array();
    userList_so.setProperty("list",list);


    application.clientsByID = new Object();
}

application. userName, userPwd)
{
    client.userName = userName;

    if (userName == "__mainPage__")
    {
        client.userID = client.__ID__;

         client.putMeInLine = function(userID, userName) {
            trace("putMeInLine:"+userID+","+userName);
            application.clientsByID[userID] = this;
            addToLine(userID, userName);
        }
        client.removeMeFromLine = function(userID) {
            trace("removeMeFromLine:"+userID);
            removeFromList(userID);
        }
        client.setName = function(name) {
            trace("setName:"+name);
            gFrameworkFC.getClientGlobals(this).username = name;
            return "ack";
        }
        client.setDomainName = function(name) {
            trace("setDomainName:"+name);
            userList_so.setProperty("userdomainname",name);
            return "ack";
        }
        application.acceptConnection(client);

        client.userBell = function(usr){
            userList_so.send("userConnectBell",usr);
        }
    }
    else if (userName == adminUserName)
    {
        if (userPwd == adminUserPassword) {

            client.nextUser = function() {
                var list = userList_so.getProperty("list");
                trace("nextUser, booting "+list[0].userID);
                removeFromList(list[0].userID);
            }

            client.sendURL = function(url) {
                trace("sendURL:"+url);
                var list = userList_so.getProperty("list");
                trace("client id:"+list[0].userID);
                trace("client:"+application.clientsByID[list[0].userID]);

application.clientsByID[list[0].userID].call("getURL",null,url);
            }

            adminStatus_so.setProperty("adminIsIn",true);
            gFrameworkFC.getClientGlobals(client).username = userName;
            application.acceptConnection(client);
        } else {
            application.rejectConnection(client, {message:
application.strings [0]});
        }
    }
}

application. userName, userPwd) {
    trace("onConnectAccept:"+userName+","+userPwd);

    if (userName == "__mainPage__")
    {
        trace("calling getID with:"+client.userID);
        client.call("getID", null, client.userID);
    }
}

application. {
    trace("onDisconnect");
    if (client.userName == adminUserName) {
        adminStatus_so.setProperty("adminIsIn", false);
    } else {
        removeFromList(client.userID);
        userList_so.send("userDisconnectBell", client.userName);

    }
}

function addToLine(userID, userName) {
    trace("addToLine:"+userID+", "+userName);
    var list = userList_so.getProperty("list");
    list.push ({userID: userID, userName:userName});
    userList_so.setProperty("list",list);
}

function removeFromList(userID) {
    trace("removeFromList:"+userID);
    application.clientsByID[userID] = null;
    delete application.clientsByID[userID];

    var list = userList_so.getProperty("list");
    var newList = new Array();
    for (var i=0; i<list.length; i++) {
        if (list[i].userID != userID) {
            newList.push({userID: list[i].userID,
userName:list[i].userName});
        }
    }
    userList_so.setProperty("list",newList);
}

My Red5 part is much of the code from fitcdemo..

package ChatSystem;

import java.util.List;
import java.util.Iterator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.red5.server.adapter.ApplicationAdapter ;
import org.red5.server.api.IClient;
import org.red5.server.api.IConnection;
import org.red5.server.api.IScope;
import org.red5.server.api.Red5;
import org.red5.server.api.service.IPendingServiceCall;
import org.red5.server.api.service.IPendingServiceCallback;
import org.red5.server.api.service.IServiceCapableConnection;
import org.red5.server.api.stream.IBroadcastStream;
import org.red5.server.api.stream.IPlayItem;
import org.red5.server.api.stream.IPlaylistSubscriberStream;
import org.red5.server.api.stream.IStreamAwareScopeHandler;
import org.red5.server.api.stream.ISubscriberStream;
import org.red5.server.api.so.ISharedObject ;



public class CSApplication extends ApplicationAdapter implements
IStreamAwareScopeHandler, IPendingServiceCallback {

    public String adminUserName = " Admin";
    public String adminUserPassword = "pwd";
    public String userName;
    public String userPwd;
    //private boolean persistent;
    public String URL;
    String[] clientsByID = new String[100];

    private static final Log log = LogFactory.getLog (CSApplication.class);

    public boolean appStart(IScope scope) {
        // initiating the handler here
        log.info("Client is connected ");

        log.info("Creating Shared Objects ");
        createSharedObject(scope, "adminStatus", true);
        ISharedObject adminStatus_so = getSharedObject(scope,
"adminStatus");
        adminStatus_so.removeAttributes();
        adminStatus_so.setAttribute("adminIsIn", false);

        createSharedObject(scope, "userList", true);
        //ISharedObject userList_so = getSharedObject(scope, "userList");
        //userList_so.setAttribute("List",list);
        //userList_so.removeAttributes();

        return true;
    }
    @Override
    public boolean appConnect(IConnection conne, Object[] params) {
        IServiceCapableConnection service = (IServiceCapableConnection)
conne;
        log.info("Client is connected " + conne.getClient().getId() + "
conne " + conne);
        log.info("Setting stream id as : "+ getClients().size()); //
just a unique number


        service.invoke("setId", new Object[]{conne.getClient().getId()},
this);
        return true;
    }
    //@Override
    public boolean appJoin(IClient client, IScope scope, String
userName, String userPwd) {
        log.info("Client joined app " + client.getId());
        IConnection conne = Red5.getConnectionLocal();
        client.setAttribute("userName",userName);
        client.setAttribute("userPwd",userPwd);
        ISharedObject UserList = getSharedObject(scope,"UserList");
        if (client.getAttribute(userName)== "__mainPage__"){
            //ISharedObject UserList = getSharedObject(scope,"UserList");
            UserList.setAttribute(client.getId(),userName);
        }
        else if(userName == adminUserName){
            if(userPwd == adminUserPassword){
                String IDofClient = conne.getClient ().getId();
                removeFromList(IDofClient);
                //URL notifications
                URLNotify(IDofClient,URL);
                //<- Find the Notification way
                ISharedObject adminStatus_so = getSharedObject(scope,
"adminStatus");
                adminStatus_so.setAttribute("adminIsIn", true);
                this.userName = userName;
            }
            rejectClient(conne.getClient());
        }
        return true;
    }
    public void putMeInLine(String userID, String userName) {
        log.info("putMeInLine:"+userID+","+userName);
        //ISharedObject UserList_so = getSharedObject(scope,"UserList");
        clientsByID[1]= userID;
        addToLine(userID, userName);
    }
public String URLNotify(String clientID,String URL){
    // write a Iterator to find the specied userId and then send him the URL
    return URL;
}
public void addToLine(String userID,String userName){
    ISharedObject UserList_so = getSharedObject(scope,"UserList");
    UserList_so.setAttribute(userID,userName);
}
public void removeMeFromLine(String userId){
    ISharedObject UserList_so = getSharedObject(scope,"UserList");
    UserList_so.removeAttribute(userId);
}
public boolean removeFromList(String ID)
{
    log.info("removeFromList:"+ID);
    ISharedObject userList_so = getSharedObject(scope, "userList");
    //list = userList_so.getAttributes("list");
    Object[]list = new Object[100];
    //list = userList_so.getData(ID);
    for (int i=0; i<list.length; i++) {
        list[i] = userList_so.getAttribute(ID);
    }
    if (userList_so.hasAttribute(ID)){
    for (int i=0; i<list.length; i++) {
    if (list[i] == userList_so.getAttribute(ID)) {
        this.removeAttribute(ID);
    }
    }
    return true;
}return false;
}
public String setName(String name){
        log.info("setName:"+name);
        userName= name;
        return "ack";
    }
public String setDomainName(String name) {
            log.info("setDomainName:"+name);
            ISharedObject userList_so = getSharedObject(scope, "userList");
            userList_so.setAttribute("userdomainname",name);
            return "ack";
        }
public boolean userBell(String userId){
    IConnection current = Red5.getConnectionLocal();
    Iterator<IConnection> itr = scope.getConnections();
    while ( itr.hasNext()) {
        IConnection conne = itr.next();
        IServiceCapableConnection service = (IServiceCapableConnection)
conne;
        if (conne.equals(current))
            service.invoke("userBell");
    }
    return true;
}

public void streamPublishStart(IBroadcastStream stream) {
    // Notify all the clients that the stream had been started
    log.debug("Starting the Stream Broadcast: "+stream.getPublishedName());
    IConnection current = Red5.getConnectionLocal();
    Iterator<IConnection> itr = scope.getConnections();
    while (itr.hasNext()) {
        IConnection conne = itr.next();
        if (conne.equals (current))
            // Current client Should not be Notified
            continue;

        if (conne instanceof IServiceCapableConnection) {
            ((IServiceCapableConnection) conne).invoke("newStream", new
Object[]{stream.getPublishedName()}, this);
            log.debug("Now sending notification to "+conne);
        }
    }
}

public void streamBroadcastStart(IBroadcastStream stream) {
}

public void streamBroadcastClose(IBroadcastStream stream) {
}

public void streamSubscriberStart(ISubscriberStream stream) {
}

public void streamPlaylistItemStop(IPlaylistSubscriberStream stream,
IPlayItem item) {

}

public void streamPlaylistItemPlay(IPlaylistSubscriberStream stream,
IPlayItem item, boolean isLive) {
}

public void streamPlaylistVODItemPause(IPlaylistSubscriberStream stream,
IPlayItem item, int position) {

}

public void streamPlaylistVODItemResume(IPlaylistSubscriberStream
stream, IPlayItem item, int position) {

}

public void streamPlaylistVODItemSeek(IPlaylistSubscriberStream stream,
IPlayItem item, int position) {

}

public void streamSubscriberClose(ISubscriberStream stream) {

}
/**
* Get streams. called from client
*
* @return iterator of broadcast stream names
*/
public List<String> getStreams(){
    IConnection conne = Red5.getConnectionLocal();
    return getBroadcastStreamNames(conne.getScope());
}

/**
* Handle callback from service call.
*/
public void resultReceived(IPendingServiceCall call) {
    log.info("Received result " + call.getResult() + " for " +
call.getServiceMethodName());
}
public void appDisconnect(IConnection conne,IBroadcastStream
stream,IScope scope) {
    log.info("Application is disconnected ");
    IClient client = conne.getClient();
    if (client.equals(adminUserName)&& scope == conne.getScope()){
        ISharedObject adminStatus_so = getSharedObject(scope,
"adminStatus");
        adminStatus_so.beginUpdate();
        adminStatus_so.setAttribute("adminIsIn", false);
        stream.close();
        conne.close();
        super.disconnect (conne,scope);
        adminStatus_so.endUpdate();
    }
    else
    {
        ISharedObject userList_so = getSharedObject(scope, "userList");
        userList_so.beginUpdate();
        removeFromList( conne.getClient().getId());
        stream.close();
        conne.getClient().disconnect();
        super.disconnect(conne,scope);
        userList_so.endUpdate();
    }
}
}


Thanks in Advance,
Kumar.


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



--
The early bird may get the worm, but the second mouse gets the cheese.
_______________________________________________
Red5 mailing list
[email protected]
http://osflash.org/mailman/listinfo/red5_osflash.org

Reply via email to