Posted By

chrisaiv on 12/06/07


Tagged

ssas fms fcs


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

yeco
thehumbledeveloper


Server-side ActionScript Notes


 / Published in: ActionScript
 

These are the standard event handlers for a new Application using the FMS.

  1. /*
  2. 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.
  3.  
  4. Each application object is a singleton object. Each instance gets it's own application object which is an instance of the Application class.
  5.  
  6. These are all the standard event handler method of the application object
  7. */
  8.  
  9. /***************************
  10. Startup
  11. ***************************/
  12. application.onAppStart = function ( ) {
  13. //A. onAppStart is where to Initialize counters, variables, id's, etc
  14. trace( "onAppStart> " + application.name + " is starting at " + new Date() );
  15.  
  16. //B. You can set up a Server-side shared object to synchronize clients
  17. this.so = SharedObject.get(application.name + ".com", true);
  18.  
  19. //C. This is the proper way to set default variables. It allows for expansion
  20. if(this.so.getProperty("t" == undefined)){}
  21. if(this.so.getProperty("foo" == undefined)){}
  22.  
  23. //Always assign unique ID's on the Server-Side because it's single threaded
  24. this.nextUserId = 0;
  25. };
  26. application.onStatus = function (info) {
  27. trace("onStatus> info.level: " + info.level + ", info.code: " + info.code);
  28. trace("onStatus> info.description: " + info.description);
  29. trace("onStatus> info.details: " + info.details);
  30. };
  31. application.onConnect = function (p_client, userName, password) {
  32. //A. Assign a uniqueID for any user who logs in
  33. //p_client.userId = this.nextUserId++;
  34.  
  35. //B. Decide is a client needs a userName
  36. p_client.userName = userName;
  37.  
  38. //C. Decide is you want to give a client user read/write access
  39. //p_client.writeAccess = "/public";
  40. //p_client.readAccess = "/";
  41.  
  42. //D. Inform the user that they have made a success connection
  43. application.acceptConnection(p_client);
  44.  
  45. trace("onConnect> client.ip: " + p_client.ip);
  46. trace("onConnect> client.agent: " + p_client.agent);
  47. trace("onConnect> client.referrer: " + p_client.referrer);
  48. trace("onConnect> client.protocol: " + p_client.protocol);
  49. };
  50. application.onDisconnect = function (p_client) {
  51. //A. Clear any session variables that may pertain to a client user (SharedObject variables)
  52. trace("onDisconnect> client.userName: " + p_client.userName)
  53. trace("onDisconnect> disconnecting at: " + new Date( ));
  54. };
  55. /***************************
  56. Shutdown
  57. ***************************/
  58. application.onAppStop = function (info) {
  59. //A. For when the app stops
  60. trace("onAppStop> application.name: " + application.name);
  61. trace("onAppStop> stopping at " + new Date( ));
  62. trace("onAppStop> info.level: " + info.level);
  63. trace("onAppStop> info.code: " + info.code);
  64. trace("onAppStop> info.description: " + info.description);
  65. };
  66. /***************************
  67. MidLife
  68. ***************************/
  69. /*
  70. Below are methods that any client can call. You are also able to write such methods within onConnect like:
  71.  
  72. ///////////////////////////////////////////////////
  73. application.onConnect = function(p_client){
  74. p_client.changeText = function(p_client){
  75. //Do Something
  76. }
  77. }
  78. ///////////////////////////////////////////////////
  79.  
  80. 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 fing issues with memory allocation so it's much more efficient to use the psuedo Javascript Class called prototype.
  81. */
  82. Client.prototype.changeText = function(p_client){
  83.  
  84. }
  85. Client.prototype.getStreamLength = function(p_streamName) {
  86. trace("Stream.length: " + p_streamName + ", " + Stream.length(p_streamName));
  87. return Stream.length(p_streamName);
  88. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: jinpingv on April 8, 2008

Very helpful. Thanks for sharing

Posted By: jinpingv on April 8, 2008

One Question: How to implement a function in client side with AS3 that will be called by FMS2.0. I know in AS2, client side code is like:

    var my_nc:NetConnection = new NetConnection();
    my_nc.connect("rtmp://localhost/LiveStreams");

    my_nc.someFunction=function () {
        //do sth;
}; Then, in Server side, I can invoke this client function by:

application.onConnect = function(client) { // accept the new client's connection application.acceptConnection(client); client.call("someFunction", new someHandler()); }

someHandler = function(){ this.onResult = function(res){ trace("random num: " + res); } this.onStatus = function(info){ trace("failed and got:" + info.code); }

};

Do you know how to do that with AS3 in client? Thank you very much.

Posted By: jinpingv on April 8, 2008

One Question: How to implement a function in client side with AS3 that will be called by FMS2.0. I know in AS2, client side code is like:

    var my_nc:NetConnection = new NetConnection();
    my_nc.connect("rtmp://localhost/LiveStreams");

    my_nc.someFunction=function () {
        //do sth;
}; Then, in Server side, I can invoke this client function by:

application.onConnect = function(client) { // accept the new client's connection application.acceptConnection(client); client.call("someFunction", new someHandler()); }

someHandler = function(){ this.onResult = function(res){ trace("random num: " + res); } this.onStatus = function(info){ trace("failed and got:" + info.code); }

};

Do you know how to do that with AS3 in client? Thank you very much.

Posted By: jinpingv on April 9, 2008

One Question: How to implement a function in client side with AS3 that will be called by FMS2.0. I know in AS2, client side code is like:

    var my_nc:NetConnection = new NetConnection();
    my_nc.connect("rtmp://localhost/LiveStreams");

    my_nc.someFunction=function () {
        //do sth;
}; Then, in Server side, I can invoke this client function by:

application.onConnect = function(client) { // accept the new client's connection application.acceptConnection(client); client.call("someFunction", new someHandler()); }

someHandler = function(){ this.onResult = function(res){ trace("random num: " + res); } this.onStatus = function(info){ trace("failed and got:" + info.code); }

};

Do you know how to do that with AS3 in client? Thank you very much.

Posted By: chrisaiv on May 21, 2008

Sorry for the late reply.

One example where I needed to make a request to AS1 server-side code using AS3 was to retreive the length of an mp3. In my example, setNsDuration is actually a function which will receive a parameter from the FMS2.

//Retreive the Length of the Song from FMS and set it to a variable nc.call("getStreamLength", new Responder(setNsDuration), mp3:filename);

function setNsDuration(length:Number):void{ someVariable = length; }

You need to login to post a comment.