// Server side actionscript (a bit different from client side as3) // Array to hold clients videoStreams = new Array(null,null,null,null); // Fill it up with null values // Our live server side stream // http://help.adobe.com/en_US/FlashMediaServer/3.5_SS_ASD/WS5b3ccc516d4fbf351e63e3d11a11afc95e-7e42.html var serverStream = null; var currentLive = null; var switchInterval = null; // On Start (when the application is first instantiated) application.onAppStart = function() { application.allowDebug = true; trace("Starting Conference Application"); serverStream = Stream.get("live"); serverStream.onStatus = function(info) { trace(info.code); }; switchInterval = setInterval(switchStream,10000); }; // When someone connects from Flash application.onConnect = function(newClient) { trace("New Client Connecting"); // Client object // creating a property called clientName var done = false; for (i = 0; i < videoStreams.length && !done; i++) { if (videoStreams[i] == null) { newClient.clientName = "stream" + i; trace(newClient.clientName); videoStreams[i] = newClient; trace("New Client: " + newClient.clientName); done = true; } } if (!done) { // If all of the positions are in use // Don't let a new person connect application.rejectConnection(newClient); trace("sorry, full"); } // Accept the connection application.acceptConnection(newClient); // Function that get's called by the client to determine where to go newClient.streamSelect = function() { trace("Stream " + newClient.clientName + " used"); //Send the property to Client object return newClient.clientName; }; }; application.onDisconnect = function(oldClient) { for (i = 0; i < videoStreams.length; i++) { if (videoStreams[i] != null) { if (videoStreams[i].clientName == oldClient.clientName) { videoStreams[i] = null; } } } } switchStream = function() { var switched = false; for (i = 0; i < videoStreams.length && !switched; i++) { if (videoStreams[i] != null && videoStreams[i].clientName != currentLive) { trace("Switching to " + videoStreams[i].clientName); serverStream.play(videoStreams[i].clientName,-1,-1); switched = true; currentLive = videoStreams[i].clientName; } } if (!switched) { trace("Didn't switch, no valid streams"); } }