@flowplayer/player 3.2.3 → 3.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core.js +1 -15
- package/default.js +1 -15
- package/embed.js +3 -17
- package/index.d.ts +3 -4
- package/package.json +1 -1
- package/plugin.d.ts +3 -2
- package/plugins/ads.js +2 -17
- package/plugins/analytics.js +1 -1
- package/plugins/chromecast.js +1 -16
- package/plugins/dash.js +5 -2
- package/plugins/health.js +1 -1
- package/plugins/ovp.js +1 -15
- package/plugins/playlist.js +1 -1
- package/plugins/preview.js +1 -1
- package/util/loader.d.ts +1 -1
package/plugins/health.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!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.health=t())}(this,(function(){"use strict";const e="rebuffer";var t=Object.freeze({__proto__:null,RECORD:"health:record",REBUFFER:e});const n="load",i="fullscreenenter",o="fullscreenexit",s="loadedmetadata",r="loadeddata",a="progress",d="loadstart",c="pause",l="playing",u="waiting",_="canplay",h="ended",p="seeked",f="seeking";function m(e){try{return!!new URL(e)}catch(e){return!1}}function v(e,t){const n=function(){try{return localStorage.getItem("flowplayer/debug")}catch(e){return""}}(),i=(i,...o)=>{const s=(null==t?void 0:t.debug)||n;s&&e.match(s)&&console.log(`${e} -- ${i}`,...o)};return i.log=i,i}const E=navigator;function g(e){var t,n;const i=null===(t=e.hls)||void 0===t?void 0:t.bandwidthEstimate;return i?1e-6*i:(null===(n=E.connection)||void 0===n?void 0:n.downlink)||-1}function y(e,t){return function(e,t){return"function"==typeof navigator.sendBeacon&&navigator.sendBeacon(e,t)}(e,JSON.stringify({events:t}))}const R="https://ljsp.lwcdn.com".concat("/web/public/countdown/time.json"),O=window,I=O._flowplayerTimekeeper||(O._flowplayerTimekeeper={});var w;!function(e){e[e.OFF=0]="OFF",e[e.ON=1]="ON",e[e.AUDIO_REQUIRED=2]="AUDIO_REQUIRED"}(w||(w={}));const D=e=>{switch(e){case!0:return w.ON;case!1:return w.OFF;default:return e}},N=[];function T(e){if(e.suspended)return;const t=N.slice(0);N.length=0,0!=t.length&&(e.logger.log(`:dispatch events={${t.length}}`),y("https://ihi.flowplayer.com/v1/health/events",t))}async function A(e,t,n){const i=await S();N.push(Object.assign(t,i)),e.logger.log(":enqueue",t.event,t),N.length<10&&!n||T(e)}const b=()=>{var e,t;try{const n=window;return null===(t=null===(e=null==n?void 0:n.google)||void 0===e?void 0:e.ima)||void 0===t?void 0:t.VERSION}catch(e){return}},S=async()=>{try{const e=await async function(){const e=I.cachedServerOffset;if(e)return e;const t=I.pendingRequest||(I.pendingRequest=fetch(R)),n=await t,i=parseInt(n.headers.get("age")||"0"),o=await n.json(),s=Date.now()-o.millisUtc-1e3*i;return I.cachedServerOffset=s,I.cachedServerOffset}();return{timestamp:Date.now()-e,
|
|
1
|
+
!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.health=t())}(this,(function(){"use strict";const e="rebuffer";var t=Object.freeze({__proto__:null,RECORD:"health:record",REBUFFER:e});const n="load",i="fullscreenenter",o="fullscreenexit",s="loadedmetadata",r="loadeddata",a="progress",d="loadstart",c="pause",l="playing",u="waiting",_="canplay",h="ended",p="seeked",f="seeking";function m(e){try{return!!new URL(e)}catch(e){return!1}}function v(e,t){const n=function(){try{return localStorage.getItem("flowplayer/debug")}catch(e){return""}}(),i=(i,...o)=>{const s=(null==t?void 0:t.debug)||n;s&&e.match(s)&&console.log(`${e} -- ${i}`,...o)};return i.log=i,i}const E=navigator;function g(e){var t,n;const i=null===(t=e.hls)||void 0===t?void 0:t.bandwidthEstimate;return i?1e-6*i:(null===(n=E.connection)||void 0===n?void 0:n.downlink)||-1}function y(e,t){return function(e,t){return"function"==typeof navigator.sendBeacon&&navigator.sendBeacon(e,t)}(e,JSON.stringify({events:t}))}const R="https://ljsp.lwcdn.com".concat("/web/public/countdown/time.json"),O=window,I=O._flowplayerTimekeeper||(O._flowplayerTimekeeper={});var w;!function(e){e[e.OFF=0]="OFF",e[e.ON=1]="ON",e[e.AUDIO_REQUIRED=2]="AUDIO_REQUIRED"}(w||(w={}));const D=e=>{switch(e){case!0:return w.ON;case!1:return w.OFF;default:return e}},N=[];function T(e){if(e.suspended)return;const t=N.slice(0);N.length=0,0!=t.length&&(e.logger.log(`:dispatch events={${t.length}}`),y("https://ihi.flowplayer.com/v1/health/events",t))}async function A(e,t,n){const i=await S();N.push(Object.assign(t,i)),e.logger.log(":enqueue",t.event,t),N.length<10&&!n||T(e)}const b=()=>{var e,t;try{const n=window;return null===(t=null===(e=null==n?void 0:n.google)||void 0===e?void 0:e.ima)||void 0===t?void 0:t.VERSION}catch(e){return}},S=async()=>{try{const e=await async function(){const e=I.cachedServerOffset;if(e)return e;const t=I.pendingRequest||(I.pendingRequest=fetch(R)),n=await t,i=parseInt(n.headers.get("age")||"0"),o=await n.json(),s=Date.now()-o.millisUtc-1e3*i;return I.cachedServerOffset=s,I.cachedServerOffset}();return{timestamp:Date.now()-e,adjusted_timestamp:!0}}catch(e){return{timestamp:Date.now(),adjusted_timestamp:!1}}},U=(e,t)=>Object.assign(e,{detail:t}),k=(e,{event:t,media_session_id:n,session_id:i})=>({event:t,media_session_id:n,session_id:i,device_id:e.deviceId(),version:"3.2.5",commit:"176e25b4b03756a6a18fc30efbefd80a66eb8db1",ima_sdk_version:b(),preload:e.opt("preload"),autoplay:D(e.opt("autoplay")),live:e.opt("live"),dvr:e.opt("dvr"),source:e.original_src,downlink_mbs:g(e),player_id:e.opt("metadata.player_id"),media_id:e.opt("metadata.media_id"),site_id:e.opt("metadata.site_id"),category_id:e.opt("metadata.category_id"),sitegroup_id:e.opt("metadata.sitegroup_id"),token:e.token,plugins:e.plugins.map(e=>e.constructor.name).sort((e,t)=>e.localeCompare(t)),current_time:e.currentTime,external_media_id:e.opt("external_media_id")}),C=e=>({bitrate:null==e?void 0:e.bitrate,resolution:null==e?void 0:e.attrs.RESOLUTION,frame_rate:null==e?void 0:e.attrs["FRAME-RATE"]});function L(e,t,n,i){const o=k(t,e.eventInfo(n)),{before:s,after:r}=i;A(e,((e,t,n)=>Object.assign(e,{state:{before:t,after:n}}))(o,C(s),C(r)))}const M=[1e7]+""+-1e3+-4e3+-8e3+-1e11,B=()=>"undefined"==typeof crypto?"":M.replace(/[018]/g,e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16));var x;function j(e){switch(e){case x.MEDIA_PLAYBACK_ABORTED:return"media playback was aborted";case x.MEDIA_ERR_NETWORK:return"a network error occurred";case x.MEDIA_ERR_DECODE:return"unable to decode media content";case x.MEDIA_ERR_SRC_NOT_SUPPORTED:return"unsupported media type";case x.NO_INTERNET:return"no internet connection detected";case x.MIXED_CONTENT:return"cannot load insecure content in a secure context";default:return"an unknown error occurred"}}!function(e){e[e.UNKNOWN=-1]="UNKNOWN",e[e.MEDIA_PLAYBACK_ABORTED=1]="MEDIA_PLAYBACK_ABORTED",e[e.MEDIA_ERR_NETWORK=2]="MEDIA_ERR_NETWORK",e[e.MEDIA_ERR_DECODE=3]="MEDIA_ERR_DECODE",e[e.MEDIA_ERR_SRC_NOT_SUPPORTED=4]="MEDIA_ERR_SRC_NOT_SUPPORTED",e[e.MIXED_CONTENT=1001]="MIXED_CONTENT",e[e.NO_INTERNET=1002]="NO_INTERNET"}(x||(x={}));const F=(e,t)=>{let n=null;return(...i)=>{null!==n&&(clearTimeout(n),n=null),n=setTimeout(()=>t(...i),e)}},H=B();class Health{constructor(e,t){this.session_id=H,this.suspended=!1,this.logger=v("health",t.opts),this.media_session_id=B(),this.analyticsLoop=setInterval(()=>T(this),2e3),t.on("reap",()=>clearInterval(this.analyticsLoop));const n=this;if(t.health={get media_session_id(){return n.media_session_id},set media_session_id(e){n.media_session_id=e},get session_id(){return n.session_id},set session_id(e){n.session_id=e},toggle(e){e?n.resume():n.suspend()}},!Health._UNLOAD_SUBSCRIBED){Health._UNLOAD_SUBSCRIBED=!0;const t=t=>e.instances.forEach(e=>e.emit(t.type));document.addEventListener("visibilitychange",e=>{"hidden"==document.visibilityState&&t(e)}),window.addEventListener("pagehide",t)}}eventInfo(e){return{event:e,media_session_id:this.media_session_id,session_id:this.session_id}}suspend(){this.suspended=!0,clearInterval(this.analyticsLoop)}resume(){this.suspended=!1,this.analyticsLoop=setInterval(()=>T(this),2e3)}init(t,v,E){!function(t){t.on(u,(function(n){t.seeking||t.networkState===t.NETWORK_LOADING&&t.readyState!==t.HAVE_NOTHING&&t.emit(e)}))}(E),E.on("health:record",({detail:e})=>{const t=k(E,this.eventInfo(e.event));Object.assign(t,e.detail||{}),A(this,t)}),[_,d,n,s,r,a,u,e].forEach(e=>{E.on(e,e=>{A(this,k(E,this.eventInfo(e.type)))})}),[l,c,f,p,h,i,o].forEach(e=>{E.on(e,e=>{A(this,k(E,this.eventInfo(e.type)))})}),E.on("volumechange",F(800,e=>{const t=k(E,this.eventInfo(e.type));A(this,U(t,{volume:parseFloat(E.volume.toFixed(2)),muted:E.muted}))})),E.on("resize",F(800,e=>{const t=k(E,this.eventInfo(e.type));A(this,U(t,{height:v.clientHeight,width:v.clientWidth}))})),E.on("qualitychange",({type:e,detail:t})=>{switch(t.kind){case"hls":return L(this,E,e,t)}});let g=Date.now()+5e3;E.on("timeupdate",e=>{if(Date.now()<g)return;g=Date.now()+5e3;const t=k(E,this.eventInfo(e.type));var n;A(this,U(t,{duration:(n=E.duration,Number.isFinite(n)?n:n===1/0?-1:void 0)}))}),E.addEventListener("error",e=>{const t=k(E,this.eventInfo(e.type)),n=e.error||E.error;if(!n)return A(this,t,!0);const i=n.code,o={error_message:n.message||j(i),error_code:i,error_stack:n.stack||""};return A(this,U(t,o),!0)}),E.on("src",e=>{var t;const n=null===(t=e.detail)||void 0===t?void 0:t.src;if("string"!=typeof n)return;if(!m(E.original_src))return;if(!m(n))return;if(n==E.original_src)return;this.media_session_id=B();A(this,k(E,this.eventInfo(e.type))),T(this)}),E.on("visibilitychange",e=>{A(this,k(E,this.eventInfo(e.type))),T(this)})}}return Health.events=t,Health._UNLOAD_SUBSCRIBED=!1,function(e,t){if("object"==typeof exports&&"undefined"!=typeof module)return t;"flowplayer"in e||(e.flowplayer={extensions:[]});const n=e.flowplayer;"function"==typeof n?n(t):(Array.isArray(n.extensions)||(n.extensions=[]),~n.extensions.indexOf(t)||n.extensions.push(t))}(window,Health),Health}));
|
package/plugins/ovp.js
CHANGED
|
@@ -1,15 +1 @@
|
|
|
1
|
-
!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.ovp=e())}(this,(function(){"use strict";
|
|
2
|
-
/*! *****************************************************************************
|
|
3
|
-
Copyright (c) Microsoft Corporation.
|
|
4
|
-
|
|
5
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
-
purpose with or without fee is hereby granted.
|
|
7
|
-
|
|
8
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
9
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
10
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
11
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
12
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
***************************************************************************** */const t=t=>"object"==typeof t&&null!==t&&!Array.isArray(t),e=(...n)=>n.reduce((n,o)=>t(o)?(Object.keys(o).forEach(i=>{if(t(n[i])&&t(o[i]))return n[i]=e(n[i],o[i]);n[i]=o[i]}),n):n,{});class Pipe{constructor(t){this.data=t}static of(t){return new Pipe(t)}static maybe(t,e,...n){return null==t?t:e.apply(t,[t,...n])}tap(t,...e){return t.apply(this,[this.data,...e]),new Pipe(this.data)}fmap(t,...e){const n=t.apply(this,[this.data,...e]);return new Pipe(n)}unwrap(){return this.data}}const n="https://ljsp.lwcdn.com".concat("/web/public/countdown/time.json"),o=window,i=o._flowplayerTimekeeper||(o._flowplayerTimekeeper={});function r(t){return fetch(t).then(t=>t.json())}function a(){let t=[].join.call(arguments,"/");return"/"!==t[0]&&(t="/"+t),s()+"/web/public/native/config"+t}const s=()=>"https://ljsp.lwcdn.com";function l(t){(async function(){const t=i.cachedServerOffset;if(t)return t;const e=i.pendingRequest||(i.pendingRequest=fetch(n)),o=await e,r=parseInt(o.headers.get("age")||"0"),a=await o.json(),s=Date.now()-a.millisUtc-1e3*r;return i.cachedServerOffset=s,i.cachedServerOffset})().then(e=>Object.assign(t,{server_time_offset:e}))}function c(t){return~t.indexOf("/")?t:"/media/"+t}var d={404:"media not found",402:"invalid subscription",400:"bad request",415:"unsupported media type"};function u(t){const e=t.ima,n=t.duration;if(!e||!n)return t;const o=null==e?void 0:e.ads;return Array.isArray(o)&&(e.ads=o.map((function(t){return"number"==typeof t.percentage&&(t.time=t.percentage*n),t}))),t}function p(t,n){var o,i;n="object"==typeof n?n:{};const r={title:null===(o=null==t?void 0:t.metadata)||void 0===o?void 0:o.title,description:null===(i=null==t?void 0:t.metadata)||void 0===i?void 0:i.description},a={ima:{parameters:function({media_id:t,duration:e,title:n,tags:o,category_name:i,ad_keywords:r}){return{ad_keywords:r||"",media_id:t||"",category:i||"",media_name:n||"",media_tags:o||"",media_duration:e||-1}}((null==t?void 0:t.metadata)||{})}},s=n.embed||{};return delete s.src,e(a,r,t,(delete(l=n).src,delete l.metadata,delete l.title,delete l.description,delete l.duration,delete l.poster,l),s);var l}const m=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/;function f(t){return"object"==typeof t&&"ovp/base64"==t.type}function v(t,e){return function(t,e){return!t.startsWith("blob:")&&(!(~t.indexOf(".")||!m.test(t))&&(e.type="video/ovp",!0))}(t,e)||f(e)}function y(t){try{return function(t){return null===t?{}:JSON.parse(t)}(decodeURIComponent(atob(t).split("").map((function(t){return"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)})).join("")))}catch(t){return{err:t.message}}}function h(t){const e=t.split(/[^0-9]/).map(t=>parseInt(t,10));return Date.UTC(e[0],e[1]-1,e[2],e[3],e[4],e[5])}function w(t){return t.live}var _=Object.freeze({__proto__:null,OVP_ERROR:"ovp:error",OVP_MEDIA_REQUEST_START:"ovp:request:start",OVP_MEDIA_REQUEST_COMPLETE:"ovp:request:media:complete",OVP_PLAYLIST_REQUEST_COMPLETE:"ovp:request:playlist:complete",LIVE_COUNTDOWN_TICK:"ovp:live:countdown:tick",LIVE_COUNTDOWN_START:"ovp:live:countdown:start",LIVE_COUNTDOWN_COMPLETE:"ovp:live:countdown:complete",OVP_MEDIA_CHANGED:"ovp:media:changed",OVP_REALTIME_MESSAGE:"ovp:message:realtime"});function g(t,e){const n=null==e?void 0:e.src;if(f(e))return function(t,e){const n=y(e.src||"");if(function(t){return"string"==typeof t.err}(n))return console.error(n.err);b(t,n)}(t,e);n&&Pipe.of(n).fmap(c).fmap(a).fmap(t=>fetch(t)).fmap(e=>e.then(t=>Promise.all([t.status,t.json()])).then(([e,n])=>200==e?b(t,n):E(t,n)))}function b(t,n){return t.emit("ovp:media:changed",n),function(t){return Array.isArray(t.playlist)}(n)?function(t,n){if("function"!=typeof window.flowplayer.playlist)return console.warn("OVP responded with Playlist media but the playlist plugin does not exist"),E(t,{status:415});t.emit("ovp:request:playlist:complete",function(t,n){const o=Object.assign({},t),i=(null==t?void 0:t.playlist)||{},r=e(n,i),a=((null==r?void 0:r.playlist)||[]).map(t=>p(t,o));return Object.assign(r,{playlist:a})}(t.opts,n))}(t,n):w(n)?function(t,e){var n,o;const i=(null===(n=null==e?void 0:e.metadata)||void 0===n?void 0:n.live_start_time)||(null===(o=null==e?void 0:e.metadata)||void 0===o?void 0:o.starttime);i&&(e.live_start_time=Pipe.of(i).fmap(h).unwrap());t.emit("ovp:live:countdown:start",Pipe.of(e).fmap(p,t.opts).fmap(u).unwrap())}(t,n):function(t,e){t.emit("ovp:request:media:complete",Pipe.of(e).fmap(p,t.opts).fmap(u).unwrap())}(t,n)}function E(t,e){return e.message?t.emit("ovp:error",e):e.status?t.emit("ovp:error",new Error(d[e.status])):t.emit("ovp:error",e)}const O={};function P(t,e,n){"object"!=typeof O[e]&&(O[e]=n);const o=t.opts,i=(null==o?void 0:o.metadata)||{};i.player_id=e,o.metadata=i,n.title&&delete n.title,n.description&&delete n.description;const r=Object.assign(o,n);t.setOpts(r),n.autoplay&&t.togglePlay(!0)}let j=!1;function A(t,e,n){T()||Pipe.of("recommendation").fmap(a,e,n).fmap(r).fmap(e=>e.then(e=>function(t,e){const n=e.playlist;if(t.opts.recommendations=n,!n.length)return;t.emit("recommendationsready",{playlist:n.map((function(t){var e;return{poster:t.poster,src:t.src,title:null===(e=null==t?void 0:t.metadata)||void 0===e?void 0:e.title,metadata:t.metadata||{}}}))})}(t,e)).catch(L))}function T(){return j}function L(t){j=!0,console.error("Failed to load recommendations: %j",t)}function C(t){const e="number"==typeof t?t:parseInt(t,10);return(e>9?"":"0")+e}function x(t,e){const n=t._customElements.get(e);return n&&t.root.querySelector(n)||void 0}const S="flowplayer-live-countdown";function M(t){return t&&t.live_start_time&&t.live_start_time-Date.now()>0}function D(t,e){let n=0;function o(){return function(t,e){const n=Date.now()-e;return Math.floor((t-n)/1e3)}(e.live_start_time||0,e.server_time_offset||0)}function i(){const i=o();if(i<0||isNaN(i)||0===t.reaper)return clearInterval(n),function(t,e){t.emit("ovp:live:countdown:complete");const n=x(t,S);n&&n.remove(),t.root.classList.remove("is-livecountdown"),t.emit("ovp:request:media:complete",e)}(t,e);var r,a,s;r=t,a=t.root,s=i,a.classList.add("is-livecountdown"),r.emit("ovp:live:countdown:tick",{remaining_time:I(s+1)}),r.hasState("is-starting")||r.setState("is-starting",!0)}l(e),i(),n=setInterval(i,250)}function I(t){const e=function(t){"number"!=typeof t&&(t=parseInt(t,10)),t=Math.round(t);const e=Math.floor(t/86400);t-=86400*e;const n=Math.floor(t/3600);t-=3600*n;const o=Math.floor(t/60);return{days:e,hours:n,minutes:o,seconds:t-=60*o}}(t);let n="";return e.days&&(n+=e.days+":"),n+C(e.hours)+":"+C(e.minutes)+":"+C(e.seconds)}class WebsocketBridge{constructor(t){this.manualDisconnect=!1,this.video=t,this.onClose=this.onClose.bind(this),this.onMessage=this.onMessage.bind(this)}static of(t){return new WebsocketBridge(t)}connect(t){this.client=new WebSocket("wss://player.ws.flowplayer.com?mediaId="+t),this.current_media_id=t,this.wireup()}onClose(){this.manualDisconnect?this.manualDisconnect=!1:this.current_media_id&&this.reconnect(this.current_media_id)}onMessage(t){JSON.parse(t.data).forEach(t=>{this.video.emit("ovp:message:realtime",t)})}reconnect(t){this.cleanup(),this.connect(t)}wireup(){this.client&&(this.client.addEventListener("message",this.onMessage),this.client.addEventListener("close",this.onClose))}cleanup(){this.client&&(this.client.removeEventListener("message",this.onMessage),this.client.removeEventListener("close",this.onClose),this.client=void 0)}disconnect(){this.client&&(this.manualDisconnect=!0,this.client.close())}}const k=(t,e)=>new(((t,e)=>{const n=t.get(e);if(!n)throw new Error(`no flowplayer component with the name ${e} exists`);const o=window.customElements.get(e);if(!o)throw new Error(`no default flowplayer component with the name ${e} exists`);const i=window.customElements.get(n);return"function"!=typeof i?o:i})(t._customElements,e))(t);class FlowplayerComponent extends HTMLElement{constructor(t){super(),this.player=t}}class FlowplayerLiveCountdown extends FlowplayerComponent{constructor(t){super(t),this.classList.add("fp-livecountdown");const e=function(...t){const e=document.createElement("div");return 0==t.length||e.classList.add(...t),e}("fp-inner");this.append(e);const n=document.createElement("p");n.innerText=t.i18n("ovp.starting_in"),e.append(n);const o=document.createElement("p");o.classList.add("fp-countdown"),e.append(o),t.on("ovp:live:countdown:tick",e=>{const n=e.detail.remaining_time;t.root.classList.add("is-livecountdown"),o.innerText=n})}}const q=["*.lwcdn.com","*.flowplayer.com"];function V(){try{return window.location.hostname!==window.parent.location.hostname?function(t){const e=document.createElement("a");return e.href=t,e}(document.referrer).hostname:document.location.hostname}catch(t){return window.location.hostname}}class OVP{constructor(t){((t,e,n)=>{window.customElements.get(e)||window.customElements.define(e,n),t.customElements.get(e)||t.customElements.set(e,e)})(t,S,FlowplayerLiveCountdown)}onload(t,e,n,o){if("string"==typeof o.src)return"string"!=typeof t.player_id||0===o.src.indexOf(t.player_id)||f(o)||(o.src=[t.player_id,o.src].join("/")),g(n,o)}wants(t,e,n){return v(t,e)}init(t,n,o){const i=new WebsocketBridge(o);let s=Object.assign({},t);const l=function(t){if(!s)return t;delete s.src;const n=e(t,s);return s=!1,n};o.on("ovp:error",(function(t){o.emit("error",t.data)})),o.on("ovp:request:start",(function(){o.setState("is-waiting",!0),t.recommendations&&(t.recommendations=!1)})),o.on("ovp:media:changed",(function({data:t}){var e;const n=null===(e=null==t?void 0:t.metadata)||void 0===e?void 0:e.media_id;(null==t?void 0:t.live)&&n&&(i.disconnect(),i.connect(n))})),o.on("ovp:message:realtime",(function({data:e}){var n;const i=null==e?void 0:e.event,r=null==e?void 0:e.value,a=o.opt("metadata",{live_start_time:""});switch(i){case"METADATA":{const e=Object.assign(a,r),i=Object.assign(t,{metadata:e});i.live&&(null===(n=null==i?void 0:i.metadata)||void 0===n?void 0:n.live_start_time)&&(i.live_start_time=h(i.metadata.live_start_time)),o.setOpts(i);break}}})),o.on("beforeplay",(function(e){const n=t;if(w(n)){if(R(n))return;e.preventDefault()}})),o.on("ovp:request:media:complete",(function(t){const e=t.data;if(!e)return;if(0==o.reaper||"object"!=typeof t.data||M(t.data))return;const n=l(e);o.setOpts(n),o.setAttrs(n),n.src&&o.setSrc(n.src),n.autoplay&&o.togglePlay(!0)})),o.on("config",(function({data:e}){var i,s;if("string"==typeof t.src&&v(t.src,{}))return;if(t.src&&N(t.src))return;if((null==e?void 0:e.domains)&&(null==e?void 0:e.domains.length)&&!((t,e)=>{const n=t.split(".").reverse();return e.concat(q).some(t=>{const e=t.split(".").reverse(),o="*"===e[e.length-1];return o&&e.pop(),(o||e.length===n.length)&&e.every((t,e)=>n[e]===t)})})(V(),e.domains))return function({root:t,video:e,data:n}){e&&e.destroy(),console.error(new Error(n.details||n.reason)),t.innerHTML="",t.classList.remove("flowplayer"),t.classList.add("flowplayer-fatal"),t.style.removeProperty("background-image");const o=document.createElement("h2");o.textContent="Playback Error";const i=document.createElement("p");i.textContent="Are you the site owner?";const r=document.createElement("a");r.classList.add("troubleshoot"),r.target="_blank",r.href="https://docs.flowplayer.com/troubleshooting/player#"+n.reason,r.textContent="Troubleshoot?";const a=document.createElement("img");a.src="https://flowplayer.com/user/pages/images/logo-white.png",t.append(o,i,r,a)}({root:n,video:o,data:{details:`Hostname ${window.location.hostname} is not allowed to load player ${null===(i=e.metadata)||void 0===i?void 0:i.player_id}.`,reason:"domain"}});const l=null==e?void 0:e.brand_color;return l&&o.root.style.setProperty("--fp-brand-color","#"==l[0]?l:"#"+l),"string"==typeof t.player_id&&(null===(s=null==t?void 0:t.metadata)||void 0===s?void 0:s.player_id)!==t.player_id?function(t,e){if("object"==typeof O[e])return console.debug("using Cache(%s)",e),P(t,e,O[e]);Pipe.of(e).fmap(a).fmap(r).fmap(n=>n.then(n=>P(t,e,n)).catch(console.error))}(o,t.player_id):void 0})),o.on("ovp:request:playlist:complete",(function(t){const e=t.data;if(!e||0==o.reaper)return;const{playlist:n}=e,i=function(t,e){var n={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(t);i<o.length;i++)e.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(t,o[i])&&(n[o[i]]=t[o[i]])}return n}(e,["playlist"]),r=l({playlist:i});Array.isArray(r.playlist)&&(r.playlist=i),o.setOpts(r);const a={type:"flowplayer/playlist",items:n};o.setSrc(a)})),o.on("ovp:live:countdown:start",(function(e){const i=e.data;if(!i||0==o.reaper)return;const r=l(i);if(o.setOpts(r),o.setAttrs(r),!M(i))return o.emit("ovp:request:media:complete",i);x(o,S)||(n.appendChild(k(o,S)),D(o,t))})),o.on("timeupdate",(function(){var e,n,i;const r=t;w(r)?R(r)||(o.togglePlay(!1),o.emit("ended")):t.recommendations&&(null===(e=null==t?void 0:t.metadata)||void 0===e?void 0:e.media_id)&&(Array.isArray(t.recommendations)||o.currentTime/o.duration<.8||T()||(null===(n=null==t?void 0:t.metadata)||void 0===n?void 0:n.media_id)&&(null===(i=null==t?void 0:t.metadata)||void 0===i?void 0:i.player_id)&&A(o,t.metadata.media_id,t.metadata.player_id))})),o.on("reap",(function(){i.disconnect()}))}}function R(t){var e,n;const o=null===(e=null==t?void 0:t.metadata)||void 0===e?void 0:e.live_stop_time;if(!o)return!0;return!!(null===(n=null==t?void 0:t.metadata)||void 0===n?void 0:n.allow_after_stop_time)||h(o)>Date.now()}OVP.events=_;const N=t=>{var e;if(t&&Array.isArray(t))return"object"==typeof t[0]&&"ovp/base64"===(null===(e=t[0])||void 0===e?void 0:e.type)};return function(t,e){if("object"==typeof exports&&"undefined"!=typeof module)return e;"flowplayer"in t||(t.flowplayer={extensions:[]});const n=t.flowplayer;"function"==typeof n?n(e):(Array.isArray(n.extensions)||(n.extensions=[]),~n.extensions.indexOf(e)||n.extensions.push(e))}(window,OVP),OVP}));
|
|
1
|
+
!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.ovp=e())}(this,(function(){"use strict";const t=t=>"object"==typeof t&&null!==t&&!Array.isArray(t),e=(...n)=>n.reduce((n,o)=>t(o)?(Object.keys(o).forEach(i=>{if(t(n[i])&&t(o[i]))return n[i]=e(n[i],o[i]);n[i]=o[i]}),n):n,{});class Pipe{constructor(t){this.data=t}static of(t){return new Pipe(t)}static maybe(t,e,...n){return null==t?t:e.apply(t,[t,...n])}tap(t,...e){return t.apply(this,[this.data,...e]),new Pipe(this.data)}fmap(t,...e){const n=t.apply(this,[this.data,...e]);return new Pipe(n)}unwrap(){return this.data}}const n="https://ljsp.lwcdn.com".concat("/web/public/countdown/time.json"),o=window,i=o._flowplayerTimekeeper||(o._flowplayerTimekeeper={});function r(t){return fetch(t).then(t=>t.json())}function a(){let t=[].join.call(arguments,"/");return"/"!==t[0]&&(t="/"+t),s()+"/web/public/native/config"+t}const s=()=>"https://ljsp.lwcdn.com";function l(t){(async function(){const t=i.cachedServerOffset;if(t)return t;const e=i.pendingRequest||(i.pendingRequest=fetch(n)),o=await e,r=parseInt(o.headers.get("age")||"0"),a=await o.json(),s=Date.now()-a.millisUtc-1e3*r;return i.cachedServerOffset=s,i.cachedServerOffset})().then(e=>Object.assign(t,{server_time_offset:e}))}function c(t){return~t.indexOf("/")?t:"/media/"+t}var d={404:"media not found",402:"invalid subscription",400:"bad request",415:"unsupported media type"};function u(t){const e=t.ima,n=t.duration;if(!e||!n)return t;const o=null==e?void 0:e.ads;return Array.isArray(o)&&(e.ads=o.map((function(t){return"number"==typeof t.percentage&&(t.time=t.percentage*n),t}))),t}function p(t,n){var o,i;n="object"==typeof n?n:{};const r={title:null===(o=null==t?void 0:t.metadata)||void 0===o?void 0:o.title,description:null===(i=null==t?void 0:t.metadata)||void 0===i?void 0:i.description},a={ima:{parameters:function({media_id:t,duration:e,title:n,tags:o,category_name:i,ad_keywords:r}){return{ad_keywords:r||"",media_id:t||"",category:i||"",media_name:n||"",media_tags:o||"",media_duration:e||-1}}((null==t?void 0:t.metadata)||{})}},s=n.embed||{};return delete s.src,e(a,r,t,(delete(l=n).src,delete l.metadata,delete l.title,delete l.description,delete l.duration,delete l.poster,l),s);var l}const m=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/;function f(t){return"object"==typeof t&&"ovp/base64"==t.type}function v(t,e){return function(t,e){return!t.startsWith("blob:")&&(!(~t.indexOf(".")||!m.test(t))&&(e.type="video/ovp",!0))}(t,e)||f(e)}function y(t){try{return function(t){return null===t?{}:JSON.parse(t)}(decodeURIComponent(atob(t).split("").map((function(t){return"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)})).join("")))}catch(t){return{err:t.message}}}function h(t){const e=t.split(/[^0-9]/).map(t=>parseInt(t,10));return Date.UTC(e[0],e[1]-1,e[2],e[3],e[4],e[5])}function w(t){return t.live}var _=Object.freeze({__proto__:null,OVP_ERROR:"ovp:error",OVP_MEDIA_REQUEST_START:"ovp:request:start",OVP_MEDIA_REQUEST_COMPLETE:"ovp:request:media:complete",OVP_PLAYLIST_REQUEST_COMPLETE:"ovp:request:playlist:complete",LIVE_COUNTDOWN_TICK:"ovp:live:countdown:tick",LIVE_COUNTDOWN_START:"ovp:live:countdown:start",LIVE_COUNTDOWN_COMPLETE:"ovp:live:countdown:complete",OVP_MEDIA_CHANGED:"ovp:media:changed",OVP_REALTIME_MESSAGE:"ovp:message:realtime"});function g(t,e){const n=null==e?void 0:e.src;if(f(e))return function(t,e){const n=y(e.src||"");if(function(t){return"string"==typeof t.err}(n))return console.error(n.err);b(t,n)}(t,e);n&&Pipe.of(n).fmap(c).fmap(a).fmap(t=>fetch(t)).fmap(e=>e.then(t=>Promise.all([t.status,t.json()])).then(([e,n])=>200==e?b(t,n):E(t,n)))}function b(t,n){return t.emit("ovp:media:changed",n),function(t){return Array.isArray(t.playlist)}(n)?function(t,n){if("function"!=typeof window.flowplayer.playlist)return console.warn("OVP responded with Playlist media but the playlist plugin does not exist"),E(t,{status:415});t.emit("ovp:request:playlist:complete",function(t,n){const o=Object.assign({},t),i=(null==t?void 0:t.playlist)||{},r=e(n,i),a=((null==r?void 0:r.playlist)||[]).map(t=>p(t,o));return Object.assign(r,{playlist:a})}(t.opts,n))}(t,n):w(n)?function(t,e){var n,o;const i=(null===(n=null==e?void 0:e.metadata)||void 0===n?void 0:n.live_start_time)||(null===(o=null==e?void 0:e.metadata)||void 0===o?void 0:o.starttime);i&&(e.live_start_time=Pipe.of(i).fmap(h).unwrap());t.emit("ovp:live:countdown:start",Pipe.of(e).fmap(p,t.opts).fmap(u).unwrap())}(t,n):function(t,e){t.emit("ovp:request:media:complete",Pipe.of(e).fmap(p,t.opts).fmap(u).unwrap())}(t,n)}function E(t,e){return e.message?t.emit("ovp:error",e):e.status?t.emit("ovp:error",new Error(d[e.status])):t.emit("ovp:error",e)}const O={};function P(t,e,n){"object"!=typeof O[e]&&(O[e]=n);const o=t.opts,i=(null==o?void 0:o.metadata)||{};i.player_id=e,o.metadata=i,n.title&&delete n.title,n.description&&delete n.description;const r=Object.assign(o,n);t.setOpts(r),n.autoplay&&t.togglePlay(!0)}let j=!1;function A(t,e,n){T()||Pipe.of("recommendation").fmap(a,e,n).fmap(r).fmap(e=>e.then(e=>function(t,e){const n=e.playlist;if(t.opts.recommendations=n,!n.length)return;t.emit("recommendationsready",{playlist:n.map((function(t){var e;return{poster:t.poster,src:t.src,title:null===(e=null==t?void 0:t.metadata)||void 0===e?void 0:e.title,metadata:t.metadata||{}}}))})}(t,e)).catch(L))}function T(){return j}function L(t){j=!0,console.error("Failed to load recommendations: %j",t)}function C(t){const e="number"==typeof t?t:parseInt(t,10);return(e>9?"":"0")+e}function x(t,e){const n=t._customElements.get(e);return n&&t.root.querySelector(n)||void 0}const S="flowplayer-live-countdown";function M(t){return t&&t.live_start_time&&t.live_start_time-Date.now()>0}function D(t,e){let n=0;function o(){return function(t,e){const n=Date.now()-e;return Math.floor((t-n)/1e3)}(e.live_start_time||0,e.server_time_offset||0)}function i(){const i=o();if(i<0||isNaN(i)||0===t.reaper)return clearInterval(n),function(t,e){t.emit("ovp:live:countdown:complete");const n=x(t,S);n&&n.remove(),t.root.classList.remove("is-livecountdown"),t.emit("ovp:request:media:complete",e)}(t,e);var r,a,s;r=t,a=t.root,s=i,a.classList.add("is-livecountdown"),r.emit("ovp:live:countdown:tick",{remaining_time:I(s+1)}),r.hasState("is-starting")||r.setState("is-starting",!0)}l(e),i(),n=setInterval(i,250)}function I(t){const e=function(t){"number"!=typeof t&&(t=parseInt(t,10)),t=Math.round(t);const e=Math.floor(t/86400);t-=86400*e;const n=Math.floor(t/3600);t-=3600*n;const o=Math.floor(t/60);return{days:e,hours:n,minutes:o,seconds:t-=60*o}}(t);let n="";return e.days&&(n+=e.days+":"),n+C(e.hours)+":"+C(e.minutes)+":"+C(e.seconds)}class WebsocketBridge{constructor(t){this.manualDisconnect=!1,this.video=t,this.onClose=this.onClose.bind(this),this.onMessage=this.onMessage.bind(this)}static of(t){return new WebsocketBridge(t)}connect(t){this.client=new WebSocket("wss://player.ws.flowplayer.com?mediaId="+t),this.current_media_id=t,this.wireup()}onClose(){this.manualDisconnect?this.manualDisconnect=!1:this.current_media_id&&this.reconnect(this.current_media_id)}onMessage(t){JSON.parse(t.data).forEach(t=>{this.video.emit("ovp:message:realtime",t)})}reconnect(t){this.cleanup(),this.connect(t)}wireup(){this.client&&(this.client.addEventListener("message",this.onMessage),this.client.addEventListener("close",this.onClose))}cleanup(){this.client&&(this.client.removeEventListener("message",this.onMessage),this.client.removeEventListener("close",this.onClose),this.client=void 0)}disconnect(){this.client&&(this.manualDisconnect=!0,this.client.close())}}const k=(t,e)=>new(((t,e)=>{const n=t.get(e);if(!n)throw new Error(`no flowplayer component with the name ${e} exists`);const o=window.customElements.get(e);if(!o)throw new Error(`no default flowplayer component with the name ${e} exists`);const i=window.customElements.get(n);return"function"!=typeof i?o:i})(t._customElements,e))(t);class FlowplayerComponent extends HTMLElement{constructor(t){super(),this.player=t}}class FlowplayerLiveCountdown extends FlowplayerComponent{constructor(t){super(t),this.classList.add("fp-livecountdown");const e=function(...t){const e=document.createElement("div");return 0==t.length||e.classList.add(...t),e}("fp-inner");this.append(e);const n=document.createElement("p");n.innerText=t.i18n("ovp.starting_in"),e.append(n);const o=document.createElement("p");o.classList.add("fp-countdown"),e.append(o),t.on("ovp:live:countdown:tick",e=>{const n=e.detail.remaining_time;t.root.classList.add("is-livecountdown"),o.innerText=n})}}const q=["*.lwcdn.com","*.flowplayer.com"];function V(){try{return window.location.hostname!==window.parent.location.hostname?function(t){const e=document.createElement("a");return e.href=t,e}(document.referrer).hostname:document.location.hostname}catch(t){return window.location.hostname}}class OVP{constructor(t){((t,e,n)=>{window.customElements.get(e)||window.customElements.define(e,n),t.customElements.get(e)||t.customElements.set(e,e)})(t,S,FlowplayerLiveCountdown)}onload(t,e,n,o){if("string"==typeof o.src)return"string"!=typeof t.player_id||0===o.src.indexOf(t.player_id)||f(o)||(o.src=[t.player_id,o.src].join("/")),g(n,o)}wants(t,e,n){return v(t,e)}init(t,n,o){const i=new WebsocketBridge(o);let s=Object.assign({},t);const l=function(t){if(!s)return t;delete s.src;const n=e(t,s);return s=!1,n};o.on("ovp:error",(function(t){o.emit("error",t.data)})),o.on("ovp:request:start",(function(){o.setState("is-waiting",!0),t.recommendations&&(t.recommendations=!1)})),o.on("ovp:media:changed",(function({data:t}){var e;const n=null===(e=null==t?void 0:t.metadata)||void 0===e?void 0:e.media_id;(null==t?void 0:t.live)&&n&&(i.disconnect(),i.connect(n))})),o.on("ovp:message:realtime",(function({data:e}){var n;const i=null==e?void 0:e.event,r=null==e?void 0:e.value,a=o.opt("metadata",{live_start_time:""});switch(i){case"METADATA":{const e=Object.assign(a,r),i=Object.assign(t,{metadata:e});i.live&&(null===(n=null==i?void 0:i.metadata)||void 0===n?void 0:n.live_start_time)&&(i.live_start_time=h(i.metadata.live_start_time)),o.setOpts(i);break}}})),o.on("beforeplay",(function(e){const n=t;if(w(n)){if(R(n))return;e.preventDefault()}})),o.on("ovp:request:media:complete",(function(t){const e=t.data;if(!e)return;if(0==o.reaper||"object"!=typeof t.data||M(t.data))return;const n=l(e);o.setOpts(n),o.setAttrs(n),n.src&&o.setSrc(n.src),n.autoplay&&o.togglePlay(!0)})),o.on("config",(function({data:e}){var i,s;if("string"==typeof t.src&&v(t.src,{}))return;if(t.src&&N(t.src))return;if((null==e?void 0:e.domains)&&(null==e?void 0:e.domains.length)&&!((t,e)=>{const n=t.split(".").reverse();return e.concat(q).some(t=>{const e=t.split(".").reverse(),o="*"===e[e.length-1];return o&&e.pop(),(o||e.length===n.length)&&e.every((t,e)=>n[e]===t)})})(V(),e.domains))return function({root:t,video:e,data:n}){e&&e.destroy(),console.error(new Error(n.details||n.reason)),t.innerHTML="",t.classList.remove("flowplayer"),t.classList.add("flowplayer-fatal"),t.style.removeProperty("background-image");const o=document.createElement("h2");o.textContent="Playback Error";const i=document.createElement("p");i.textContent="Are you the site owner?";const r=document.createElement("a");r.classList.add("troubleshoot"),r.target="_blank",r.href="https://docs.flowplayer.com/troubleshooting/player#"+n.reason,r.textContent="Troubleshoot?";const a=document.createElement("img");a.src="https://flowplayer.com/user/pages/images/logo-white.png",t.append(o,i,r,a)}({root:n,video:o,data:{details:`Hostname ${window.location.hostname} is not allowed to load player ${null===(i=e.metadata)||void 0===i?void 0:i.player_id}.`,reason:"domain"}});const l=null==e?void 0:e.brand_color;return l&&o.root.style.setProperty("--fp-brand-color","#"==l[0]?l:"#"+l),"string"==typeof t.player_id&&(null===(s=null==t?void 0:t.metadata)||void 0===s?void 0:s.player_id)!==t.player_id?function(t,e){if("object"==typeof O[e])return console.debug("using Cache(%s)",e),P(t,e,O[e]);Pipe.of(e).fmap(a).fmap(r).fmap(n=>n.then(n=>P(t,e,n)).catch(console.error))}(o,t.player_id):void 0})),o.on("ovp:request:playlist:complete",(function(t){const e=t.data;if(!e||0==o.reaper)return;const{playlist:n}=e,i=function(t,e){var n={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(t);i<o.length;i++)e.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(t,o[i])&&(n[o[i]]=t[o[i]])}return n}(e,["playlist"]),r=l({playlist:i});Array.isArray(r.playlist)&&(r.playlist=i),o.setOpts(r);const a={type:"flowplayer/playlist",items:n};o.setSrc(a)})),o.on("ovp:live:countdown:start",(function(e){const i=e.data;if(!i||0==o.reaper)return;const r=l(i);if(o.setOpts(r),o.setAttrs(r),!M(i))return o.emit("ovp:request:media:complete",i);x(o,S)||(n.appendChild(k(o,S)),D(o,t))})),o.on("timeupdate",(function(){var e,n,i;const r=t;w(r)?R(r)||(o.togglePlay(!1),o.emit("ended")):t.recommendations&&(null===(e=null==t?void 0:t.metadata)||void 0===e?void 0:e.media_id)&&(Array.isArray(t.recommendations)||o.currentTime/o.duration<.8||T()||(null===(n=null==t?void 0:t.metadata)||void 0===n?void 0:n.media_id)&&(null===(i=null==t?void 0:t.metadata)||void 0===i?void 0:i.player_id)&&A(o,t.metadata.media_id,t.metadata.player_id))})),o.on("reap",(function(){i.disconnect()}))}}function R(t){var e,n;const o=null===(e=null==t?void 0:t.metadata)||void 0===e?void 0:e.live_stop_time;if(!o)return!0;return!!(null===(n=null==t?void 0:t.metadata)||void 0===n?void 0:n.allow_after_stop_time)||h(o)>Date.now()}OVP.events=_;const N=t=>{var e;if(t&&Array.isArray(t))return"object"==typeof t[0]&&"ovp/base64"===(null===(e=t[0])||void 0===e?void 0:e.type)};return function(t,e){if("object"==typeof exports&&"undefined"!=typeof module)return e;"flowplayer"in t||(t.flowplayer={extensions:[]});const n=t.flowplayer;"function"==typeof n?n(e):(Array.isArray(n.extensions)||(n.extensions=[]),~n.extensions.indexOf(e)||n.extensions.push(e))}(window,OVP),OVP}));
|
package/plugins/playlist.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!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.playlist=e())}(this,(function(){"use strict";var t={PLAYLIST_NEXT:"playlist:next",PLAYLIST_PREVIOUS:"playlist:previous",PLAYLIST_SELECTION:"playlist:selection",PLAYLIST_LOOP:"playlist:loop",PLAYLIST_ENDED:"playlist:ended",PLAYLIST_READY:"playlist:ready",PLAYLIST_ADD:"playlist:add",PLAYLIST_REMOVE:"playlist:remove",INTERSTITIAL_END:"interstitial/end",INTERSTITIAL_CANCEL:"interstitial/cancel",INTERSTITIAL_NEXT_ITEM:"interstitial/next_item"};const e={translation_key:"core.skip-next",name:"fp-skip-next"},n={translation_key:"core.skip-prev",name:"fp-skip-prev"};class Pipe{constructor(t){this.data=t}static of(t){return new Pipe(t)}static maybe(t,e,...n){return null==t?t:e.apply(t,[t,...n])}tap(t,...e){return t.apply(this,[this.data,...e]),new Pipe(this.data)}fmap(t,...e){const n=t.apply(this,[this.data,...e]);return new Pipe(n)}unwrap(){return this.data}}function i(t,e){if(!e)throw new Error(t)}function s(t){return"invalid playlist configuration\ndetails: "+t+"\n\tmust match Object of shape:\n"+["\t\t{ controls?: Selector|HTMLElement","player: Selector|HTMLElement","playlist: PlaylistId|Array(MediaId|PlayerConfig)","shuffle?: Boolean|false","loop?: Boolean|false","advance?: Boolean|true","delay?: Milliseconds|5000"].join("\n\t\t, ")+"\n\t\t}"}function o(t,e){Pipe.of(t).fmap(s).fmap(i,e)}function l(t){return void 0!==t}function r(t){return"string"==typeof t}function a(t){return"object"==typeof t}function c(t){return t instanceof HTMLElement}function u(t){var e;o("Config must be an Object",l(t)&&a(t)),o("property `playlist` is required",l(t.playlist)),o("property `playlist` was not a String(MediaId)",r(t.playlist)||(e=t.playlist,o("playlist property was not of type PlaylistId|Array(MediaId|PlayConfig)",Array.isArray(e)),o("playlist property cannot be an empty Array",e.length>0),!e.forEach((function(t,e){o("item at playlist["+e+"] was not valid",r(t)||a(t))})))),"loop shuffle".split(" ").forEach((function(e){l(t[e])&&o(e+" must be a boolean value if present","boolean"==typeof t[e])})),l(t.delay)&&o("property `delay` must be a Number (Milliseconds)","number"==typeof t.delay)}function p(t){try{u(t)}catch(t){return!1}return!0}class FlowplayerComponent extends HTMLElement{constructor(t){super(),this.player=t}}class FlowplayerIcon extends FlowplayerComponent{constructor(t,e){super(t),this.classList.add("fp-icon",e.name),e.title&&this.setAttribute("title",e.title),e.title&&this.setAttribute("aria-label",e.title),this.setAttribute("tabindex","0"),this.setAttribute("focusable","true")}}const d=["title","delay","description","poster","src"];class UpNext extends FlowplayerComponent{static get observedAttributes(){return d}constructor(e){super(e),this.classList.add("up-next"),this.addEventListener("animationend",()=>{this.dispatchEvent(new CustomEvent(t.INTERSTITIAL_END))}),this.addEventListener("animationcancel",()=>{this.classList.add("cancelled"),this.dispatchEvent(new CustomEvent(t.INTERSTITIAL_CANCEL))}),this.addEventListener(t.INTERSTITIAL_NEXT_ITEM,this._setUpNext.bind(this))}getTitle(){return this.getAttribute("title")||""}getDescription(){return this.getAttribute("description")||""}getPoster(){return this.getAttribute("poster")||""}getDelay(){return this.getAttribute("delay")||""}connectedCallback(){this.isConnected&&this._render()}attributeChangedCallback(){this._render()}_render(){var e,n;this.innerHTML="",this.classList.remove("cancelled");const i=document.createDocumentFragment(),s=document.createElement("div");s.classList.add("pane","left");const o=document.createElement("div");o.classList.add("pane","right"),i.append(s,o);const l=document.createElement("div");l.classList.add("poster"),l.style.backgroundImage="url("+this.getPoster()+")",s.append(l),l.addEventListener("click",()=>this.dispatchEvent(new CustomEvent(t.INTERSTITIAL_END)));const r=document.createElement("span");r.classList.add("fp-icon","fp-play"),l.append(r);const a=document.createElement("span");a.classList.add("title"),a.textContent=this.getTitle();const c=document.createElement("span");c.classList.add("description"),c.textContent=this.getDescription();const u=document.createElement("span");u.classList.add("countdown"),this.getDelay()&&(u.style.setProperty("--up-next-delay",this.getDelay()+"s"),u.classList.add("go"));const p=document.createElement("span");p.classList.add("cancel"),p.textContent=null!==(n=null===(e=this.player)||void 0===e?void 0:e.i18n("playlist.cancel"))&&void 0!==n?n:"cancel",p.addEventListener("click",()=>u.classList.remove("go")),o.append(a,c,p,u),this.append(i)}_setUpNext(t){var e,n,i;const s=t.detail.next,o=this.player.opt("playlist.delay",void 0)||10;this.setAttribute("title",null!==(e=s.title)&&void 0!==e?e:""),this.setAttribute("description",null!==(n=s.description)&&void 0!==n?n:""),this.setAttribute("poster",null!==(i=s.poster)&&void 0!==i?i:""),this.setAttribute("delay",o+"")}}const y=(t,e)=>new(((t,e)=>{const n=t.get(e);if(!n)throw new Error(`no flowplayer component with the name ${e} exists`);const i=window.customElements.get(e);if(!i)throw new Error(`no default flowplayer component with the name ${e} exists`);const s=window.customElements.get(n);return"function"!=typeof s?i:s})(t._customElements,e))(t),f=(t,e,n)=>{window.customElements.get(e)||window.customElements.define(e,n),t.customElements.get(e)||t.customElements.set(e,e)};function m(t,e){const n=t._customElements.get(e);return n&&t.root.querySelector(n)||void 0}function h(t,e,n){return t.setAttribute(e,n),t}function v(t,e){return t.classList.add(...e.split(" ")),t}function L(t,e,n){return e.split(" ").forEach(e=>t.classList.toggle(e,n)),t}function E(...t){const e=document.createElement("div");return 0==t.length||e.classList.add(...t),e}function w(t,e,n){const i=function(t){return Array.isArray(t)?t.slice(0):t.split(".")}(e);for(;i.length;){if(null==t)return n;const e=i.shift();if("string"!=typeof e)return n;t=t[e]}return null==t?n:t}function b(t,e){if(!e[t])return;const n=document.createElement("span");n.innerText=e[t];const i=E(t);return i.append(n),i}class FlowplayerPlaylistControls extends FlowplayerComponent{constructor(e){super(e),e.on(t.PLAYLIST_READY,t=>{const n=w(t,"data.queue",w(e,"playlist.queue"));n&&this.list(n,e)}),e.on(t.PLAYLIST_NEXT,()=>{var t;(null===(t=e.playlist)||void 0===t?void 0:t.queue)&&Array.from(this.querySelectorAll("li")).forEach((t,n)=>{var i;n===(null===(i=e.playlist)||void 0===i?void 0:i.queue.idx)?t.className="is-current":t.className="is-queued"})}),e.on(["playing","pause"],t=>{const e=this.querySelector(".is-current");e&&(e.classList.toggle("is-playing","playing"===t.type),e.classList.toggle("is-paused","flowplayer-pause-icon"===t.type))}),e.on(t.PLAYLIST_ADD,t=>{var n;const i=null===(n=e.playlist)||void 0===n?void 0:n.queue;if(!t.data||!i)return;t.data.members.forEach(t=>{const n=this.videoRow(t,e);n&&this.append(n)})}),e.on(t.PLAYLIST_REMOVE,t=>{if(!t.data)return;const e=Array.from(this.querySelectorAll("li"))[t.data.index];e&&this.removeChild(e)})}list(t,e){this.innerHTML="",v(this,"fp-playlist"),t.members.forEach(t=>{const n=this.videoRow(t,e);n&&this.append(n)})}videoRow(t,e){if(!t.title)return;const n=document.createElement("li");var i,s;return n.classList.add("is-queued"),n.onclick=this.videoRow_onclick.bind(this,n,t,e),i=n,s=[E("fp-color"),this.videoInfo(t),this.buttons(t,e)],i.append(...s),n}videoRow_onclick(t,e,n){var i;if(t.classList.contains("is-current"))return n.togglePlay(!n.playerState["is-playing"]);const s=Array.from(this.querySelectorAll("li")).indexOf(t);-1!==s&&(null===(i=n.playlist)||void 0===i||i.play(s))}videoInfo(t){const e=E("video-info"),n=b("title",t);n&&e.append(n);const i=b("description",t);return i&&e.append(i),e}buttons(t,e){const n=E("video-buttons"),i=y(e,"flowplayer-play-icon"),s=y(e,"flowplayer-pause-icon");return n.append(i,s),t.poster&&(n.style.backgroundImage=["url(",t.poster,")"].join("")),n}}var g;function x(t,e){var n,i;const s=e.sort||I,o=null!==(n=e.mode)&&void 0!==n?n:g.FIFO;return t=s(t.slice(0),o),{mode:o,sort:s,members:t,last_idx:t.length-1,plays:null!==(i=e.plays)&&void 0!==i?i:0,idx:-1}}function A(t){return t.idx==t.last_idx}function I(t,e){return(e&g.SHUFFLE)==g.SHUFFLE?t.sort((function(){return Math.random()-Math.random()})):t.slice(0)}function T(t){return x(t.members,{mode:t.mode,plays:t.plays+1,sort:t.sort})}!function(t){t[t.SHUFFLE=1]="SHUFFLE",t[t.FIFO=2]="FIFO",t[t.LOOP=4]="LOOP"}(g||(g={}));!function(){let t=!1;try{const e=Object.defineProperty({},"passive",{get:function(){t=!0}});window.addEventListener("testPassive",null,e),window.removeEventListener("testPassive",null,e)}catch(t){}}();const _=["touchstart","touchmove"];function P(t,e,n){const i=function(t,e){const n=new CustomEvent(t,{detail:e,cancelable:!0});return e&&Object.defineProperty(n,"data",{get:()=>e}),n}(e,n);return t.dispatchEvent(i),t}function S(t,e,n,i){Array.isArray(e)?e.forEach(e=>q(t,e,n,i)):q(t,e,n,i)}function q(t,e,n,i){if(s=e,!~_.indexOf(s))return t.addEventListener(e,n,i),t;var s;const o=Object.assign(i||{},{passive:!0});return t.addEventListener(e,n,o),t}function O(e,n,i){const s=function(t){return++t.idx,t.members[t.idx]}(n),o=n.idx+n.plays<1;return function(t,e,n){"object"==typeof e&&t.setOpts(Object.assign(Object.assign({},e),{playlist:n}));N(t,{should_play:n.should_play})}(e,s,i),o&&i.autoplay?e.togglePlay(!0):o?e.setState("is-starting",!0):i.delay?void function(e,n){var i;const s=m(e,"flowplayer-playlist-interstitial");if(!s||!(null===(i=e.playlist)||void 0===i?void 0:i.queue)||!n.delay)return;e.root.classList.add("is-interstitial");const o=function(t){return-1==t.idx?t.members[0]:t.members[t.idx]}(e.playlist.queue);P(s,t.INTERSTITIAL_NEXT_ITEM,{next:o})}(e,i):e.togglePlay(!0)}function N(e,n){var i,s;const o=null===(i=e.playlist)||void 0===i?void 0:i.queue;if(!o)return;const l=o.idx,r=o.members[l];return r.src&&e.setSrc(r.src),e.emit(t.PLAYLIST_NEXT,{next_index:l}),null!==(s=n.should_play)&&void 0!==s&&s?e.togglePlay(!0):void 0}function C(e,n){return{queue:n,events:t,play:function(t){t<0||t>=n.members.length||(this.queue.idx=t,N(e,{should_play:!0}))},next:function(){this.queue.idx!==this.queue.last_idx&&this.play(this.queue.idx+1)},prev:function(){this.queue.idx&&this.play(this.queue.idx-1)},remove:function(n){const i=this.queue;return i.members[n]?i.idx===n?console.warn("operation failed: you cannot remove current playlist item"):(i.members.splice(n,1),i.last_idx=i.members.length-1,n<i.idx&&--i.idx,void e.emit(t.PLAYLIST_REMOVE,{index:n})):console.warn("there is no playlist item at this index")},push:function(...n){const i=e.root;if(0==this.queue.idx&&i.classList.contains("is-interstitial"))return console.warn("new items cannot be added when playlist has ended.");const s=this.queue.members;s.push(...n),this.queue.last_idx=s.length-1,e.emit(t.PLAYLIST_ADD,{members:n})},clear:function(){this.queue.members=[],this.queue.plays--,function(e,n){e.playlist&&(n=e.playlist.queue=T(n),e.emit(t.PLAYLIST_READY,{queue:n,should_play:!1}))}(e,this.queue)}}}function k(e){const n=y(e,"flowplayer-skip-previous-icon");h(n,"role","button"),S(n,"click",(function(){e.playlist&&e.playlist.prev()}));const i=y(e,"flowplayer-skip-next-icon");h(i,"role","button"),S(i,"click",(function(){e.playlist&&e.playlist.next()}));const s=E("fp-playlist-prev-preview"),o=E("fp-playlist-next-preview"),l=m(e,"flowplayer-control-buttons");return l&&(l.prepend(n),l.append(i),l.append(s),l.append(o)),e.on("reap",(function(){e.skip_controls=void 0})),e.on([t.PLAYLIST_NEXT,t.PLAYLIST_ADD,t.PLAYLIST_REMOVE],(function(t){const n=w(t,"data.queue",w(e,"playlist.queue"));if(!n||!l||!e.skip_controls)return;L(l,"is-prev-button-disabled",!n.idx),L(l,"is-next-button-disabled",n.idx===n.last_idx);const i=n.idx<n.last_idx?function(t){if(!A(t)||0!=(t.mode&g.LOOP))return t.members[function(t){const e=t.idx+1;return e>t.last_idx?0:e}(t)]}(n):null,r=n.idx>0?function(t){if(0!==t.idx||0!=(t.mode&g.LOOP))return t.members[function(t){const e=t.idx-1;return e<0?t.last_idx:e}(t)]}(n):null;o.style.backgroundImage=["url(",i?i.poster:null,")"].join(""),s.style.backgroundImage=["url(",r?r.poster:null,")"].join("")})),{prevButton:n,nextButton:i,prevPreview:s,nextPreview:o}}function F(t,e){if(!e)return;e.skip_controls&&(t.skip_controls=k(t));const n=function(t){let e=null;if(n=t.controls,!r(n)&&!c(n))return;var n;c(t.controls)?e=t.controls:r(t.controls)&&(e=document.querySelector(t.controls));return i("Could not find controls by Selector["+t.controls+"]",c(e)),e}(e);if(!n)return;const s=y(t,"flowplayer-playlist-controls");if(n.append(s),!(s instanceof FlowplayerPlaylistControls))return;v(n,"fp-playlist-controls "+(t.opt("playlist",{}).theme||"fp-dark"));const o=t.root.className.split(" ").filter((function(t){return t.match(/^use-play/)})).pop();o&&v(n,o)}function Y(t,e,n){if(Array.isArray(e))return n(function(t,e){let n=e.shuffle?g.SHUFFLE:g.FIFO;return e.loop&&(n|=g.LOOP),x(t,{mode:n,sort:e.sort})}(e,t));throw new Error("config.playlist must be an Array")}function D(e){var n;e.on(t.PLAYLIST_READY,(function(t){var n,i;const s=e.opt("playlist",{}),o=null===(n=t.detail)||void 0===n?void 0:n.queue,l=null===(i=t.detail)||void 0===i?void 0:i.should_play;o&&s&&(e.playlist=C(e,o),l&&O(e,o,s))})),e.on("ended",(n=n=>{if(n.prevented_from_ads)return;const i=e.opt("playlist");return e.playlist&&i?A(e.playlist.queue)?function(e,n){if(e.emit(t.PLAYLIST_ENDED),!n.loop)return;if(!e.playlist)return;const i=e.playlist.queue=T(e.playlist.queue);e.emit(t.PLAYLIST_LOOP),O(e,i,n)}(e,i):void(i.advance&&O(e,e.playlist.queue,i)):void 0},t=>{setTimeout((function(){if(!t.defaultPrevented)return n(t)}),0)})),e.on(["playing","waiting","seeking"],(function(){if(!e.root.classList.contains("is-interstitial"))return;const n=m(e,"flowplayer-playlist-interstitial");n&&P(n,t.INTERSTITIAL_CANCEL)}))}class Playlist{constructor(t){f(t,"flowplayer-playlist-controls",FlowplayerPlaylistControls),f(t,"flowplayer-playlist-interstitial",class extends UpNext{constructor(t){super(t),this.classList.add("fp-interstitial")}}),f(t,"flowplayer-skip-next-icon",class extends FlowplayerIcon{constructor(t){super(t,e)}}),f(t,"flowplayer-skip-previous-icon",class extends FlowplayerIcon{constructor(t){super(t,n)}})}init(e,n,i){const s=e.playlist||{};s.delay="number"==typeof s.delay?s.delay:0,i.setOpts(Object.assign(Object.assign({},e),{playlist:s})),F(i,e.playlist),function(e){var n;const i=y(e,"flowplayer-playlist-interstitial");i.addEventListener(t.INTERSTITIAL_CANCEL,()=>e.root.classList.remove("is-interstitial")),i.addEventListener(t.INTERSTITIAL_END,()=>{e.root.classList.remove("is-interstitial"),e.togglePlay(!0)}),null===(n=m(e,"flowplayer-ui"))||void 0===n||n.prepend(i)}(i),D(i)}onload(e,n,i,s){Y(e.playlist||{},s.items,(function(e){i.setState("is-playlist",!0),i.emit(t.PLAYLIST_READY,{queue:e,should_play:0===i.currentSrc.length})}))}wants(t,e,n){return"flowplayer/playlist"==e.type&&!!e.items&&p(Object.assign(Object.assign({},n),{playlist:e.items}))}}return Playlist.events=t,function(t,e){if("object"==typeof exports&&"undefined"!=typeof module)return e;"flowplayer"in t||(t.flowplayer={extensions:[]});const n=t.flowplayer;"function"==typeof n?n(e):(Array.isArray(n.extensions)||(n.extensions=[]),~n.extensions.indexOf(e)||n.extensions.push(e))}(window,Playlist),Playlist}));
|
|
1
|
+
!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.playlist=e())}(this,(function(){"use strict";var t={PLAYLIST_NEXT:"playlist:next",PLAYLIST_PREVIOUS:"playlist:previous",PLAYLIST_SELECTION:"playlist:selection",PLAYLIST_LOOP:"playlist:loop",PLAYLIST_ENDED:"playlist:ended",PLAYLIST_READY:"playlist:ready",PLAYLIST_ADD:"playlist:add",PLAYLIST_REMOVE:"playlist:remove",INTERSTITIAL_END:"interstitial/end",INTERSTITIAL_CANCEL:"interstitial/cancel",INTERSTITIAL_NEXT_ITEM:"interstitial/next_item"};const e={translation_key:"core.skip-next",name:"fp-skip-next"},n={translation_key:"core.skip-prev",name:"fp-skip-prev"};class Pipe{constructor(t){this.data=t}static of(t){return new Pipe(t)}static maybe(t,e,...n){return null==t?t:e.apply(t,[t,...n])}tap(t,...e){return t.apply(this,[this.data,...e]),new Pipe(this.data)}fmap(t,...e){const n=t.apply(this,[this.data,...e]);return new Pipe(n)}unwrap(){return this.data}}function i(t,e){if(!e)throw new Error(t)}function s(t){return"invalid playlist configuration\ndetails: "+t+"\n\tmust match Object of shape:\n"+["\t\t{ controls?: Selector|HTMLElement","player: Selector|HTMLElement","playlist: PlaylistId|Array(MediaId|PlayerConfig)","shuffle?: Boolean|false","loop?: Boolean|false","advance?: Boolean|true","delay?: Milliseconds|5000"].join("\n\t\t, ")+"\n\t\t}"}function o(t,e){Pipe.of(t).fmap(s).fmap(i,e)}function l(t){return void 0!==t}function r(t){return"string"==typeof t}function a(t){return"object"==typeof t}function c(t){return t instanceof HTMLElement}function u(t){var e;o("Config must be an Object",l(t)&&a(t)),o("property `playlist` is required",l(t.playlist)),o("property `playlist` was not a String(MediaId)",r(t.playlist)||(e=t.playlist,o("playlist property was not of type PlaylistId|Array(MediaId|PlayConfig)",Array.isArray(e)),o("playlist property cannot be an empty Array",e.length>0),!e.forEach((function(t,e){o("item at playlist["+e+"] was not valid",r(t)||a(t))})))),"loop shuffle".split(" ").forEach((function(e){l(t[e])&&o(e+" must be a boolean value if present","boolean"==typeof t[e])})),l(t.delay)&&o("property `delay` must be a Number (Milliseconds)","number"==typeof t.delay)}function p(t){try{u(t)}catch(t){return!1}return!0}class FlowplayerComponent extends HTMLElement{constructor(t){super(),this.player=t}}class FlowplayerIcon extends FlowplayerComponent{constructor(t,e){super(t),this.classList.add("fp-icon",e.name),e.title&&this.setAttribute("title",e.title),e.title&&this.setAttribute("aria-label",e.title),this.setAttribute("tabindex","0"),this.setAttribute("focusable","true")}}const d=["title","delay","description","poster","src"];class UpNext extends FlowplayerComponent{static get observedAttributes(){return d}constructor(e){super(e),this.classList.add("up-next"),this.addEventListener("animationend",()=>{this.dispatchEvent(new CustomEvent(t.INTERSTITIAL_END))}),this.addEventListener("animationcancel",()=>{this.classList.add("cancelled"),this.dispatchEvent(new CustomEvent(t.INTERSTITIAL_CANCEL))}),this.addEventListener(t.INTERSTITIAL_NEXT_ITEM,this._setUpNext.bind(this))}getTitle(){return this.getAttribute("title")||""}getDescription(){return this.getAttribute("description")||""}getPoster(){return this.getAttribute("poster")||""}getDelay(){return this.getAttribute("delay")||""}connectedCallback(){this.isConnected&&this._render()}attributeChangedCallback(){this._render()}_render(){var e,n;this.innerHTML="",this.classList.remove("cancelled");const i=document.createDocumentFragment(),s=document.createElement("div");s.classList.add("pane","left");const o=document.createElement("div");o.classList.add("pane","right"),i.append(s,o);const l=document.createElement("div");l.classList.add("poster"),l.style.backgroundImage="url("+this.getPoster()+")",s.append(l),l.addEventListener("click",()=>this.dispatchEvent(new CustomEvent(t.INTERSTITIAL_END)));const r=document.createElement("span");r.classList.add("fp-icon","fp-play"),l.append(r);const a=document.createElement("span");a.classList.add("title"),a.textContent=this.getTitle();const c=document.createElement("span");c.classList.add("description"),c.textContent=this.getDescription();const u=document.createElement("span");u.classList.add("countdown"),this.getDelay()&&(u.style.setProperty("--up-next-delay",this.getDelay()+"s"),u.classList.add("go"));const p=document.createElement("span");p.classList.add("cancel"),p.textContent=null!==(n=null===(e=this.player)||void 0===e?void 0:e.i18n("playlist.cancel"))&&void 0!==n?n:"cancel",p.addEventListener("click",()=>u.classList.remove("go")),o.append(a,c,p,u),this.append(i)}_setUpNext(t){var e,n,i;const s=t.detail.next,o=this.player.opt("playlist.delay",void 0)||10;this.setAttribute("title",null!==(e=s.title)&&void 0!==e?e:""),this.setAttribute("description",null!==(n=s.description)&&void 0!==n?n:""),this.setAttribute("poster",null!==(i=s.poster)&&void 0!==i?i:""),this.setAttribute("delay",o+"")}}const y=(t,e)=>new(((t,e)=>{const n=t.get(e);if(!n)throw new Error(`no flowplayer component with the name ${e} exists`);const i=window.customElements.get(e);if(!i)throw new Error(`no default flowplayer component with the name ${e} exists`);const s=window.customElements.get(n);return"function"!=typeof s?i:s})(t._customElements,e))(t),f=(t,e,n)=>{window.customElements.get(e)||window.customElements.define(e,n),t.customElements.get(e)||t.customElements.set(e,e)};function m(t,e){const n=t._customElements.get(e);return n&&t.root.querySelector(n)||void 0}function h(t,e,n){return t.setAttribute(e,n),t}function v(t,e){return t.classList.add(...e.split(" ")),t}function L(t,e,n){return e.split(" ").forEach(e=>t.classList.toggle(e,n)),t}function E(...t){const e=document.createElement("div");return 0==t.length||e.classList.add(...t),e}function w(t,e,n){const i=function(t){return Array.isArray(t)?t.slice(0):t.split(".")}(e);for(;i.length;){if(null==t)return n;const e=i.shift();if("string"!=typeof e)return n;t=t[e]}return null==t?n:t}function x(t,e){if(!e[t])return;const n=document.createElement("span");n.innerText=e[t];const i=E(t);return i.append(n),i}class FlowplayerPlaylistControls extends FlowplayerComponent{constructor(e){super(e),e.on(t.PLAYLIST_READY,t=>{const n=w(t,"data.queue",w(e,"playlist.queue"));n&&this.list(n,e)}),e.on(t.PLAYLIST_NEXT,()=>{var t;(null===(t=e.playlist)||void 0===t?void 0:t.queue)&&Array.from(this.querySelectorAll("li")).forEach((t,n)=>{var i;n===(null===(i=e.playlist)||void 0===i?void 0:i.queue.idx)?t.className="is-current":t.className="is-queued"})}),e.on(["playing","pause"],t=>{const e=this.querySelector(".is-current");e&&(e.classList.toggle("is-playing","playing"===t.type),e.classList.toggle("is-paused","flowplayer-pause-icon"===t.type))}),e.on(t.PLAYLIST_ADD,t=>{var n;const i=null===(n=e.playlist)||void 0===n?void 0:n.queue;if(!t.data||!i)return;t.data.members.forEach(t=>{const n=this.videoRow(t,e);n&&this.append(n)})}),e.on(t.PLAYLIST_REMOVE,t=>{if(!t.data)return;const e=Array.from(this.querySelectorAll("li"))[t.data.index];e&&this.removeChild(e)})}list(t,e){this.innerHTML="",v(this,"fp-playlist"),t.members.forEach(t=>{const n=this.videoRow(t,e);n&&this.append(n)})}videoRow(t,e){if(!t.title)return;const n=document.createElement("li");var i,s;return n.classList.add("is-queued"),n.onclick=this.videoRow_onclick.bind(this,n,t,e),i=n,s=[E("fp-color"),this.videoInfo(t),this.buttons(t,e)],i.append(...s),n}videoRow_onclick(t,e,n){var i;if(t.classList.contains("is-current"))return n.togglePlay(!n.playerState["is-playing"]);const s=Array.from(this.querySelectorAll("li")).indexOf(t);-1!==s&&(null===(i=n.playlist)||void 0===i||i.play(s))}videoInfo(t){const e=E("video-info"),n=x("title",t);n&&e.append(n);const i=x("description",t);return i&&e.append(i),e}buttons(t,e){const n=E("video-buttons"),i=y(e,"flowplayer-play-icon"),s=y(e,"flowplayer-pause-icon");return n.append(i,s),t.poster&&(n.style.backgroundImage=["url(",t.poster,")"].join("")),n}}var b;function g(t,e){var n,i;const s=e.sort||I,o=null!==(n=e.mode)&&void 0!==n?n:b.FIFO;return t=s(t.slice(0),o),{mode:o,sort:s,members:t,last_idx:t.length-1,plays:null!==(i=e.plays)&&void 0!==i?i:0,idx:-1}}function A(t){return t.idx==t.last_idx}function I(t,e){return(e&b.SHUFFLE)==b.SHUFFLE?t.sort((function(){return Math.random()-Math.random()})):t.slice(0)}function T(t){return g(t.members,{mode:t.mode,plays:t.plays+1,sort:t.sort})}!function(t){t[t.SHUFFLE=1]="SHUFFLE",t[t.FIFO=2]="FIFO",t[t.LOOP=4]="LOOP"}(b||(b={}));!function(){let t=!1;try{const e=Object.defineProperty({},"passive",{get:function(){t=!0}});window.addEventListener("testPassive",null,e),window.removeEventListener("testPassive",null,e)}catch(t){}}();const _=["touchstart","touchmove"];function P(t,e,n){const i=function(t,e){const n=new CustomEvent(t,{detail:e,cancelable:!0});return e&&Object.defineProperty(n,"data",{get:()=>e}),n}(e,n);return t.dispatchEvent(i),t}function S(t,e,n,i){Array.isArray(e)?e.forEach(e=>q(t,e,n,i)):q(t,e,n,i)}function q(t,e,n,i){if(s=e,!~_.indexOf(s))return t.addEventListener(e,n,i),t;var s;const o=Object.assign(i||{},{passive:!0});return t.addEventListener(e,n,o),t}function O(e,n,i){const s=n.idx+n.plays<0;return function(t,e,n){"object"==typeof e&&t.setOpts(Object.assign(Object.assign({},e),{playlist:n}));N(t,{should_play:n.should_play})}(e,function(t,e,n){return t.idx=e&&"number"==typeof n&&n>=0&&n<=t.last_idx?n:t.idx+1,t.members[t.idx]}(n,s,i.start_index),i),s&&i.autoplay?e.togglePlay(!0):s?e.setState("is-starting",!0):i.delay?void function(e,n){var i;const s=m(e,"flowplayer-playlist-interstitial");if(!s||!(null===(i=e.playlist)||void 0===i?void 0:i.queue)||!n.delay)return;e.root.classList.add("is-interstitial");const o=function(t){return-1==t.idx?t.members[0]:t.members[t.idx]}(e.playlist.queue);P(s,t.INTERSTITIAL_NEXT_ITEM,{next:o})}(e,i):e.togglePlay(!0)}function N(e,n){var i,s;const o=null===(i=e.playlist)||void 0===i?void 0:i.queue;if(!o)return;const l=o.idx,r=o.members[l];return r.src&&e.setSrc(r.src),e.emit(t.PLAYLIST_NEXT,{next_index:l}),null!==(s=n.should_play)&&void 0!==s&&s?e.togglePlay(!0):void 0}function C(e,n){return{queue:n,events:t,play:function(t){t<0||t>=n.members.length||(this.queue.idx=t,N(e,{should_play:!0}))},next:function(){this.queue.idx!==this.queue.last_idx&&this.play(this.queue.idx+1)},prev:function(){this.queue.idx&&this.play(this.queue.idx-1)},remove:function(n){const i=this.queue;return i.members[n]?i.idx===n?console.warn("operation failed: you cannot remove current playlist item"):(i.members.splice(n,1),i.last_idx=i.members.length-1,n<i.idx&&--i.idx,void e.emit(t.PLAYLIST_REMOVE,{index:n})):console.warn("there is no playlist item at this index")},push:function(...n){const i=e.root;if(0==this.queue.idx&&i.classList.contains("is-interstitial"))return console.warn("new items cannot be added when playlist has ended.");const s=this.queue.members;s.push(...n),this.queue.last_idx=s.length-1,e.emit(t.PLAYLIST_ADD,{members:n})},clear:function(){this.queue.members=[],this.queue.plays--,function(e,n){e.playlist&&(n=e.playlist.queue=T(n),e.emit(t.PLAYLIST_READY,{queue:n,should_play:!1}))}(e,this.queue)}}}function k(e){const n=y(e,"flowplayer-skip-previous-icon");h(n,"role","button"),S(n,"click",(function(){e.playlist&&e.playlist.prev()}));const i=y(e,"flowplayer-skip-next-icon");h(i,"role","button"),S(i,"click",(function(){e.playlist&&e.playlist.next()}));const s=E("fp-playlist-prev-preview"),o=E("fp-playlist-next-preview"),l=m(e,"flowplayer-control-buttons");return l&&(l.prepend(n),l.append(i),l.append(s),l.append(o)),e.on("reap",(function(){e.skip_controls=void 0})),e.on([t.PLAYLIST_NEXT,t.PLAYLIST_ADD,t.PLAYLIST_REMOVE],(function(t){const n=w(t,"data.queue",w(e,"playlist.queue"));if(!n||!l||!e.skip_controls)return;L(l,"is-prev-button-disabled",!n.idx),L(l,"is-next-button-disabled",n.idx===n.last_idx);const i=n.idx<n.last_idx?function(t){if(!A(t)||0!=(t.mode&b.LOOP))return t.members[function(t){const e=t.idx+1;return e>t.last_idx?0:e}(t)]}(n):null,r=n.idx>0?function(t){if(0!==t.idx||0!=(t.mode&b.LOOP))return t.members[function(t){const e=t.idx-1;return e<0?t.last_idx:e}(t)]}(n):null;o.style.backgroundImage=["url(",i?i.poster:null,")"].join(""),s.style.backgroundImage=["url(",r?r.poster:null,")"].join("")})),{prevButton:n,nextButton:i,prevPreview:s,nextPreview:o}}function F(t,e){if(!e)return;e.skip_controls&&(t.skip_controls=k(t));const n=function(t){let e=null;if(n=t.controls,!r(n)&&!c(n))return;var n;c(t.controls)?e=t.controls:r(t.controls)&&(e=document.querySelector(t.controls));return i("Could not find controls by Selector["+t.controls+"]",c(e)),e}(e);if(!n)return;const s=y(t,"flowplayer-playlist-controls");if(n.append(s),!(s instanceof FlowplayerPlaylistControls))return;v(n,"fp-playlist-controls "+(t.opt("playlist",{}).theme||"fp-dark"));const o=t.root.className.split(" ").filter((function(t){return t.match(/^use-play/)})).pop();o&&v(n,o)}function Y(t,e,n){if(Array.isArray(e))return n(function(t,e){let n=e.shuffle?b.SHUFFLE:b.FIFO;return e.loop&&(n|=b.LOOP),g(t,{mode:n,sort:e.sort})}(e,t));throw new Error("config.playlist must be an Array")}function D(e){var n;e.on(t.PLAYLIST_READY,(function(t){var n,i;const s=e.opt("playlist",{}),o=null===(n=t.detail)||void 0===n?void 0:n.queue,l=null===(i=t.detail)||void 0===i?void 0:i.should_play;o&&s&&(e.playlist=C(e,o),l&&O(e,o,s))})),e.on("ended",(n=n=>{if(n.prevented_from_ads)return;const i=e.opt("playlist");return e.playlist&&i?A(e.playlist.queue)?function(e,n){if(e.emit(t.PLAYLIST_ENDED),!n.loop)return;if(!e.playlist)return;const i=e.playlist.queue=T(e.playlist.queue);e.emit(t.PLAYLIST_LOOP),O(e,i,n)}(e,i):void(i.advance&&O(e,e.playlist.queue,i)):void 0},t=>{setTimeout((function(){if(!t.defaultPrevented)return n(t)}),0)})),e.on(["playing","waiting","seeking"],(function(){if(!e.root.classList.contains("is-interstitial"))return;const n=m(e,"flowplayer-playlist-interstitial");n&&P(n,t.INTERSTITIAL_CANCEL)}))}class Playlist{constructor(t){f(t,"flowplayer-playlist-controls",FlowplayerPlaylistControls),f(t,"flowplayer-playlist-interstitial",class extends UpNext{constructor(t){super(t),this.classList.add("fp-interstitial")}}),f(t,"flowplayer-skip-next-icon",class extends FlowplayerIcon{constructor(t){super(t,e)}}),f(t,"flowplayer-skip-previous-icon",class extends FlowplayerIcon{constructor(t){super(t,n)}})}init(e,n,i){const s=e.playlist||{};s.delay="number"==typeof s.delay?s.delay:0,i.setOpts(Object.assign(Object.assign({},e),{playlist:s})),F(i,e.playlist),function(e){var n;const i=y(e,"flowplayer-playlist-interstitial");i.addEventListener(t.INTERSTITIAL_CANCEL,()=>e.root.classList.remove("is-interstitial")),i.addEventListener(t.INTERSTITIAL_END,()=>{e.root.classList.remove("is-interstitial"),e.togglePlay(!0)}),null===(n=m(e,"flowplayer-ui"))||void 0===n||n.prepend(i)}(i),D(i)}onload(e,n,i,s){Y(e.playlist||{},s.items,(function(e){i.setState("is-playlist",!0),i.emit(t.PLAYLIST_READY,{queue:e,should_play:0===i.currentSrc.length})}))}wants(t,e,n){return"flowplayer/playlist"==e.type&&!!e.items&&p(Object.assign(Object.assign({},n),{playlist:e.items}))}}return Playlist.events=t,function(t,e){if("object"==typeof exports&&"undefined"!=typeof module)return e;"flowplayer"in t||(t.flowplayer={extensions:[]});const n=t.flowplayer;"function"==typeof n?n(e):(Array.isArray(n.extensions)||(n.extensions=[]),~n.extensions.indexOf(e)||n.extensions.push(e))}(window,Playlist),Playlist}));
|
package/plugins/preview.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):((e="undefined"!=typeof globalThis?globalThis:e||self).flowplayer=e.flowplayer||{},e.flowplayer.preview=i())}(this,(function(){"use strict";var e=Object.freeze({__proto__:null,MOUSEOVER:1,MOBILE_VIEWPORT_VISIBLE:2,VIEWPORT_VISIBLE:4});class PreviewPlugin{init(e,i,t){t.on("config",({
|
|
1
|
+
!function(e,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):((e="undefined"!=typeof globalThis?globalThis:e||self).flowplayer=e.flowplayer||{},e.flowplayer.preview=i())}(this,(function(){"use strict";var e=Object.freeze({__proto__:null,MOUSEOVER:1,MOBILE_VIEWPORT_VISIBLE:2,VIEWPORT_VISIBLE:4});class PreviewPlugin{init(e,i,t){t.on("config",({detail:e})=>{e&&JSON.stringify(this.preview_config)!==JSON.stringify(e.preview)&&this.configure(e)}),this.root=i,this.player=t,this.configure(e)}configure(e){var i,t;if(null===(i=this.preview)||void 0===i||i.remove(),!e.preview||!e.poster)return;this.preview_config=Object.assign({},e.preview),this.createPreview(e.preview.src);const n=e.preview.trigger||3;(4&n||function(){const e="undefined"!=typeof document&&"undefined"!=typeof window,i=e?navigator.userAgent:"",t=/iP(hone|od)/i.test(i)&&!/iPad/.test(i)&&!/IEMobile/i.test(i),n=/Android/.test(i)&&!/Firefox/.test(i),r=/^((?!chrome|android).)*safari/i.test(i),o=/SamsungBrowser/.test(i),s=o&&/SMART-TV/.test(i);return{controls:!t,video:function(i){return e&&document.createElement("video").canPlayType(i)},lang:e&&window.navigator.language,android:n,iphone:t,safari:r,ios:e&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,samsung:o,samsung_tv:o&&s,touch:!!("ontouchstart"in window)}}().touch&&2&n)&&(null===(t=this.preview)||void 0===t||t.classList.add("in-viewport"))}createPreview(e){var i;if(!this.root||0===(null==e?void 0:e.length))return;if(this.preview=document.createElement("img"),this.preview.classList.add("fp-preview"),this.player&&(null===(i=function(e,i){const t=e._customElements.get(i);return t&&e.root.querySelector(t)||void 0}(this.player,"flowplayer-ui"))||void 0===i||i.prepend(this.preview)),!Array.isArray(e))return this.preview.setAttribute("src",e);const t=this.root.clientWidth;this.preview.src=e.reduce((e,i)=>i.dimensions&&e.dimensions&&Math.abs(i.dimensions.width-t)<Math.abs(e.dimensions.width-t)?i:e).src}}return PreviewPlugin.trigger=e,function(e,i){if("object"==typeof exports&&"undefined"!=typeof module)return i;"flowplayer"in e||(e.flowplayer={extensions:[]});const t=e.flowplayer;return"function"==typeof t?(t(i),i):(Array.isArray(t.extensions)||(t.extensions=[]),~t.extensions.indexOf(i)||t.extensions.push(i),i)}(window,PreviewPlugin)}));
|
package/util/loader.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ import { PluginCtor } from "../types/plugin";
|
|
|
3
3
|
* adds support for asynchronous plugin loading`
|
|
4
4
|
* issue/127
|
|
5
5
|
*/
|
|
6
|
-
export declare function define(root: any, plugin: PluginCtor):
|
|
6
|
+
export declare function define(root: any, plugin: PluginCtor): PluginCtor;
|
|
7
7
|
export declare function root(): {};
|
|
8
8
|
export declare function modules(): any;
|