www.pudn.com > videoChat.zip > main.asc


 
// trim( ) removes whitespace from the beginning and end of a string. 
function trim (str) { 
  if (typeof str != "string") return ""; // Make sure str is a string. 
  str = str.replace(/^\s*/, ""); // Trim leading spaces. 
  str = str.replace(/\s*$/, ""); // Trim trailing spaces.   
  str = str.replace(/\n/g, ""); // Remove new lines. 
  str = str.replace(/\r/g, ""); // Reove carriage returns. 
  str = str.replace(/\t/g, ""); // Remove tabs. 
  return str; 
} 
 
// Get a temporary (non-persistent) RSO for a read-only list of usernames. 
application.onAppStart = function ( ) { 
  userList_so = SharedObject.get("public/userList"); 
}; 
 
/* Accept a client whose username is a unique, non-empty string 
* and update the userList shared object. 
* Each slot value in the userList is the path to which each client 
* has write access and where other clients should look for 
* a stream to which to subscribe. 
*/ 
application.onConnect = function (client, userName) { 
  userName = trim(userName); 
  if (userName.length == 0) { 
    application.rejectConnection(client, {msg: "Blank or missing user name."}); 
    trace("Blank or missing user name."); 
    return; 
  } 
 
  var userPath = userList_so.getProperty(userName); 
  if (userPath) { 
    application.rejectConnection(client, 
      {msg: "The user name '" + userName + "' is already in use."}); 
    trace("The user name '" + userName + "' is already in use."); 
    return; 
  } 
   
  client.readAccess = "/public"; 
  client.writeAccess = "public/chat;public/textchat"; 
 
   
  client.userName = userName; 
  userList_so.setProperty(userName, "public/chat/" + userName); 
  return true; 
}; 
 
// Delete records of clients when they disconnect. 
application.onDisconnect = function (client) { 
  userList_so.setProperty(client.userName, null); 
};