var Mediasite=window.Mediasite||{};Mediasite.Player=Mediasite.Player||{},Mediasite.Player.CurrentViewTracking=function(){function scheduleHeartbeat(){window.clearTimeout(c),c=window.setTimeout(onHeartbeat,p)}function onHeartbeat(){try{n.endSegment(),reportSegmentsSinceLastReport()}catch(i){t.Debug("Error in Playback Reporting onHeartbeat")}scheduleHeartbeat()}function reportSegmentsSinceLastReport(n){var t=f.getAllSegments();f.reset(),reportPlayed(t,n)}function handleSegmentStart(n){clearTimeout(r),u.fire(s.Start,n)}function handleSegmentEnd(n,t){f.addSegment(n,t),u.fire(s.End,n,t),clearTimeout(r)}function onPlaybackRateChanged(t){n.handlePlaybackRateChange(t)}function onPositionChanged(t){clearTimeout(r),r=setTimeout(function(){n.endSegment()},w),n.handlePositionChange(t)}function reportPlayed(n,i){var f=i!==!0,s,r,u;o&&e&&((u=calcBookmarkPosition(n,l()),r=toServiceSegments(n),r.length<1)||(o.ReportMediaView(JSON.stringify({playbackTicket:e,segments:r,bookmarkPosition:u}),f),h+=1,t.Debug("ReportMediaView "+makeReportMediaViewDescription(r,u)),t.Debug("ReportMediaView has been called "+h+" times.")))}function toServiceSegments(n){for(var r,u,f,e,t=[],o=function(){return t.length<1?null:t[t.length-1]},s=function(){var n=o();return n?n.StartTime+n.Duration:NaN},h=function(n,t){var i,r,u;r=n+t,i=o(),u=r-i.StartTime,i.Duration=u},c=function(n,i){t.push({StartTime:n,Duration:i})},l=function(n,t){t<=0||(Math.abs(n-s())<=y?h(n,t):c(n,t))},i=0;i0&&(i=Math.floor(n[n.length-1].end),isInNoBookmarkZone(i)&&(i=0)),i}function isInNoBookmarkZone(n){var t=a()-n;return t>=0&&t<=v}var u,s;if(!(this instanceof Mediasite.Player.CurrentViewTracking))return new Mediasite.Player.CurrentViewTracking;var i=this,t=Mediasite.Logging&&Mediasite.Logging.LoggerFactory("Playback Reporting")||{Debug:function(){console.log(arguments)}},b=.5,w=2e3,p=3e4,y=1,v=3,l=function(){return!1},a=function(){return 0},h=0,r,c,o,e,f=new Mediasite.Player.WatchedSegmentsMemory,n=new Mediasite.Player.HeuristicPlayDetector;n.tolerance=b,n.segmentStartAction=handleSegmentStart,n.segmentEndAction=handleSegmentEnd,i.onPositionChanged=onPositionChanged,i.onPlaybackRateChanged=onPlaybackRateChanged,u=new Mediasite.Player.EventBundle,s=Mediasite.Player.CurrentViewTracking.Event,this.addHandler=function(n,t){u.addHandler(n,t)},i.trackPresentation=function(i){if(!i){t.Debug("Reporting cannot track presentation: no player API to attach to");return}var r=this;l=function(){return i.getPlayerState().isLive},a=function(){return Math.floor(i.getDuration())},i.addHandler("currenttimechanged",function(n){r.onPositionChanged(n.currentTime)}),i.addHandler("playbackratechanged",function(n){r.onPlaybackRateChanged(n.currentRate)});$(window).on("beforeunload",function(){n.endSegment(),reportSegmentsSinceLastReport(!0)});scheduleHeartbeat()},i.reportToDataProvider=function(n,i){if(!n||!i){t.Debug("Reporting cannot report to data provider: no playback ticket or data provider");return}e=n,o=i}},Mediasite.Player.HeuristicPlayDetector=function(){function startSegment(){i=t,n.segmentStartAction(i.position)}function createLogger(){return Mediasite.Logging&&Mediasite.Logging.LoggerFactory("Playback Reporting")||{Debug:function(){console.log(arguments)}}}var n=this,t=null,i=null;this.tolerance=.5,this.playbackRate=1,this.playingCalculator=Mediasite.Player.HeuristicPlayDetector.isProbablyPlaying,this.timeProvider=new Mediasite.Player.HeuristicPlayDetector.StandardTimeProvider,this.logger=createLogger(),this.segmentStartAction=function(){},this.segmentEndAction=function(){},this.handlePlaybackRateChange=function(n){this.playbackRate=n},this.handlePositionChange=function(r){var u,e=n.timeProvider.getCurrentTime()/1e3,f={time:e,position:r};if(t){try{u=n.playingCalculator(t.time,t.position,f.time,f.position,n.playbackRate,n.tolerance)}catch(o){(o.name=Mediasite.Player.HeuristicPlayDetector.ErrorNames.timeAnomaly)&&n.logger.Debug("Times provided by timeProvider were out of order."),u=!1}u?i||startSegment():n.endSegment()}t=f},this.endSegment=function(r){r=r||!1,i&&t&&n.segmentEndAction(i.position,t.position,r),i=null}},Mediasite.Player.HeuristicPlayDetector.isProbablyPlaying=function(n,t,i,r,u,f){var s,h,o,e=function(n){return typeof n!="number"&&(n=0),Math.max(0,n)};if(n=e(n),t=e(t),i=e(i),r=e(r),u=e(u),f=e(f),n>i)throw{name:"Argument Error",message:"time2 must be greater than time1."};return t>r?!1:(s=i-n,h=r-t,o=s*u,Math.abs(o-h)<=o*f)},Mediasite.Player.HeuristicPlayDetector.ErrorNames={timeAnomaly:"Time Anomaly"},Mediasite.Player.HeuristicPlayDetector.StandardTimeProvider=function(){var n=window.performance&&typeof window.performance.now=="function";this.getCurrentTime=function(){return n?window.performance.now():+new Date}},Mediasite.Player.CurrentViewTracking.Event={Start:"start",End:"end"},Mediasite.Player.StateReporting=function(){function getContainerUrl(){if(window.self!=window.top)try{var n=window.parent.document.location.href;return n?n:void 0}catch(t){}}if(!(this instanceof Mediasite.Player.StateReporting))return new Mediasite.Player.StateReporting;var n=this,i=Mediasite.Logging&&Mediasite.Logging.LoggerFactory("Playback Reporting")||{Debug:function(){console.log(arguments)}},r,t,u,f=!1;n.reportMediaOpened=function(){if(t&&!f){f=!0;var n={playbackTicket:r,playerType:"Javascript",mediaPlayerType:Mediasite.Player.MediaPlayerType.GetDisplayName(u),embeddedPlayer:window.self!=window.top,url:document.location.href},e=getContainerUrl();e&&(n.container=e),t.ReportMediaOpen(JSON.stringify(n)),i.Debug("Reporting media opened","\n mediaPlayerType="+n.mediaPlayerType,"\n url="+n.url,"\n embedded="+n.embeddedPlayer)}},n.setMediaPlayerType=function(n){u=n},n.watchPlayer=function(t){t.addHandler({playstatechanged:function(){n.reportMediaOpened()}})},n.reportToDataProvider=function(n,u){if(!n||!u){i.Debug("Reporting cannot report to data provider: no playback ticket or data provider");return}r=n,t=u}},Mediasite.Player.TimelineSegment=function(n,t){this.start=n,this.end=t},Mediasite.Player.TimelineSegment.prototype={clone:function(){return new Mediasite.Player.TimelineSegment(this.start,this.end)}},Mediasite.Player.WatchedSegmentsMemory=function(){var n=[];this.addSegment=function(t,i){n.push(new Mediasite.Player.TimelineSegment(t,i))},this.getAllSegments=function(){for(var i=[],t=0;t