UNPKG

@flowplayer/player

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