UNPKG

@flowplayer/player

Version:
2 lines (1 loc) 2.89 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):((t="undefined"!=typeof globalThis?globalThis:t||self).flowplayer=t.flowplayer||{},t.flowplayer.consent=e())}(this,(function(){"use strict";class PlayerStorage{constructor(t,e){this.implementation=t,e&&e.keys().forEach(t=>{"string"==typeof e.implementation[t]&&this.implementation.setItem(t,e.implementation[t])})}keys(){var t;const e=[];for(var n=0;n<this.implementation.length;n++)(null===(t=this.implementation.key(n))||void 0===t?void 0:t.startsWith("flowplayer/"))&&e.push(this.implementation.key(n));return e}removeItem(t){try{this.implementation.removeItem("flowplayer/"+t)}catch(t){}}getItem(t){try{return this.implementation.getItem("flowplayer/"+t)}catch(t){return null}}setItem(t,e){try{this.implementation.setItem("flowplayer/"+t,e)}catch(t){}}clear(){try{this.keys().forEach(t=>this.implementation.removeItem(t))}catch(t){}}get length(){try{return this.keys().length}catch(t){return 0}}key(t){try{return this.implementation.key(t)}catch(t){return null}}}var t,e,n;!function(t){t[t.ALL=1]="ALL",t[t.NONE=2]="NONE"}(t||(t={})),function(t){t[t.ALL=8]="ALL",t[t.NONE=16]="NONE"}(e||(e={}));const s=((n=class ConsentPlugin{constructor(n,s){const o=s._storage.getItem("consent"),r=this.current_value=o&&!isNaN(Number(o))?Number(s._storage.getItem("consent")):t.NONE|e.NONE;this.player=s,this.adapt(Object.assign({consent:r},s.opts))}init(t,e,n){this.adapt(t),n.on("config",t=>{this.adapt(t.detail)});const s=t=>{n.setOpts({consent:t.detail})};document.addEventListener("flowplayer/consent",s),n.on("reap",()=>document.removeEventListener("flowplayer/consent",s))}adapt(n){const s=void 0===n.consent?this.current_value:n.consent;e.ALL&s?this.setStorage(e.ALL):e.NONE&s&&this.setStorage(e.NONE),t.ALL&s?this.setTracking(t.ALL):t.NONE&s&&this.setTracking(t.NONE),this.player._storage.setItem("consent",s.toString())}setStorage(t){try{const n=this.player._storage;switch(this.player.setState("consent-no-storage",t===e.NONE),t){case e.ALL:this.player._storage=new PlayerStorage(localStorage,this.player._storage);break;case e.NONE:this.player._storage=new PlayerStorage(sessionStorage,n),n.clear()}}catch(t){console.debug(t)}}setTracking(e){var n,s;switch(this.player.setState("consent-no-tracking",e===t.NONE),e){case t.ALL:null===(n=this.player.health)||void 0===n||n.toggle(!0);break;case t.NONE:null===(s=this.player.health)||void 0===s||s.toggle(!1)}}}).pluginName="consent",n.tracking=t,n.storage=e,n);return function(t,e){if("object"==typeof exports&&"undefined"!=typeof module)return e;if(null===document.currentScript)return e;"flowplayer"in t||(t.flowplayer={extensions:[]});const n=t.flowplayer;return"function"==typeof n?(n(e),e):(Array.isArray(n.extensions)||(n.extensions=[]),~n.extensions.indexOf(e)||n.extensions.push(e),e)}(window,s)}));