videojs-per-source-behaviors
Version:
A Video.js plugin for enhancing a player with behaviors related to changing media sources.
3 lines (2 loc) • 2.01 kB
JavaScript
/*! @name videojs-per-source-behaviors @version 3.0.1 @license Apache-2.0 */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("video.js")):"function"==typeof define&&define.amd?define(["video.js"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).videojsPerSourceBehaviors=t(e.videojs)}(this,(function(e){"use strict";function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=t(e),s="3.0.1";const n=i.default.getTech("Html5"),r=i.default.registerPlugin||i.default.plugin,o=["abort","emptied","loadstart","play"],u=["abort","emptied"],d=["ad-playback","ads-ready?","postroll?","preroll?"],a=(e,t)=>{return!!e.usingPlugin("ads")&&((e=>e.usingPlugin("ads")&&"function"==typeof e.ads.inAdBreak)(e)?e.ads.isInAdMode()&&"loadstart"!==t.type:(i=e.ads.state,d.indexOf(i)>-1));var i};let l=0;const h=function(){const e=[];let t,i,r=!1,d=!0;const h=t=>function(i,s){if(this.perSourceBehaviors.disabled())return;const n=2===arguments.length,r=this.currentSrc(),o=[i],u=arguments[arguments.length-1],d=n?this:i,a=u.bind(d),h=(...e)=>{const i=this.currentSrc()!==r;this.perSourceBehaviors.disabled()||((i||t)&&this.off(...o),i||a(...e))};return h.guid=a.guid=u.guid="psb-"+ ++l,n||o.push(s),o.push(h),e.push(o),this.on(...o)};this.perSourceBehaviors={disable:function(){return this.clearTimeout(i),i=null,r=!0,r}.bind(this),disabled:()=>r,enable:()=>(r=!1,r),enabled:()=>!r,isSrcStable:()=>d,VERSION:s},this.onPerSrc=h(),this.onePerSrc=h(!0),this.on("dispose",(()=>{e.length=0})),this.on(o,(s=>{if(this.perSourceBehaviors.disabled()||i||a(this,s))return;d&&u.indexOf(s.type)>-1&&(d=!1,this.trigger("sourceunstable"));const r=[],o=e=>r.push({time:Date.now(),event:e});o(s),this.on(n.Events,o),i=this.setTimeout((()=>{const s=this.currentSrc();d=!0,i=null,this.off(n.Events,o),s&&s!==t&&(e.forEach((e=>this.off(...e))),e.length=0,this.trigger("sourcechanged",{interimEvents:r,from:t,to:s}),t=s)}),1)}))};return h.VERSION=s,r("perSourceBehaviors",h),h}));