//let me view the stream in the console window// application.allowDebug = true; var __slsTourStream; var __slsLiveStream_1; var __livePublishing; var __chatSo; var __feedbackSo; var __clientsCount; var __feedbackInterval; var __allFeedbackScores; application.onAppStart = function () { __chatSo = SharedObject.get("chat", false); __feedbackSo = SharedObject.get("feedback", false); __clientsCount = 0; __feedbackInterval = setInterval(consolidateFeedback, 1000); __livePublishing = false; __allFeedbackScores = []; __slsLiveStream_1 = Stream.get("slsLiveGlobal_1"); __slsLiveStream_1.onStatus = function (infoObj) { trace("__slsLiveStream_1.onStatus ---------->"); for (var props in infoObj) { trace(props+" = "+infoObj[props]); } if(infoObj.code == "NetStream.Play.PublishNotify") { switchStream (true); } if(infoObj.code == "NetStream.Play.UnpublishNotify") { switchStream (false); } } __slsLiveStream_1.play("slsLive_1", -1, -1); } application.onAppStop = function () { clearInterval(__feedbackInterval); } application.onConnect = function (clientObj, clientName, clientPassword) { trace("application.onConnect("+clientObj+","+clientName+","+clientPassword+")"); clientObj.audioSampleAccess = "/"; clientObj.videoSampleAccess = "/"; trace("clientObj.audioSampleAccess = "+clientObj.audioSampleAccess); trace("clientObj.videoSampleAccess = "+clientObj.videoSampleAccess); //fme cannot connect as it doesn't have name/password variables// if(!clientPassword) { //allow fme to connect// trace("acceptConnection() for fme"); this.acceptConnection(clientObj); return; } //if client has a valid password allow the conn// if (clientPassword == "sls") { var clientDetails = {}; clientDetails.agent = clientObj.agent; clientDetails.referrer = clientObj.referrer; clientDetails.ip = clientObj.ip; clientDetails.name = clientName+" ["+__clientsCount+"]"; clientDetails.index = __clientsCount; clientObj.client = clientDetails; trace("Platform = "+clientDetails.agent); trace("Referrer = "+clientDetails.referrer); trace("IP = "+clientDetails.ip); trace("Name = "+clientDetails.name); trace("Index = "+clientDetails.index); __clientsCount++; trace("acceptConnection()"); this.acceptConnection(clientObj); clientObj.sendChatMessage = function (pMsg) { trace("sendChatMessage("+pMsg+")"); __chatSo.setProperty("chatMsg", pMsg); } clientObj.updateFeedback = function (pClientName, pScore) { trace("updateFeedback("+pClientName+", "+pScore+")"); __feedbackSo.setProperty(pClientName, pScore); } clientObj.call("clientInfo", null, clientDetails); } else { trace("rejectConnection()"); this.rejectConnection(clientObj, {message:"Invalid Password"}); } this.broadcastMsg("userStatus", this.clients.length); this.broadcastMsg("onLiveStreamUpdate", __livePublishing); } application.onDisconnect = function (clientObj) { trace("clientObj.client.name = "+clientObj.client.name); __feedbackSo.setProperty(clientObj.client.name, null); var htmlMsg = "

"+clientObj.client.name+": has left the building...

"; __chatSo.setProperty("chatMsg", htmlMsg); this.broadcastMsg("userStatus", this.clients.length); } function switchStream (isLivePublishing) { trace("switchStream ("+isLivePublishing+")"); __livePublishing = isLivePublishing; application.broadcastMsg("onLiveStreamUpdate", __livePublishing); } function consolidateFeedback() { trace("consolidateFeedback"); var score = 0; var voters = 0; var high = 0; var low = 100; var props = __feedbackSo.getPropertyNames(); for (var propValue in props) { var propData = __feedbackSo.getProperty(props[propValue]); //trace("propData = "+propData); score += propData; high = (propData > high) ? propData : high; low = (propData < low) ? propData : low; voters++; } var averageScore = (score/voters); var feedback = {averageScore:averageScore, highScore:high, lowScore:low, voters:voters}; __allFeedbackScores.push(feedback); application.broadcastMsg("feedbackData", feedback); }