!function(){var i=window.jwplayer("container"),t=function(){function t(i,t){this.internalPlayerApi=i,this.config=t,this.daiNativePlugin=window.DaiNativePlugin,this.instreamInstance=null,this.playlistItem=null,this.imaDaiSettings=null,this.storedSeekOffset=null,this.snapbackAdPosition=null,this.paused=!0,i.on("playlist",this.handlePlaylist,this),i.on("playlistItem",this.handlePlaylistItem,this),i.on("play",this.trackPlayingState,this),i.on("adPlay",this.trackPlayingState,this),i.on("pause",this.trackPausedState,this),i.on("adPause",this.trackPausedState,this),i.on("remove",this.destroy,this)}var e=t.prototype;return e.handlePlaylist=function(i){this.init()},e.handlePlaylistItem=function(t){this.init();var e=t.item.imaDaiSettings;e||(e=this.config.advertising&&this.config.advertising.imaDaiSettings),e?(this.internalPlayerApi.playAd=i.utils.noop,this.internalPlayerApi.pauseAd=i.utils.noop,this.internalPlayerApi.skipAd=i.utils.noop,this.instreamInstance=this.internalPlayerApi.createInstream(),this.playlistItem=t.item,this.imaDaiSettings=e,this.daiNativePlugin.init(),this.internalPlayerApi.once("beforePlay",this.handleBeforePlay,this)):this.destroy()},e.handleBeforePlay=function(){if(this.instreamInstance){this.instreamInstance.init(),this.internalPlayerApi.on("error",this.handleError,this),this.internalPlayerApi.on("play",this.resumeAd,this),this.internalPlayerApi.on("pause",this.handlePauseAd,this);var i=this.playlistItem.file||this.playlistItem.sources[0].file;this.daiNativePlugin.requestStream(JSON.stringify(this.imaDaiSettings),i)}},e.handleSeek=function(i){var t=i.offset,e=this.daiNativePlugin.getPreviousCuePointForStreamTime(t);e&&(this.storedSeekOffset=t,this.snapbackAdPosition=JSON.parse(e))},e.handleSeeked=function(i){if(this.snapbackAdPosition){var t=this.snapbackAdPosition.start;this.paused&&this.internalPlayerApi.play(),this.internalPlayerApi.off("seek",this.handleSeek,this),this.internalPlayerApi.off("seeked",this.handleSeeked,this),this.internalPlayerApi.seek(t)}},e.handleAdBreakEnd=function(i){if(this.internalPlayerApi.off("seek",this.handleSeek,this),this.internalPlayerApi.off("seeked",this.handleSeeked,this),this.storedSeekOffset&&this.storedSeekOffset>this.snapbackAdPosition.end){var t=this.storedSeekOffset;this.storedSeekOffset=null,this.internalPlayerApi.seek(t)}this.snapbackAdPosition=null,this.internalPlayerApi.on("seek",this.handleSeek,this),this.internalPlayerApi.on("seeked",this.handleSeeked,this),this.internalPlayerApi.play()},e.handleError=function(i){this.daiNativePlugin.destroy()},e.resumeAd=function(){this.daiNativePlugin.resumeAd()},e.handlePauseAd=function(i){this.daiNativePlugin.pauseAd(i)},e.trackPausedState=function(){this.paused=!0},e.trackPlayingState=function(){this.paused=!1},e.destroy=function(){this.internalPlayerApi.off(null,null,this)},e.finishedDaiRequest=function(i,t,e){t&&(this.internalPlayerApi.on("adBreakEnd",this.handleAdBreakEnd,this),this.internalPlayerApi.on("seek",this.handleSeek,this),this.internalPlayerApi.on("seeked",this.handleSeeked,this));var s=this.playlistItem;s.sources=t?[Object.assign(s.sources[0],{file:i,type:e})]:[Object.assign(s.sources[0],{file:i})],this.instreamInstance.replacePlaylistItem(s),this.instreamInstance.destroy()},e.init=function(){this.instreamInstance&&this.instreamInstance.destroy(),this.instreamInstance=null,this.playlistItem=null,this.imaDaiSettings=null,this.storedSeekOffset=null,this.snapbackAdPosition=null,this.paused=!0,this.daiNativePlugin.destroy()},t}();i.registerPlugin("daiPluginSdk","8.0",t)}();
