Guest User

Untitled

a guest
Jun 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1.  
  2. /*
  3.  
  4. Between the time an instance is created and destroyed, a number of things can happen.
  5. To simplify how things work, they are divided into three sections: startup, midlife,
  6. and shutdown.
  7.  
  8. Each application object is a singleton object. Each instance gets it's own a
  9. pplication object which is an instance of the Application class.
  10.  
  11. These are all the standard event handler method of the application object
  12.  
  13. */
  14.  
  15.  
  16.  
  17. /***************************
  18.  
  19. Startup
  20.  
  21. ***************************/
  22.  
  23. application.onAppStart = function() {
  24.  
  25. //A. onAppStart is where to Initialize counters, variables, id's, etc
  26.  
  27. trace("onAppStart> "+application.name+" is starting at "+new Date());
  28.  
  29.  
  30.  
  31. //B. You can set up a Server-side shared object to synchronize clients
  32.  
  33. this.so = SharedObject.get(application.name+".com", true);
  34.  
  35.  
  36.  
  37. //C. This is the proper way to set default variables. It allows for expansion
  38.  
  39. if (this.so.getProperty("t" == undefined)) {
  40. }
  41.  
  42. if (this.so.getProperty("foo" == undefined)) {
  43. }
  44. //Always assign unique ID's on the Server-Side because it's single threaded
  45.  
  46. this.nextUserId = 0;
  47.  
  48. };
  49.  
  50. application.onStatus = function(info) {
  51.  
  52. trace("onStatus> info.level: "+info.level+", info.code: "+info.code);
  53.  
  54. trace("onStatus> info.description: "+info.description);
  55.  
  56. trace("onStatus> info.details: "+info.details);
  57.  
  58. };
  59.  
  60. application.onConnect = function(p_client, userName, password) {
  61.  
  62. //A. Assign a uniqueID for any user who logs in
  63.  
  64. //p_client.userId = this.nextUserId++;
  65.  
  66.  
  67.  
  68. //B. Decide is a client needs a userName
  69.  
  70. p_client.userName = userName;
  71.  
  72.  
  73.  
  74. //C. Decide is you want to give a client user read/write access
  75.  
  76. //p_client.writeAccess = "/public";
  77.  
  78. //p_client.readAccess = "/";
  79.  
  80.  
  81.  
  82. //D. Inform the user that they have made a success connection
  83.  
  84. application.acceptConnection(p_client);
  85.  
  86.  
  87.  
  88. trace("onConnect> client.ip: "+p_client.ip);
  89.  
  90. trace("onConnect> client.agent: "+p_client.agent);
  91.  
  92. trace("onConnect> client.referrer: "+p_client.referrer);
  93.  
  94. trace("onConnect> client.protocol: "+p_client.protocol);
  95.  
  96. };
  97.  
  98. application.onDisconnect = function(p_client) {
  99.  
  100. //A. Clear any session variables that may pertain to a client user
  101. // (SharedObject variables)
  102.  
  103. trace("onDisconnect> client.userName: "+p_client.userName);
  104.  
  105. trace("onDisconnect> disconnecting at: "+new Date());
  106.  
  107. };
  108.  
  109. /***************************
  110.  
  111. Shutdown
  112.  
  113. ***************************/
  114.  
  115. application.onAppStop = function(info) {
  116.  
  117. //A. For when the app stops
  118.  
  119. trace("onAppStop> application.name: "+application.name);
  120.  
  121. trace("onAppStop> stopping at "+new Date());
  122.  
  123. trace("onAppStop> info.level: "+info.level);
  124.  
  125. trace("onAppStop> info.code: "+info.code);
  126.  
  127. trace("onAppStop> info.description: "+info.description);
  128.  
  129. };
  130.  
  131. /***************************
  132.  
  133. MidLife
  134.  
  135. ***************************/
  136.  
  137. /*
  138.  
  139. Below are methods that any client can call. You are also able to
  140. write such methods within onConnect like:
  141.  
  142.  
  143.  
  144. ///////////////////////////////////////////////////
  145.  
  146. application.onConnect = function(p_client){
  147.  
  148. p_client.changeText = function(p_client){
  149.  
  150. //Do Something
  151.  
  152. }
  153.  
  154. }
  155.  
  156. ///////////////////////////////////////////////////
  157.  
  158. The reason you may not want to do this is because every time
  159. a user connects, this function will be placed into memory.
  160. Therefore if many users connect, you could begin to find issues
  161. with memory allocation so it's much more efficient to use
  162. the psuedo Javascript Class called prototype.
  163.  
  164. */
  165.  
  166. Client.prototype.changeText = function(p_client) {
  167.  
  168. };
  169.  
  170. Client.prototype.getStreamLength = function(p_streamName) {
  171.  
  172. trace("Stream.length: "+p_streamName+", "+Stream.length(p_streamName));
  173.  
  174. return Stream.length(p_streamName);
  175.  
  176. };
Add Comment
Please, Sign In to add comment