var cuServiceUrl="http://clientstat.castup.net/Report?";var cuPlayerEvent=1;var cuClientDebugEvent=3;var cuRolloverEvent=4;var cuMediaErrorEvent=5;var cuEntryQOSSampleEvent=6;var cuSeekEvent=7;var cuQOSGradeAlertPointPassedEvent=8;var cuFrameRateDiteriated=10;var cuQOSGradeChangedEvent=8;var cuUserInteractionEvent=12;var cuWatchEvent=13;var cuSessionSummaryEvent=14 var cuPlayingEndedEvent=15;var cuOrangeTimeStatusEvent=50;var cuOrangeTimePlayerStatusEvent=51;var cuOrangeTimeUserEvent=52;var cuCurrentGradeEvent=101;var cuBufferingCountTolerance=3;var cuQOSGradeAlertPoints=[80,60,40];var cuRolloverRegEx="://([^/?]*)(.*)";var cuClientIDRegEx="cu=(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})";var cuQOSBufferingTimeTolerance=9000;var cuQOSPlayingTimeTolerance=9000;var cuQOSImproveGradeStepTime=900000;var cuQOSImproveGradeStep=5;var cuQOSCurrentGradeWindow=60000;var cuCurrentQOSGradeSendInterval=30000;var cuSessionBufferingCountGradeFactor=10;var cuCurrentBufferingCountGradeFactor=20;var cuCurrentGradeFactor=1;var loggerContainerName="";var CU_WATCHDOG_INTERVAL=50;var CU_QOSUPDATE_INTERVAL=2000;var CU_PALYING_EVENT_TIMEOUT=5000;var culogger=null;function CUQOSManager(playerName,enableErater,logger,wrapper,communicator,sendEventOnQOSGradeChange) {this.playerName=playerName;this.enableErater=enableErater;this.sendEventOnQOSGradeChange=sendEventOnQOSGradeChange;this.componentID=0;this.clientID=CUUtilsGenrateGUID();this.initialEntryUrl="";this.playID=CUUtilsGenrateGUID(true);this.playStartTime=0;this.bufferingTime=0;this.loadingTime=0;this.qosGrade=100;this.currentQosGrade=100;this.qosCode=100;this.currentQosCode=100;this.liveWidgetContainer=null;this.currentMediaDuration=0;this.currentPlayingURL="Unknown";this.currentState="Unknown";this.eventOrder=1;this.currentEventOrder=1;this.savedEventOrder=1;this.sentPlayEvent=false;this.lastCurrentGradeSentTime=null;this.lastEventSentTime=null;this.entryQOSGradeAVG=0;this.entryQOSGradeMIN=100;this.QOSGradeAlertPointsSentFlags={};this.playingTimer=new CUUtilsTimer();this.loadingTimer=new CUUtilsTimer();this.bufferingTimer=new CUUtilsTimer();this.sessionTimer=new CUUtilsTimer();this.QOSUpdateInterval=-1;this.sendStartPlayingEventTimeOut=-1;this.sendSessionSampleEventTimeOut=-1;culogger=logger!=null&&typeof(logger)!="undefined"?logger:this.buildLogger();this.playerWrapper=wrapper!=null&&typeof(wrapper)!="undefined"?wrapper:this.buildWrapper(playerName);this.playerWrapper.addEvent(CUPlayerWrapper.ItemChangeEvent,this.itemChangeHandler,this);this.playerWrapper.addEvent(CUPlayerWrapper.StateChangeEvent,this.stateChangeHandler,this);this.playerWrapper.addEvent(CUPlayerWrapper.MediaErrorEvent,this.mediaErrorHandler,this);this.playerWrapper.addEvent(CUPlayerWrapper.SessionStartedEvent,this.sessionStartedHandler,this);this.playerWrapper.addEvent(CUPlayerWrapper.SessionEndedEvent,this.sessionEndedHandler,this);this.playerWrapper.addEvent(CUPlayerWrapper.EntryChangeEvent,this.entryChangeHandler,this);this.playerWrapper.addEvent(CUPlayerWrapper.PlayingStartedEvent,this.playingStartHandler,this);this.playerWrapper.addEvent(CUPlayerWrapper.RolloverEvent,this.rolloverHandler,this);this.playerWrapper.addEvent(CUPlayerWrapper.BufferingEvent,this.bufferingHandler,this);this.playerWrapper.addEvent(CUPlayerWrapper.PositionChangeEvent,this.positionChangeHandler,this);this.playerWrapper.addEvent(CUPlayerWrapper.ReconnectingEvent,this.reconnectingHandler,this);this.erater=this.buildErater(this.enableErater,this.playerWrapper);this.communicator=communicator!=null&&typeof(communicator)!="undefined"?communicator:this.buildCommunicator(cuServiceUrl);this.communicator.componentID=this.componentID;this.communicator.clientID=this.clientID;this.sessionGradeCalculator=this.buildSessionGradeCalculator(cuSessionBufferingCountGradeFactor);this.currentGradeCalculator=this.buildCurrentGradeCalculator(cuCurrentBufferingCountGradeFactor);var thisQOSManager=this;CUUtilsAddEvent("contextmenu",function(event){thisQOSManager.contextMenuHandler(event);},document);CUUtilsAddEvent("keydown",function(event){thisQOSManager.keydownHandler(event);},document);} CUQOSManager.GradeChangeEvent="gradeChange";CUQOSManager.prototype=new CUEventDispatcher;CUQOSManager.prototype.buildLogger=function() {var elem=document.getElementById(loggerContainerName);if(elem!=null) {return new HTMLLogger(elem);} if(typeof(console)!="undefined"&&console!=null) {return new FireBugLogger();} return new EmptyLogger();} CUQOSManager.prototype.buildWrapper=function(playerName) {return new CUWMVPlayerWrapper(playerName,true);} CUQOSManager.prototype.buildCommunicator=function(serviceURL) {return new CUCommunicator(serviceURL,0);} CUQOSManager.prototype.buildErater=function(enableErater,playerWrapper) {if(enableErater==true) return new CUErater(playerWrapper);else return new EmptyErater();} CUQOSManager.prototype.buildSessionGradeCalculator=function(bufferingCountGradeFactor) {return new CUGradeCalculator(-1,true,true,bufferingCountGradeFactor);} CUQOSManager.prototype.buildCurrentGradeCalculator=function(bufferingCountGradeFactor) {return new CUGradeCalculator(cuQOSCurrentGradeWindow,true,false,bufferingCountGradeFactor);} CUQOSManager.prototype.enableErate=function() {if(!this.enableErater) {this.enableErater=true;this.erater=this.buildErater(this.enableErater,this.playerWrapper);}} CUQOSManager.prototype.itemChangeHandler=function(args) {args.scope.initTimeouts();args.scope.initLoadingTimer();args.scope.sessionGradeCalculator.init();args.scope.currentGradeCalculator.init();args.scope.initQOSGradeAlertPointsSentFlags();args.scope.entryQOSGradeAVG=0;args.scope.entryQOSGradeMIN=100;args.scope.qosGrade=100;args.scope.currentQosGrade=100;args.scope.qosCode=100;args.scope.currentQosCode=100;if(args.scope.sentPlayEvent)args.scope.sendEndPlayingEvent();args.scope.lastEventSentTime==null args.scope.sentPlayEvent=false;args.scope.lookForClientID(args.newURL);} CUQOSManager.prototype.stateChangeHandler=function(args) {var newState=args.newState;var oldState=args.oldState;if(newState==2||newState==3||newState==6) {args.scope.loadingTime=args.scope.loadingTimer.stop();} if(newState==9||oldState==9||(oldState==1&&newState==3)) {args.scope.initPlayingTimer();} args.scope.currentState=newState;culogger.log("stateChangeHandler "+oldState+" "+newState);} CUQOSManager.prototype.mediaErrorHandler=function(args) {culogger.log("mediaErrorHandler "+args.mediaObject);args.scope.handlePlayerMediaError(args.mediaObject);} CUQOSManager.prototype.entryChangeHandler=function(args) {culogger.log("entryChangeHandler "+args.currentURL);args.scope.initialEntryUrl=args.currentURL;} CUQOSManager.prototype.initTimeouts=function() {clearTimeout(this.sendStartPlayingEventTimeOut);clearTimeout(this.sendSessionSampleEventTimeOut);} CUQOSManager.prototype.initPlayingTimer=function() {culogger.log("init playingTimer");this.playStartTime=0;this.playingTimer.start();} CUQOSManager.prototype.initLoadingTimer=function() {culogger.log("init loadingTimer");this.loadingTime=0;this.loadingTimer.start();} CUQOSManager.prototype.sessionStartedHandler=function(args) {culogger.log('sessionStartedHandler url='+args.URL);args.scope.initPlayingSession(args.URL);} CUQOSManager.prototype.sessionEndedHandler=function(args) {culogger.log('sessionEndedHandler url='+args.URL);args.scope.endPlayingSession(args.URL);} CUQOSManager.prototype.playingStartHandler=function(args) {culogger.log('playingStartHandler url='+args.URL);args.scope.handlePlayerStartPlaying(args.duration,args.URL,args.isUnique);} CUQOSManager.prototype.rolloverHandler=function(args) {culogger.log('rolloverHandler '+CUUtilsCleanVideoURL(args.oldURL)+" "+CUUtilsCleanVideoURL(args.newURL));args.scope.handleRollover(args.oldURL,args.newURL);} CUQOSManager.prototype.bufferingHandler=function(args) {if(args.start) {args.scope.bufferingTimer.start();culogger.log('bufferingHandler Started '+args.count);} else {args.scope.bufferingTime=args.scope.bufferingTimer.stop();args.scope.handleBufferingEnded(args.count);args.scope.updateQOSGrade();}} CUQOSManager.prototype.reconnectingHandler=function(args) {if(args.start) {args.scope.sendCurrentQOSGradeEvent();} else {args.scope.sendCurrentQOSGradeEvent();}} CUQOSManager.prototype.positionChangeHandler=function(args) {args.scope.handlePositionChanged(args.oldPosition,args.newPosition);} CUQOSManager.prototype.handlePlayerStartPlaying=function(clipDuration,clipURL,isUnique) {this.playStartTime=this.playingTimer.stop();this.savedEventOrder=this.eventOrder;this.eventOrder++;var thisQOSManager=this;this.currentMediaDuration=clipDuration;this.currentPlayingURL=clipURL;var currentMediaDurationInMiliSeconds=this.currentMediaDuration*1000;culogger.log("currentMediaDurationInMiliSeconds "+currentMediaDurationInMiliSeconds);clearTimeout(this.sendStartPlayingEventTimeOut);clearTimeout(this.sendSessionSampleEventTimeOut);this.sessionGradeCalculator.add(null,null,null,null,this.playStartTime);this.currentGradeCalculator.add(null,null,null,null,this.playStartTime);if(currentMediaDurationInMiliSeconds>CU_PALYING_EVENT_TIMEOUT) {this.sendStartPlayingEventTimeOut=setTimeout(function(){thisQOSManager.sendStartPlayingEvent();},CU_PALYING_EVENT_TIMEOUT);this.sendSessionSampleEventTimeOut=setTimeout(function(){thisQOSManager.sendSessionSampleEvent(clipURL);},60000);} else {this.sendStartPlayingEvent();} if(isUnique==true) {this.sendWatchEventEvent();}} CUQOSManager.prototype.sendEndPlayingEvent=function() {var playID=this.playID;var playerParams=this.buildEventParams();playerParams.Duration=this.getLastEventTimeGapInSeconds();this.communicator.sendEvent(cuPlayingEndedEvent,playID,playerParams);} CUQOSManager.prototype.sendStartPlayingEvent=function() {var playID=this.playID;var playerParams=this.buildEventParams(false);playerParams.EventOrder=this.savedEventOrder;this.sentPlayEvent=true;this.communicator.sendEvent(cuPlayerEvent,playID,playerParams);} CUQOSManager.prototype.sendWatchEventEvent=function() {var playID=this.playID;var playerParams=this.buildEventParams();this.lastEventSentTime=null;playerParams.Duration=this.getLastEventTimeGapInSeconds();this.communicator.sendEvent(cuWatchEvent,playID,playerParams);} CUQOSManager.prototype.handleRollover=function(oldURL,newURL) {var playID=this.playID;var playerParams=this.buildEventParams();this.communicator.sendEvent(cuRolloverEvent,playID,playerParams);this.sendCurrentQOSGradeEvent();} CUQOSManager.prototype.handleBufferingEnded=function(bufferingCount) {this.sessionGradeCalculator.add(null,null,bufferingCount,this.bufferingTime,null);this.currentGradeCalculator.add(null,null,bufferingCount,this.bufferingTime,null);} CUQOSManager.prototype.handlePositionChanged=function(oldPosition,newPosition) {culogger.log('handlePositionChanged old='+oldPosition+" new="+newPosition);var playID=this.playID;var playerParams=this.buildEventParams();playerParams.OldPosition=CUUtilsCheckInt(oldPosition);playerParams.CurrentPosition=CUUtilsCheckInt(newPosition);this.communicator.sendEvent(cuSeekEvent,playID,playerParams);} CUQOSManager.prototype.handlePlayerMediaError=function(mediaObject) {var playID=this.playID;var playerParams=this.buildEventParams();this.communicator.sendEvent(cuMediaErrorEvent,playID,playerParams);this.sendCurrentQOSGradeEvent();} CUQOSManager.prototype.handleUserEvent=function() {if(this.playerWrapper==null||!this.playerWrapper.hasPlayer()||!this.playerWrapper.hasMedia())return;var playID=this.playID;var playerParams=this.buildEventParams();var currentPostion=this.playerWrapper.getCurrentPostion();if(currentPostion!=null) {playerParams.CurrentPosition=CUUtilsCheckInt(currentPostion*10)/10;} this.communicator.sendEvent(cuClientDebugEvent,playID,playerParams);alert("Your viewing details were sent to CastUP");} CUQOSManager.prototype.sendSessionSampleEvent=function(url) {if(url==this.currentPlayingURL) {var playID=this.playID;var playerParams=this.buildEventParams();playerParams.AverageQOSGrade=this.entryQOSGradeAVG;playerParams.MinimumQOSGrade=this.entryQOSGradeMIN;this.communicator.sendEvent(cuEntryQOSSampleEvent,playID,playerParams);}} CUQOSManager.prototype.sendQOSGradeAlertPointEvent=function() {var playID=this.playID;var playerParams=this.buildEventParams();this.communicator.sendEvent(cuQOSGradeAlertPointPassedEvent,playID,playerParams);} CUQOSManager.prototype.sendQOSGradeChangeEvent=function() {var playID=this.playID;var playerParams=this.buildEventParams();playerParams.AverageQOSGrade=CUUtilsCheckInt(this.entryQOSGradeAVG);playerParams.MinimumQOSGrade=CUUtilsCheckInt(this.entryQOSGradeMIN);this.communicator.sendEvent(cuQOSGradeChangedEvent,playID,playerParams);} CUQOSManager.prototype.sendCurrentQOSGradeEvent=function() {var playID=this.playID;var playerParams=this.buildEventParams(false);playerParams=this.addCurrentQOSGradeParams(playerParams);playerParams.EventOrder=this.currentEventOrder;playerParams.Duration=this.getLastEventTimeGapInSeconds();this.currentEventOrder++;playerParams.QOSGrade=this.currentQosGrade;playerParams.QOSCode=this.currentQosCode;playerParams.SessionQOSGrade=this.qosGrade;this.communicator.sendEvent(cuCurrentGradeEvent,playID,playerParams);} CUQOSManager.prototype.sendFrameRateDiteriated=function() {var playID=this.playID;var playerParams=this.buildEventParams();this.communicator.sendEvent(cuFrameRateDiteriated,playID,playerParams);} CUQOSManager.prototype.sendSessionSummaryEvent=function() {var playID=this.playID;var playerParams=this.buildEventParams();playerParams.sessionDuration=this.sessionTimer.getElapsedTime();this.communicator.sendEvent(cuSessionSummaryEvent,playID,playerParams);} CUQOSManager.prototype.sendUserInteractionEvent=function(userAction) {if(this.playerWrapper.hasPlayer()) {var playID=this.playID;var playerParams=this.buildEventParams();playerParams.userAction=userAction;this.communicator.sendEvent(cuUserInteractionEvent,playID,playerParams);}} CUQOSManager.prototype.initPlayingSession=function(playURL) {this.playID=CUUtilsGenrateGUID();this.eventOrder=1;this.currentEventOrder=1;this.initQOSGradeAlertPointsSentFlags();var thisQOSManager=this;this.sessionTimer.init();clearInterval(this.QOSUpdateInterval);this.QOSUpdateInterval=setInterval(function(){thisQOSManager.interval();},CU_QOSUPDATE_INTERVAL);} CUQOSManager.prototype.endPlayingSession=function(playURL) {clearInterval(this.QOSUpdateInterval);this.sendSessionSummaryEvent();this.sendEndPlayingEvent();this.eventOrder=1;this.currentEventOrder=1;this.loadingTime=0;this.playStartTime=0;this.sentPlayEvent=false;this.playingTimer.stop();this.loadingTimer.stop();this.bufferingTimer.init();this.sessionGradeCalculator.init();this.currentGradeCalculator.init();} CUQOSManager.prototype.contextMenuHandler=function(event) {culogger.log('contextMenuHandler alt='+event.altKey+" ctrl="+event.ctrlKey+" shift="+event.shiftKey);if(event.shiftKey==true&&event.ctrlKey&&!event.altKey) {this.handleUserEvent();}} CUQOSManager.prototype.keydownHandler=function(event) {if(event!=null&&event.ctrlKey&&event.shiftKey&&event.keyCode==81) {}} CUQOSManager.prototype.lookForClientID=function(mediaURL) {var clientID=CUUtilsGetClientID(mediaURL);if(clientID!=null&&clientID.toString()!=""&&typeof(clientID)!="undefined"&&this.communicator.clientID!=clientID) {culogger.log('update clientID '+clientID) this.communicator.clientID=clientID;}} CUQOSManager.prototype.interval=function() {this.updateQOSGrade();} CUQOSManager.prototype.updateQOSGrade=function() {if(this.playerWrapper.hasPlayer()&&this.playerWrapper.hasNetwork()&&this.playerWrapper.getPlayState()==3&&this.playerWrapper.hasMedia()&&this.playerWrapper.getMediaUrl()!=null&&this.playerWrapper.getMediaUrl().length>0) {var frameRate=this.playerWrapper.getFrameRate();var bufferingCount=this.playerWrapper.getBufferingCount();var lastBufferingTime=this.bufferingTime;var lastPlayingTime=this.playStartTime;var encodedFrameRate=this.playerWrapper.getEncodedFrameRate();this.sessionGradeCalculator.add(frameRate,encodedFrameRate,null,null,null);this.currentGradeCalculator.add(frameRate,encodedFrameRate,null,null,null);var newGrade=this.sessionGradeCalculator.getGrade();this.qosCode=this.sessionGradeCalculator.getCode();this.currentQosGrade=this.currentGradeCalculator.getGrade();this.currentQosCode=this.currentGradeCalculator.getCode();if(this.currentQosGrade<=0)this.currentQosGrade=1;if(this.currentQosGrade<100)this.currentQosGrade=this.currentQosGrade*cuCurrentGradeFactor;if(newGrade<=0)newGrade=1;if(newGrade!=this.qosGrade) {var gradeChangeEventArgs=new Object();gradeChangeEventArgs.oldGrade=this.qosGrade;gradeChangeEventArgs.newGrade=newGrade;this.fireEvent(CUQOSManager.GradeChangeEvent,gradeChangeEventArgs);this.qosGrade=newGrade;if(this.entryQOSGradeAVG==0)this.entryQOSGradeAVG=newGrade;else this.entryQOSGradeAVG=(this.entryQOSGradeAVG+newGrade)/2;if(newGrade0) {this.testCurrentQOSGrade();}} CUQOSManager.prototype.testCurrentQOSGrade=function() {if(this.playerWrapper.hasPlayer()) {var sendByState=this.playerWrapper.getPlayState()==3||this.playerWrapper.getPlayState()==6||this.playerWrapper.getPlayState()==11;var sendBySettingsRate=this.playerWrapper.hasSettings()&&this.playerWrapper.getSettingsRate()==1;if(sendByState&&sendBySettingsRate) {var now=new Date();if(this.lastCurrentGradeSentTime==null) {this.sendCurrentQOSGradeEvent();this.lastCurrentGradeSentTime=now;} else {if(now-this.lastCurrentGradeSentTime>=cuCurrentQOSGradeSendInterval) {this.lastCurrentGradeSentTime=now;this.sendCurrentQOSGradeEvent();}}}}} CUQOSManager.prototype.testQOSGradeChange=function() {if(this.sendEventOnQOSGradeChange==true) {this.sendQOSGradeChangeEvent();} else {this.testQOSGradeAlertPoints();}} CUQOSManager.prototype.testQOSGradeAlertPoints=function() {var pointGrade;for(var i=0;i"+this.elem.innerHTML;} this.debug=function(message) {message=this.formatMessage(message);this.elem.innerHTML=''+message+'
'+this.elem.innerHTML;} return this;} HTMLLogger.prototype=new EmptyLogger;function FireBugLogger() {this.log=function(message) {message=this.formatMessage(message);console.log(message);} this.debug=function(message) {message=this.formatMessage(message);console.debug(message);} return this;} FireBugLogger.prototype=new EmptyLogger; function CUEventDispatcher() {return this;} CUEventDispatcher.prototype.addEvent=function(eventName,handler,scope) {if(this.events==null)this.events={};if(this.events[eventName]==null) {this.events[eventName]=new Array();} this.events[eventName].push({handler:handler,scope:scope});} CUEventDispatcher.prototype.removeEvent=function(eventName,handler) {if(this.events==null)this.events={};if(this.events[eventName]!=null) {for(var i=0;i0) setTimeout(CUPlayerWrapper.lookForPlayers,100);} CUPlayerWrapper.start=function() {if(CUPlayerWrapper.pageLoaded) {CUPlayerWrapper.lookForPlayers();} else {if(!CUPlayerWrapper.addedOnLoadEvent) {CUUtilsAddOnloadEvent(CUPlayerWrapper.lookForPlayers);CUPlayerWrapper.addedOnLoadEvent=true;}}} CUPlayerWrapper.onLoadHandler=function() {CUPlayerWrapper.pageLoaded=true;} CUUtilsAddOnloadEvent(CUPlayerWrapper.onLoadHandler); function CUNDSPlayerWrapper(playerId,lookForPlayerAtStartup,useWatchDog){this.ComponentID=NDSComponentID;this.ContentTypeID=NDSContentTypeID;this.playerId=playerId;this.lookForPlayerAtStartup=lookForPlayerAtStartup;this.useWatchDog=useWatchDog;this.player=null;} CUNDSPlayerWrapper.prototype=new CUPlayerWrapper;CUNDSPlayerWrapper.prototype.canInit=function(){if(!this.hasPlayer()){this.player=document.getElementById(this.playerId);} if(this.player==null){return false;} return true;} CUNDSPlayerWrapper.prototype.hasPlayer=function(){if(this.player==null){return false;} return true;} CUNDSPlayerWrapper.prototype.getVersionInfo=function(){if(this.player==null){return"";} return this.player.versionInfo;} function CUCommunicator(serviceURL,componentID,clientID) {this.serviceURL=serviceURL;this.componentID=componentID;this.clientID=clientID;this.sendCustomWMPEvent=function(eventID,playID,params,player) {this.sendEvent(eventID,playID,params);} this.sendEvent=function(eventID,playID,params){if(this.isValidParams(params)){if(this.componentID==0){if(this.validateWrapper(wrapper)){if(this.validateParam(wrapper.ComponentID)){this.componentID=wrapper.ComponentID;}}} if(playID==0){playID=generateGUID(true);} if(params["assetID"]!=null){params["ContentID"]=params["assetID"];if(this.validateWrapper(wrapper)){if(this.validateParam(wrapper.ContentTypeID)){params["ContentTypeID"]=wrapper.ContentTypeID;}}} if(params["VersionInfo"]==null){if(this.validateWrapper(wrapper)){if((typeof wrapper.canInit=='function')&&(typeof wrapper.getVersionInfo=='function')) {if(wrapper.canInit()){var strVersionInfo=wrapper.getVersionInfo();if((strVersionInfo)&&(strVersionInfo!="")){params["VersionInfo"]=strVersionInfo;}}}}} params.ComponentID=this.componentID;params.ClientID=this.clientID;params.PlayerEvent=eventID;params.PlayID=playID;this.SendToServer(params);}} this.validateWrapper=function(wrapper){try{if((wrapper)&&(typeof(wrapper)!="undefined")){return true;} return false;} catch(ex){return false;}} this.validateParam=function(paramToValidate) {if((paramToValidate)&&(typeof(paramToValidate)!="undefined")) {if(isNaN(paramToValidate)==false){return true;}} return false;} this.SendToServer=function(params) {var args=CUUtilsDictionaryToUrlQueryString(params);if(args!=""){var url=this.serviceURL+args;this.callURL(url);}} this.isValidParams=function(params) {try {if(params["MediaUrl"]==null||params["MediaUrl"].toString()==""||params["MediaUrl"].toString().length<=0) {return false;}} catch(er) {return false;} return true;} this.callURL=function(B){var A=new Image(1,1);A.src=B;A.onload=function(){this.doVOID()}};this.doVOID=function(){return;} return this;} var cuErateServiceUrl="http://213.8.137.51/Erate/EventReportQuery.asp";var cuErateExposureEventType=1;var cuErateClickEventType=2;var cuErateItemInfoParam="ERateID,CastUP_Content_ERateId";var cuErateItemClickParam="AssociatedURL";var cuStaticErateList={};cuStaticErateList["54420701"]="GUJ7KZ";cuStaticErateList["49685442"]="GUJ7KZ";cuStaticErateList["4767480"]="GUJ7KZ";cuStaticErateList["8311551"]="GUJ7KZ";cuStaticErateList["10428181"]="XF7EHK";cuStaticErateList["71391735"]="XF7EHK";cuStaticErateList["92413871"]="GUJ7KZ";cuStaticErateList["7860453"]="GUJ7KZ";cuStaticErateList["90556843"]="GUJ7KZ";cuStaticErateList["11951978"]="GUJ7KZ";cuStaticErateList["87881257"]="VRT56J";cuStaticErateList["96932107"]="VRT56J";cuStaticErateList["26403368"]="UKSJND";cuStaticErateList["59520360"]="UKSJND";cuStaticErateList["87881257"]="VRT56J";cuStaticErateList["96932107"]="VRT56J";cuStaticErateList["80988218"]="ZJ9KW9";cuStaticErateList["24135526"]="ZJ9KW9";cuStaticErateList["35148149"]="G1EI3Q";cuStaticErateList["57754065"]="G1EI3Q";cuStaticErateList["45350893"]="LY92IP";cuStaticErateList["19970820"]="LY92IP";cuStaticErateList["11128516"]="JAYRLD";cuStaticErateList["50100244"]="JAYRLD";cuStaticErateList["34281090"]="BMX98V";cuStaticErateList["99177892"]="BMX98V";function EmptyErater() {return this;} EmptyErater.prototype.sendExposureEvent=function(currentMedia){} EmptyErater.prototype.playerClickHandler=function(currentMedia){} function CUErater(playerWrapper) {this.currentERateID=null;this.exposureSentERateID=null;this.lastSentTime=new Date();this.playerWrapper=playerWrapper;this.playerWrapper.addEvent(CUPlayerWrapper.ItemChangeEvent,this.itemChangeHandler,this);this.playerWrapper.addEvent(CUPlayerWrapper.ClickEvent,this.clickHandler,this);this.sendExposureEvent=function(url) {if(this.playerWrapper==null)return;this.currentERateID=this.getMediaErateID(this.playerWrapper);if(this.currentERateID==null||this.currentERateID.toString().length<1) {this.currentERateID=this.getErateIdFromStaticList(url);} var diff=new Date()-this.lastSentTime;if(this.currentERateID!=null&&this.currentERateID.toString().length>0&&diff>300) {var erateURL=cuErateServiceUrl+'?EventType='+cuErateExposureEventType+'&Toolid='+this.currentERateID+'&random='+Math.random();this.callURL(erateURL);this.exposureSentERateID=this.currentERateID;this.lastSentTime=new Date();}} this.playerClickHandler=function() {if(this.playerWrapper==null)return;this.currentERateClick=this.playerWrapper.getCurrentItemInfo(cuErateItemClickParam);if(this.currentERateID!=null&&this.currentERateID.toString().length>0&&this.currentERateClick!="") {var erateURL=cuErateServiceUrl+'?EventType='+cuErateClickEventType+'&Toolid='+this.currentERateID+'&random='+Math.random();;this.callURL(erateURL);}} this.callURL=function(B){var A=new Image(1,1);A.src=B;A.onload=function(){this.doVOID()}};this.doVOID=function(){return;} return this;} CUErater.prototype=new EmptyErater;CUErater.prototype.itemChangeHandler=function(args) {args.scope.sendExposureEvent(args.newURL);} CUErater.prototype.clickHandler=function(args) {args.scope.playerClickHandler();} CUErater.prototype.getErateIdFromStaticList=function(url) {if(url==null||url.toString().length<1)return null;for(var secretid in cuStaticErateList) {if(url.toString().indexOf(secretid)>0) {return cuStaticErateList[secretid];}} return null;} CUErater.prototype.getMediaErateID=function(playerWrapper) {var list=cuErateItemInfoParam.split(",");var erateID=null;for(var i=0;i0) {return erateID;}} return erateID;} var cuRolloverRegEx="://([^/?]*)(.*)";var cuClientIDRegEx="cu=(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})";var cuSecretIDRegEx="/(\\d{6,}-\\d{2})";var cuURLParamRegEx="=(\\w*)(&?|\\z)";function CUUtilsAddOnloadEvent(newOnloadEvent) {CUUtilsAddEvent("load",newOnloadEvent,window);} function CUUtilsAddOnBeforeUnloadEvent(newOnBeforeUnloadEvent) {var oldFunf=window.onbeforeunload;window.onbeforeunload=function() {if(oldFunf!=null&&typeof(oldFunf)=="function") {newOnBeforeUnloadEvent();return oldFunf();} else {return newOnBeforeUnloadEvent();}};} function CUUtilsAddEvent(eventName,handler,target) {try {var onEventName="on"+eventName;if(typeof(document.attachEvent)!="undefined") {target.attachEvent(onEventName,handler);} if(typeof(document.addEventListener)!="undefined") {target.addEventListener(eventName,handler,false);}} catch(er) {}} function CUUtilsDictionaryToUrlQueryString(params) {var retVal="";for(property in params) {retVal+="&"+property+"="+params[property];} return retVal.substring(1,retVal.length);} function CUUtilsGenrateGUID(empty) {if(empty==true)return"00000000-0000-0000-0000-000000000000";var CHARS='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');var chars=CHARS,uuid=[],rnd=Math.random;var ri=0,r;uuid[8]=uuid[13]=uuid[18]=uuid[23]='-';uuid[14]='4';for(var i=0;i<36;i++) {if(!uuid[i]) {r=0|rnd()*16;uuid[i]=chars[(i==19)?(r&0x3)|0x8:r&0xf];}} return uuid.join('');} function generateGUID(empty){return(CUUtilsGenrateGUID(empty));} function CUUtilsCheckInt(numb) {try {numb=parseInt(numb,10);if(numb.toString()==Number.NaN.toString()||typeof(numb)!="number")return 0;} catch(e) {return 0;} return numb;} function CUUtilsCompareMedia(mediaA,mediaB) {if(mediaA==null||mediaB==null)return false;try {for(var i=0;i0) {var URLArr=url.split("?");returnURL=escape(URLArr[0]);} return returnURL;} function CUUtilsGetEntryUrlEscaped(url) {return escape(url);} function CUUtilsIsRollover(oldURL,newURL) {var oldRegEx=new RegExp(cuRolloverRegEx,"gi");var newRegEx=new RegExp(cuRolloverRegEx,"gi");var oldMatches=oldRegEx.exec(oldURL);var newMatches=newRegEx.exec(newURL);if(oldMatches!=null&&newMatches!=null&&oldMatches.length>1&&newMatches.length>2) {if(oldMatches[1]!=newMatches[1]&&oldMatches[2]==newMatches[2]) {return true}} return false;} function CUUtilsCleanVideoURL(videoURL) {var returnURL=videoURL;if(videoURL!=null&&videoURL.toString()!="") {returnURL=videoURL.split("?")[0];} return returnURL;} function CUUtilsGetClientID(videoURL) {var clientID=null;var clientIDRegEx=new RegExp(cuClientIDRegEx,"gi");var matches=clientIDRegEx.exec(videoURL);if(matches!=null&&matches.length>1) clientID=matches[1];return clientID;} function CUUtilsGetSecretID(videoURL) {var secretID=null;var secretIDRegEx=new RegExp(cuSecretIDRegEx);var matches=secretIDRegEx.exec(videoURL);if(matches!=null&&matches.length>1) secretID=matches[1];return secretID;} function CUUtilsGetURLParameter(videoURL,parameterName) {var parameterValue=null;var parameterValueRegex=new RegExp(parameterName+cuURLParamRegEx);var matches=parameterValueRegex.exec(videoURL);if(matches!=null&&matches.length>1) parameterValue=matches[1];return parameterValue;} function CUUtilsGetFlasPlayerVersion() {var isIE=(navigator.appVersion.indexOf("MSIE")!=-1)?true:false;var isWin=(navigator.appVersion.toLowerCase().indexOf("win")!=-1)?true:false;var isOpera=(navigator.userAgent.indexOf("Opera")!=-1)?true:false;var flashVer=-1;if(navigator.plugins!=null&&navigator.plugins.length>0) {if(navigator.plugins["Shockwave Flash 2.0"]||navigator.plugins["Shockwave Flash"]) {var swVer2=navigator.plugins["Shockwave Flash 2.0"]?" 2.0":"";var flashDescription=navigator.plugins["Shockwave Flash"+swVer2].description;var descArray=flashDescription.split(" ");var tempArrayMajor=descArray[2].split(".");var versionMajor=tempArrayMajor[0];var versionMinor=tempArrayMajor[1];var versionRevision=descArray[3];if(versionRevision=="") {versionRevision=descArray[4];} if(versionRevision[0]=="d") {versionRevision=versionRevision.substring(1);} else if(versionRevision[0]=="r") {versionRevision=versionRevision.substring(1);if(versionRevision.indexOf("d")>0) {versionRevision=versionRevision.substring(0,versionRevision.indexOf("d"));}} else if(versionRevision[0]=="b") {versionRevision=versionRevision.substring(1);} var flashVer=versionMajor+"."+versionMinor+"."+versionRevision;}} else if(navigator.userAgent.toLowerCase().indexOf("webtv/2.6")!=-1)flashVer=4;else if(navigator.userAgent.toLowerCase().indexOf("webtv/2.5")!=-1)flashVer=3;else if(navigator.userAgent.toLowerCase().indexOf("webtv")!=-1)flashVer=2;else if(isIE&&isWin&&!isOpera) {flashVer=CUUtilsGetControlVersion();} return flashVer;} function CUUtilsGetControlVersion() {var version;var axo;var e;try {axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");version=axo.GetVariable("$version");}catch(e){} if(!version) {try {axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");version="WIN 6,0,21,0";axo.AllowScriptAccess="always";version=axo.GetVariable("$version");}catch(e){}} if(!version) {try {axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");version=axo.GetVariable("$version");}catch(e){}} if(!version) {try {axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");version="WIN 3,0,18,0";}catch(e){}} if(!version) {try {axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");version="WIN 2,0,0,11";}catch(e){version=-1;}} return version;} function CUUtilsWMPCanReceiveDSEvents() {var result=false;if(navigator!=null&&navigator.userAgent!=null) result=(-1!=navigator.userAgent.indexOf("Firefox"))||(-1!=navigator.userAgent.indexOf("WebKit"))||(-1!=navigator.userAgent.indexOf("Presto"));return result;} function CUUtilsTimer() {this.startTime=this.startTime=new Date().getTime();this.endTime=this.startTime=new Date().getTime();this.stoped=false;this.started=false;this.paused=false;this.pauseArr=null;this.init=function() {this.endTime=this.startTime=new Date().getTime();this.started=false;this.stoped=false;this.paused=false;this.pauseArr=null;} this.start=function(){if(!this.started){this.endTime=this.startTime=new Date().getTime();} this.started=true;this.stoped=false;} this.stop=function() {if(!this.stoped) {this.endTime=new Date().getTime();} this.stoped=true;this.started=false;return this.getElapsedTime();} this.pause=function() {if(this.started) {if(!this.paused) {this.pauseTime=new Date().getTime();} this.paused=true;} return this.getElapsedTime();} this.resume=function() {if(this.paused) {if(this.pauseArr==null)this.pauseArr=new Array();this.pauseArr.push(new Date().getTime()-this.pauseTime);} this.paused=false;return this.getElapsedTime();} this.getElapsedTime=function() {var retVal;if(this.paused) {retVal=(this.pauseTime-this.startTime)-this.getTotalPauseTime();} else {if(this.stoped) {retVal=(this.endTime-this.startTime)-this.getTotalPauseTime();} else {retVal=(new Date().getTime()-this.startTime)-this.getTotalPauseTime();}} return retVal;} this.getTotalPauseTime=function() {var retVal=0;if(this.pauseArr!=null) {for(var i=0;i0?true:false;this.windowSize=typeof(windowSize)!="undefined"&&windowSize>0?windowSize:Number.MAX_VALUE;this.dataFields=dataFields;this.initialized=false;this.windowStart=new Date();this.data=new Array();this.accumulator={};this.trend={};this.lastData;this.count=0;return this;} CUUtilsTimeSeriesData.prototype.initAccumulator=function() {this.accumulator={};var field;for(var i=0;i=0&&((now-this.data[i]["date"])<=this.windowSize)) {for(var j=0;jminimumTrendTimeToLowest) {this.trend[field]["lowestValue"]=value;this.trend[field]["lowestValueTrend"]=trendTo;} if(value>this.trend[field]["highestValue"]&&trendTimeTo>minimumTrendTimeToHighest) {this.trend[field]["highestValue"]=value;this.trend[field]["highestValueTrend"]=trendTo;}}} i--;} if(i+1>0) {this.data=this.data.slice(i+1);}} CUUtilsTimeSeriesData.prototype.reCalculateTrend=function() {var newTrend=0;var length=this.data.length;if(length>1) {this.updateTrend(this.data[length-2],this.data[length-1]);}} CUUtilsTimeSeriesData.prototype.updateTrend=function(firstData,secondData) {var newTrend=0;var oldTrend=0;for(var i=0;i0&&oldTrend<=0)||(newTrend<0&&oldTrend>=0)||(newTrend==0&&oldTrend!=0)) {this.trend[field]["time"]=new Date();} this.trend[field]["value"]=newTrend;}}}} CUUtilsTimeSeriesData.prototype.reCalculate=function() {if(this.checkWindow) {this.initAccumulator();this.initTrendEdges();this.reCalculateWindow();this.reCalculateTrend();}} CUUtilsTimeSeriesData.prototype.addData=function(data) {if(!this.initialized) {this.init(data);} if(!this.checkWindow) {var now=new Date();var field;var minimumTrendTimeToLowest;var minimumTrendTimeToHighest;var value;if(this.lastData!=null) {this.updateTrend(this.lastData,data);} for(var i=0;iminimumTrendTimeToLowest) {this.trend[field]["lowestValue"]=value;this.trend[field]["lowestValueTrend"]=this.trend[field]["value"];} if(value>this.trend[field]["highestValue"]&&now-this.trend[field]["time"]>minimumTrendTimeToHighest) {this.trend[field]["highestValue"]=value;this.trend[field]["highestValueTrend"]=this.trend[field]["value"];}}} this.lastData=data;this.count++;} else {var now=new Date();this.data.push(data);this.reCalculateTrend();data["date"]=now;data["trendTo"]={};data["trendTimeTo"]={};for(var i=0;i0) {if(typeof(this.data[length-1][fieldName])!="undefined"&&this.data[length-1][fieldName]!=null) {return this.data[length-1][fieldName];}}} else {if(this.lastData!=null) {if(typeof(this.lastData[fieldName])!="undefined"&&this.lastData[fieldName]!=null) {return this.lastData[fieldName];}}} return null;} CUUtilsTimeSeriesData.prototype.getHighest=function(fieldName) {if(typeof(this.trend[fieldName])!="undefined"&&this.trend[fieldName]!=null) {this.reCalculate();var value=this.trend[fieldName]["highestValue"];if(value!=Number.MIN_VALUE) return value;} return null;} CUUtilsTimeSeriesData.prototype.getHighestTrend=function(fieldName) {if(typeof(this.trend[fieldName])!="undefined"&&this.trend[fieldName]!=null) {this.reCalculate();var value=this.trend[fieldName]["highestValueTrend"];if(value!=Number.MIN_VALUE) return value;} return null;} CUUtilsTimeSeriesData.prototype.getLowest=function(fieldName) {if(typeof(this.trend[fieldName])!="undefined"&&this.trend[fieldName]!=null) {this.reCalculate();var value=this.trend[fieldName]["lowestValue"];if(value!=Number.MAX_VALUE) return value;} return null;} CUUtilsTimeSeriesData.prototype.getLowestTrend=function(fieldName) {if(typeof(this.trend[fieldName])!="undefined"&&this.trend[fieldName]!=null) {this.reCalculate();var value=this.trend[fieldName]["lowestValueTrend"];if(value!=Number.MAX_VALUE) return value;} return null;} CUUtilsTimeSeriesData.prototype.length=function() {this.reCalculate();if(this.checkWindow) {return this.data.length;} else {return this.count;}} CUGradeCalculator.FIRST_FRAMERATE_TREND_TIME=1000;CUGradeCalculator.SECOND_FRAMERATE_TREND_TIME=3000;CUGradeCalculator.FIRST_FRAMERATE_RATIO=70;CUGradeCalculator.SECOND_FRAMERATE_RATIO=50;CUGradeCalculator.MINIMUM_FRAMERATE=10;CUGradeCalculator.BUFFERING_TIME_TOLERANCE=typeof(cuQOSBufferingTimeTolerance)!="undefined"?cuQOSBufferingTimeTolerance:9000;CUGradeCalculator.PLAY_TIME_TOLERANCE=typeof(cuQOSPlayingTimeTolerance)!="undefined"?cuQOSPlayingTimeTolerance:9000;CUGradeCalculator.IMPROVE_GRADE_STEP_TIME=typeof(cuQOSImproveGradeStepTime)!="undefined"?cuQOSImproveGradeStepTime:900000;CUGradeCalculator.IMPROVE_GRADE_STEP=typeof(cuQOSImproveGradeStep)!="undefined"?cuQOSImproveGradeStep:5;function CUGradeCalculator(slidingWindowSize,useTimes,improveInTime,bufferingCountGradeFactor) {this.slidingWindowSize=slidingWindowSize;this.usetimes=useTimes;this.improveInTime=improveInTime;this.bufferingCountGradeFactor=bufferingCountGradeFactor;this.dataFields=new Array();this.dataFields.push({"Name":"frameRate","MinimumTrendTimeToLowest":500,"MinimumTrendTimeToHighest":500});this.dataFields.push({"Name":"bufferingCount","MinimumTrendTimeToLowest":-1,"MinimumTrendTimeToHighest":-1});this.dataFields.push({"Name":"lastBufferingTime","MinimumTrendTimeToLowest":-1,"MinimumTrendTimeToHighest":-1});this.dataFields.push({"Name":"playingTime","MinimumTrendTimeToLowest":-1,"MinimumTrendTimeToHighest":-1});this.timeSeriesDataColector=new CUUtilsTimeSeriesData(this.dataFields,this.slidingWindowSize,500);this.grade=0;this.code=0;this.lastCurrentGrade=0;this.lastGoodGradeTime=0;this.improveGrade=0;this.improveTimer=new CUUtilsTimer();this.init();return this;} CUGradeCalculator.prototype.init=function() {this.grade=0;this.code=0;this.lastCurrentGrade=0;this.lastGoodGradeTime=0;this.improveGrade=0;this.improveTimer.init();this.timeSeriesDataColector.init();} CUGradeCalculator.prototype.add=function(frameRate,encodedFramerate,bufferingCount,lastBufferingTime,playingTime) {this.grade=100;this.code=100;if(frameRate!=null&&frameRate=1) highestBuffercount=highestBuffercount-1;var highestLastBufferingTime=this.timeSeriesDataColector.getHighest("lastBufferingTime");if(highestLastBufferingTime==null)highestLastBufferingTime=0;var highestPlayingTime=this.timeSeriesDataColector.getHighest("playingTime");if(highestPlayingTime==null)highestPlayingTime=0;this.code=this.calculateGradeCode(lowestFramerate,lowestFramerateTrend,encodedFramerate,highestLastBufferingTime,highestPlayingTime);if(this.code<100&&this.improveInTime&&this.code+this.improveGrade<100) {var currentCode=this.calculateGradeCode(frameRate,framerateTrend,encodedFramerate,lastBufferingTime,playingTime);var goodBufferingCount=(bufferingCount==null||bufferingCount<=1);var goodFramerateTrend=framerateTrend>=0;if(currentCode==100&&goodBufferingCount&&goodFramerateTrend) {this.improveTimer.start();this.improveTimer.resume();} else {this.improveTimer.pause();} this.lastGoodGradeTime=this.improveTimer.getElapsedTime();if(currentCode==100&&goodBufferingCount&&goodFramerateTrend&&this.lastGoodGradeTime>0) {this.improveGrade=CUUtilsCheckInt((this.lastGoodGradeTime/CUGradeCalculator.IMPROVE_GRADE_STEP_TIME)*CUGradeCalculator.IMPROVE_GRADE_STEP);}} var newGrade=this.code-(highestBuffercount*this.bufferingCountGradeFactor)+this.improveGrade;if(newGrade>100)newGrade=100;if(newGrade<0)newGrade=0;this.grade=newGrade;} CUGradeCalculator.prototype.calculateGradeCode=function(framerate,framerateTrend,encodedFramerate,lastBufferingTime,playingTime) {var code=100;if(framerateTrend<=0&&framerateCUGradeCalculator.BUFFERING_TIME_TOLERANCE) {code=60;} else {if(playingTime>CUGradeCalculator.PLAY_TIME_TOLERANCE) {code=70;}}} return code;} CUGradeCalculator.prototype.getGrade=function() {return this.grade;} CUGradeCalculator.prototype.getCode=function() {return this.code;} //OVERRIDE CONFIG paramters cuOrangeTimeStatusEvent=50; cuOrangeTimePlayerStatusEvent=51; cuOrangeTimeUserEvent=52; NDSComponentID = 500009 NDSContentTypeID = 1 //instantiate CUQOSManager object var wrapper= new CUNDSPlayerWrapper('WMPObjFF',false,false); var CUQOSManagerObj = new CUQOSManager('WMPObjFF',false, null, wrapper, null,true);