Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Between the time an instance is created and destroyed, a number of things can happen.
- To simplify how things work, they are divided into three sections: startup, midlife,
- and shutdown.
- Each application object is a singleton object. Each instance gets it's own a
- pplication object which is an instance of the Application class.
- These are all the standard event handler method of the application object
- */
- /***************************
- Startup
- ***************************/
- application.onAppStart = function() {
- //A. onAppStart is where to Initialize counters, variables, id's, etc
- trace("onAppStart> "+application.name+" is starting at "+new Date());
- //B. You can set up a Server-side shared object to synchronize clients
- this.so = SharedObject.get(application.name+".com", true);
- //C. This is the proper way to set default variables. It allows for expansion
- if (this.so.getProperty("t" == undefined)) {
- }
- if (this.so.getProperty("foo" == undefined)) {
- }
- //Always assign unique ID's on the Server-Side because it's single threaded
- this.nextUserId = 0;
- };
- application.onStatus = function(info) {
- trace("onStatus> info.level: "+info.level+", info.code: "+info.code);
- trace("onStatus> info.description: "+info.description);
- trace("onStatus> info.details: "+info.details);
- };
- application.onConnect = function(p_client, userName, password) {
- //A. Assign a uniqueID for any user who logs in
- //p_client.userId = this.nextUserId++;
- //B. Decide is a client needs a userName
- p_client.userName = userName;
- //C. Decide is you want to give a client user read/write access
- //p_client.writeAccess = "/public";
- //p_client.readAccess = "/";
- //D. Inform the user that they have made a success connection
- application.acceptConnection(p_client);
- trace("onConnect> client.ip: "+p_client.ip);
- trace("onConnect> client.agent: "+p_client.agent);
- trace("onConnect> client.referrer: "+p_client.referrer);
- trace("onConnect> client.protocol: "+p_client.protocol);
- };
- application.onDisconnect = function(p_client) {
- //A. Clear any session variables that may pertain to a client user
- // (SharedObject variables)
- trace("onDisconnect> client.userName: "+p_client.userName);
- trace("onDisconnect> disconnecting at: "+new Date());
- };
- /***************************
- Shutdown
- ***************************/
- application.onAppStop = function(info) {
- //A. For when the app stops
- trace("onAppStop> application.name: "+application.name);
- trace("onAppStop> stopping at "+new Date());
- trace("onAppStop> info.level: "+info.level);
- trace("onAppStop> info.code: "+info.code);
- trace("onAppStop> info.description: "+info.description);
- };
- /***************************
- MidLife
- ***************************/
- /*
- Below are methods that any client can call. You are also able to
- write such methods within onConnect like:
- ///////////////////////////////////////////////////
- application.onConnect = function(p_client){
- p_client.changeText = function(p_client){
- //Do Something
- }
- }
- ///////////////////////////////////////////////////
- The reason you may not want to do this is because every time
- a user connects, this function will be placed into memory.
- Therefore if many users connect, you could begin to find issues
- with memory allocation so it's much more efficient to use
- the psuedo Javascript Class called prototype.
- */
- Client.prototype.changeText = function(p_client) {
- };
- Client.prototype.getStreamLength = function(p_streamName) {
- trace("Stream.length: "+p_streamName+", "+Stream.length(p_streamName));
- return Stream.length(p_streamName);
- };
Add Comment
Please, Sign In to add comment