@flowplayer/player 3.0.2 → 3.0.3-rc.0
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/events.d.ts +1 -1
- package/core/events.js +2 -2
- package/core.js +2 -2
- package/default.js +2 -2
- package/embed.js +18 -18
- package/package.json +1 -1
- package/plugins/cuepoints.js +1 -1
- package/plugins/dash.js +1 -1
- package/plugins/health.js +16 -1
- package/plugins/hls.js +1 -1
- package/plugins/ovp.js +1 -1
- package/plugins/preview.js +1 -1
package/plugins/health.js
CHANGED
|
@@ -1 +1,16 @@
|
|
|
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",
|
|
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",f="ended",h="seeked",p="seeking";function m(e){try{return!!new URL(e)}catch(e){return!1}}
|
|
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
|
+
***************************************************************************** */
|
|
16
|
+
function v(e,t,n,i){return new(n||(n=Promise))((function(o,s){function r(e){try{d(i.next(e))}catch(e){s(e)}}function a(e){try{d(i.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}d((i=i.apply(e,t||[])).next())}))}const E=navigator;function y(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 g(e,t){return function(e,t){return"function"==typeof navigator.sendBeacon&&navigator.sendBeacon(e,t)}(e,JSON.stringify({events:t}))}const R=[1e7]+""+-1e3+-4e3+-8e3+-1e11,O=()=>"undefined"==typeof crypto?"":R.replace(/[018]/g,e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16)),D="https://ljsp.lwcdn.com".concat("/web/public/countdown/time.json"),w=window,N=w._flowplayerTimekeeper||(w._flowplayerTimekeeper={});var T;!function(e){e[e.OFF=0]="OFF",e[e.ON=1]="ON",e[e.AUDIO_REQUIRED=2]="AUDIO_REQUIRED"}(T||(T={}));const A=e=>{switch(e){case!0:return T.ON;case!1:return T.OFF;default:return e}},I=O(),b=[];function S(e){const t=b.slice(0);b.length=0,0!=t.length&&(e.logger.log(`:dispatch events={${t.length}}`),g("https://health.flowplayer.com/v1/health/events",t))}function U(e,t,n){return v(this,void 0,void 0,(function*(){const i=yield C();b.push(Object.assign(t,i)),e.logger.log(":enqueue",t.event,t),b.length<10&&!n||S(e)}))}const k=()=>{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}},C=()=>v(void 0,void 0,void 0,(function*(){try{const e=yield function(){return v(this,void 0,void 0,(function*(){const e=N.cachedServerOffset;if(e)return e;const t=N.pendingRequest||(N.pendingRequest=fetch(D)),n=yield t,i=parseInt(n.headers.get("age")||"0"),o=yield n.json(),s=Date.now()-o.millisUtc-1e3*i;return N.cachedServerOffset=s,N.cachedServerOffset}))}();return{timestamp:Date.now()-e,adjustedTimestamp:!0}}catch(e){return{timestamp:Date.now(),adjustedTimestamp:!1}}})),x=(e,t)=>Object.assign(e,{detail:t}),M=(e,{event:t,media_session_id:n})=>({event:t,media_session_id:n,device_id:e.deviceId(),session_id:I,version:"3.0.3-rc.0",commit:"2c2f1dc6b25c66190cde2fd1fb53e24144756668",ima_sdk_version:k(),preload:e.opt("preload"),autoplay:A(e.opt("autoplay")),live:e.opt("live"),source:e.original_src,downlink_mbs:y(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")}),B=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 j(e,t,n,i){const o=M(t,{event:n,media_session_id:e.media_session_id}),{before:s,after:r}=i;U(e,((e,t,n)=>Object.assign(e,{state:{before:t,after:n}}))(o,B(s),B(r)))}var F;function L(e){switch(e){case F.MEDIA_PLAYBACK_ABORTED:return"media playback was aborted";case F.MEDIA_ERR_NETWORK:return"a network error occurred";case F.MEDIA_ERR_DECODE:return"unable to decode media content";case F.MEDIA_ERR_SRC_NOT_SUPPORTED:return"unsupported media type";case F.NO_INTERNET:return"no internet connection detected";case F.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"}(F||(F={}));const H=(e,t)=>{let n=null;return(...i)=>{null!==n&&(clearTimeout(n),n=null),n=setTimeout(()=>t(...i),e)}};class Health{constructor(e,t){this.logger=function(e,t){return{log:(...n)=>{const i=e.opt("debug");i&&t.match(i)&&console.log(t,...n)}}}(t,"health"),this.media_session_id=O();const n=setInterval(()=>S(this),1e3);if(t.on("reap",()=>clearInterval(n)),!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)}}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=M(E,{event:e.event,media_session_id:this.media_session_id});Object.assign(t,e.detail||{}),U(this,t)}),[_,d,n,s,r,a,u,e].forEach(e=>{E.on(e,e=>{U(this,M(E,{event:e.type,media_session_id:this.media_session_id}))})}),[l,c,p,h,f,i,o].forEach(e=>{E.on(e,e=>{U(this,M(E,{event:e.type,media_session_id:this.media_session_id}))})}),E.on("volumechange",H(800,e=>{const t=M(E,{event:e.type,media_session_id:this.media_session_id});U(this,x(t,{volume:parseFloat(E.volume.toFixed(2)),muted:E.muted}))})),E.on("resize",H(800,e=>{const t=M(E,{event:e.type,media_session_id:this.media_session_id});U(this,x(t,{height:v.clientHeight,width:v.clientWidth}))})),E.on("qualitychange",({type:e,detail:t})=>{switch(t.kind){case"hls":return j(this,E,e,t)}});let y=Date.now()+1e3;E.on("timeupdate",e=>{if(Date.now()<y)return;y=Date.now()+1e3;const t=M(E,{event:e.type,media_session_id:this.media_session_id});var n;U(this,x(t,{duration:(n=E.duration,Number.isFinite(n)?n:n===1/0?-1:void 0)}))}),E.addEventListener("error",e=>{const t=M(E,{event:e.type,media_session_id:this.media_session_id}),n=e.error||E.error;if(!n)return U(this,t,!0);const i=n.code,o={error_message:n.message||L(i),error_code:i,error_stack:n.stack||""};return U(this,x(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=O();U(this,M(E,{event:e.type,media_session_id:this.media_session_id})),S(this)}),E.on("visibilitychange",e=>{U(this,M(E,{event:e.type,media_session_id:this.media_session_id})),S(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/hls.js
CHANGED
|
@@ -354,4 +354,4 @@
|
|
|
354
354
|
/*!*********************************!*\
|
|
355
355
|
!*** ./src/utils/xhr-loader.ts ***!
|
|
356
356
|
\*********************************/
|
|
357
|
-
/*! exports provided: default */function(t,e,r){r.r(e);var i=r(/*! ../utils/logger */"./src/utils/logger.ts"),n=r(/*! ../loader/load-stats */"./src/loader/load-stats.ts"),s=/^age:\s*[\d.]+\s*$/m,a=function(){function t(t){this.xhrSetup=void 0,this.requestTimeout=void 0,this.retryTimeout=void 0,this.retryDelay=void 0,this.config=null,this.callbacks=null,this.context=void 0,this.loader=null,this.stats=void 0,this.xhrSetup=t?t.xhrSetup:null,this.stats=new n.LoadStats,this.retryDelay=0}var e=t.prototype;return e.destroy=function(){this.callbacks=null,this.abortInternal(),this.loader=null,this.config=null},e.abortInternal=function(){var t=this.loader;self.clearTimeout(this.requestTimeout),self.clearTimeout(this.retryTimeout),t&&(t.onreadystatechange=null,t.onprogress=null,4!==t.readyState&&(this.stats.aborted=!0,t.abort()))},e.abort=function(){var t;this.abortInternal(),null!==(t=this.callbacks)&&void 0!==t&&t.onAbort&&this.callbacks.onAbort(this.stats,this.context,this.loader)},e.load=function(t,e,r){if(this.stats.loading.start)throw new Error("Loader can only be used once.");this.stats.loading.start=self.performance.now(),this.context=t,this.config=e,this.callbacks=r,this.retryDelay=e.retryDelay,this.loadInternal()},e.loadInternal=function(){var t=this.config,e=this.context;if(t){var r=this.loader=new self.XMLHttpRequest,i=this.stats;i.loading.first=0,i.loaded=0;var n=this.xhrSetup;try{if(n)try{n(r,e.url)}catch(t){r.open("GET",e.url,!0),n(r,e.url)}r.readyState||r.open("GET",e.url,!0)}catch(t){return void this.callbacks.onError({code:r.status,text:t.message},e,r)}e.rangeEnd&&r.setRequestHeader("Range","bytes="+e.rangeStart+"-"+(e.rangeEnd-1)),r.onreadystatechange=this.readystatechange.bind(this),r.onprogress=this.loadprogress.bind(this),r.responseType=e.responseType,self.clearTimeout(this.requestTimeout),this.requestTimeout=self.setTimeout(this.loadtimeout.bind(this),t.timeout),r.send()}},e.readystatechange=function(){var t=this.context,e=this.loader,r=this.stats;if(t&&e){var n=e.readyState,s=this.config;if(!r.aborted&&n>=2)if(self.clearTimeout(this.requestTimeout),0===r.loading.first&&(r.loading.first=Math.max(self.performance.now(),r.loading.start)),4===n){e.onreadystatechange=null,e.onprogress=null;var a=e.status;if(a>=200&&a<300){var o,l;if(r.loading.end=Math.max(self.performance.now(),r.loading.first),l="arraybuffer"===t.responseType?(o=e.response).byteLength:(o=e.responseText).length,r.loaded=r.total=l,!this.callbacks)return;var u=this.callbacks.onProgress;if(u&&u(r,t,o,e),!this.callbacks)return;var d={url:e.responseURL,data:o};this.callbacks.onSuccess(d,r,t,e)}else r.retry>=s.maxRetry||a>=400&&a<499?(i.logger.error(a+" while loading "+t.url),this.callbacks.onError({code:a,text:e.statusText},t,e)):(i.logger.warn(a+" while loading "+t.url+", retrying in "+this.retryDelay+"..."),this.abortInternal(),this.loader=null,self.clearTimeout(this.retryTimeout),this.retryTimeout=self.setTimeout(this.loadInternal.bind(this),this.retryDelay),this.retryDelay=Math.min(2*this.retryDelay,s.maxRetryDelay),r.retry++)}else self.clearTimeout(this.requestTimeout),this.requestTimeout=self.setTimeout(this.loadtimeout.bind(this),s.timeout)}},e.loadtimeout=function(){i.logger.warn("timeout while loading "+this.context.url);var t=this.callbacks;t&&(this.abortInternal(),t.onTimeout(this.stats,this.context,this.loader))},e.loadprogress=function(t){var e=this.stats;e.loaded=t.loaded,t.lengthComputable&&(e.total=t.total)},e.getCacheAge=function(){var t=null;if(this.loader&&s.test(this.loader.getAllResponseHeaders())){var e=this.loader.getResponseHeader("age");t=e?parseFloat(e):null}return t},t}();e.default=a}}).default},t.exports=r())})));var r=Object.freeze({__proto__:null,ATTACHED:"hls:attached"});const i="com.widevine.alpha";const n="application/vnd.apple.mpegURL",s=[n,"application/x-mpegurl"],a=document.createElement("video").canPlayType(n);function o(t){const{pathname:e}=function(t){const e=document.createElement("a");return e.href=t,e}(t);return e.endsWith(".m3u8")}function l({src:t="",type:e="",drm:r},n){const l=(null==n?void 0:n.hls)||{},u="native"in l&&l.native;return(!a||!u)&&(!(r&&!Object.keys(r).find(t=>{return e=t,[i].filter((function(t){return t===e})).length;var e}))&&(!(!e||!s.includes(e))||o(t)))}var u="audio:set",d="audio:update",c="audio:tracks";const h=[e.Events.SUBTITLE_TRACKS_UPDATED,e.Events.SUBTITLE_TRACK_SWITCH,e.Events.LEVEL_SWITCHED];function f(t,e){h.forEach((function(r){t.on(r,(function(){!function(t,e){var r;const i=t.levels[t.currentLevel];if(!i||!t.subtitleTracks.length||i.attrs.SUB)return;const n=null===(r=null==i?void 0:i.attrs)||void 0===r?void 0:r.SUBTITLES;if(!n)return e.emit("tracks:text:all",[]);const s=t.subtitleTracks.filter((function(t){return t.groupId==n})).map((function(t){return e.textTracks[t.id]}));e.emit("tracks:text:all",s)}(t,e)}))}))}var g=Object.assign(Object.assign({},{404:"the video was not found",403:"access to this video was denied",410:"the video no longer exists",0:"no internet connection detected"}),{keySystemNoKeys:"no keys",keySystemNoAccess:"no access to key system",keySystemNoSession:"no session for key system",keySystemLicenseRequestFailed:"license request failed",keyLoadError:"decrypt key load failed",keyLoadTimeOut:"decrypt key load timed outs"});var v;function p(t,r,i){if(!t.reaper||!i.src)return;t.hls&&(t.emit("recover",{type:"hls"}),t.hls.destroy());const n="live"in r==0;if(i.drm&&"https:"!==location.protocol&&"localhost"!==location.hostname&&"127.0.0.1"!==location.hostname)return t.emit("error",{message:"Secure page required for DRM"});const s=t.hls=new e(function(t){return Object.assign(Object.assign({autoStartLoad:!1},t.hls),{startPosition:t.start_time||-1})}(r));s.subtitleDisplay=!1,s.attachMedia(t),s.loadSource(i.src),t.emit("hls:attached",{hls:s}),function(t,r){t.on(e.Events.AUDIO_TRACKS_UPDATED,(function(t,e){r.emit(c,e.audioTracks)})),t.on(e.Events.AUDIO_TRACK_SWITCHING,(function(t,e){r.emit(d,e)})),t.on(e.Events.MANIFEST_PARSED,(function(t,e){e.audioTracks&&r.emit(c,e.audioTracks)})),t.on(e.Events.LEVEL_SWITCHED,(function(e,i){const n=t.levels[i.level];n&&r.emit(c,t.audioTracks.filter((function(t){return t.groupId&&~(n.audioGroupIds||[]).indexOf(t.groupId)})))}))}(s,t),f(s,t);const a=function(t){var e;const r=null===(e=t.data)||void 0===e?void 0:e.level;"number"==typeof r&&(s.levels[r]||-1===r?s.nextLevel=r:console.error(new Error("skipping invalid quality: "+t.data)))},o=function(t){var e;const r=null===(e=t.data)||void 0===e?void 0:e.id;"number"==typeof r&&r!=s.audioTrack&&setTimeout((function(){s.audioTrack=r}),0)};t.on("quality:set",a),t.on(u,o),t.on("src",(function(){t.hls&&t.hls.destroy(),t.off("quality:set",a),t.off(u,o)})),t.on("audioonlysource",(function(){})),t.on("reap",(function(){s&&s.destroy()})),t.on("remotesession:started",()=>{t.hls&&t.hls.stopLoad()}),t.on("remotesession:ended",()=>{t.hls&&t
|
|
357
|
+
/*! exports provided: default */function(t,e,r){r.r(e);var i=r(/*! ../utils/logger */"./src/utils/logger.ts"),n=r(/*! ../loader/load-stats */"./src/loader/load-stats.ts"),s=/^age:\s*[\d.]+\s*$/m,a=function(){function t(t){this.xhrSetup=void 0,this.requestTimeout=void 0,this.retryTimeout=void 0,this.retryDelay=void 0,this.config=null,this.callbacks=null,this.context=void 0,this.loader=null,this.stats=void 0,this.xhrSetup=t?t.xhrSetup:null,this.stats=new n.LoadStats,this.retryDelay=0}var e=t.prototype;return e.destroy=function(){this.callbacks=null,this.abortInternal(),this.loader=null,this.config=null},e.abortInternal=function(){var t=this.loader;self.clearTimeout(this.requestTimeout),self.clearTimeout(this.retryTimeout),t&&(t.onreadystatechange=null,t.onprogress=null,4!==t.readyState&&(this.stats.aborted=!0,t.abort()))},e.abort=function(){var t;this.abortInternal(),null!==(t=this.callbacks)&&void 0!==t&&t.onAbort&&this.callbacks.onAbort(this.stats,this.context,this.loader)},e.load=function(t,e,r){if(this.stats.loading.start)throw new Error("Loader can only be used once.");this.stats.loading.start=self.performance.now(),this.context=t,this.config=e,this.callbacks=r,this.retryDelay=e.retryDelay,this.loadInternal()},e.loadInternal=function(){var t=this.config,e=this.context;if(t){var r=this.loader=new self.XMLHttpRequest,i=this.stats;i.loading.first=0,i.loaded=0;var n=this.xhrSetup;try{if(n)try{n(r,e.url)}catch(t){r.open("GET",e.url,!0),n(r,e.url)}r.readyState||r.open("GET",e.url,!0)}catch(t){return void this.callbacks.onError({code:r.status,text:t.message},e,r)}e.rangeEnd&&r.setRequestHeader("Range","bytes="+e.rangeStart+"-"+(e.rangeEnd-1)),r.onreadystatechange=this.readystatechange.bind(this),r.onprogress=this.loadprogress.bind(this),r.responseType=e.responseType,self.clearTimeout(this.requestTimeout),this.requestTimeout=self.setTimeout(this.loadtimeout.bind(this),t.timeout),r.send()}},e.readystatechange=function(){var t=this.context,e=this.loader,r=this.stats;if(t&&e){var n=e.readyState,s=this.config;if(!r.aborted&&n>=2)if(self.clearTimeout(this.requestTimeout),0===r.loading.first&&(r.loading.first=Math.max(self.performance.now(),r.loading.start)),4===n){e.onreadystatechange=null,e.onprogress=null;var a=e.status;if(a>=200&&a<300){var o,l;if(r.loading.end=Math.max(self.performance.now(),r.loading.first),l="arraybuffer"===t.responseType?(o=e.response).byteLength:(o=e.responseText).length,r.loaded=r.total=l,!this.callbacks)return;var u=this.callbacks.onProgress;if(u&&u(r,t,o,e),!this.callbacks)return;var d={url:e.responseURL,data:o};this.callbacks.onSuccess(d,r,t,e)}else r.retry>=s.maxRetry||a>=400&&a<499?(i.logger.error(a+" while loading "+t.url),this.callbacks.onError({code:a,text:e.statusText},t,e)):(i.logger.warn(a+" while loading "+t.url+", retrying in "+this.retryDelay+"..."),this.abortInternal(),this.loader=null,self.clearTimeout(this.retryTimeout),this.retryTimeout=self.setTimeout(this.loadInternal.bind(this),this.retryDelay),this.retryDelay=Math.min(2*this.retryDelay,s.maxRetryDelay),r.retry++)}else self.clearTimeout(this.requestTimeout),this.requestTimeout=self.setTimeout(this.loadtimeout.bind(this),s.timeout)}},e.loadtimeout=function(){i.logger.warn("timeout while loading "+this.context.url);var t=this.callbacks;t&&(this.abortInternal(),t.onTimeout(this.stats,this.context,this.loader))},e.loadprogress=function(t){var e=this.stats;e.loaded=t.loaded,t.lengthComputable&&(e.total=t.total)},e.getCacheAge=function(){var t=null;if(this.loader&&s.test(this.loader.getAllResponseHeaders())){var e=this.loader.getResponseHeader("age");t=e?parseFloat(e):null}return t},t}();e.default=a}}).default},t.exports=r())})));var r=Object.freeze({__proto__:null,ATTACHED:"hls:attached"});const i="com.widevine.alpha";const n="application/vnd.apple.mpegURL",s=[n,"application/x-mpegurl"],a=document.createElement("video").canPlayType(n);function o(t){const{pathname:e}=function(t){const e=document.createElement("a");return e.href=t,e}(t);return e.endsWith(".m3u8")}function l({src:t="",type:e="",drm:r},n){const l=(null==n?void 0:n.hls)||{},u="native"in l&&l.native;return(!a||!u)&&(!(r&&!Object.keys(r).find(t=>{return e=t,[i].filter((function(t){return t===e})).length;var e}))&&(!(!e||!s.includes(e))||o(t)))}var u="audio:set",d="audio:update",c="audio:tracks";const h=[e.Events.SUBTITLE_TRACKS_UPDATED,e.Events.SUBTITLE_TRACK_SWITCH,e.Events.LEVEL_SWITCHED];function f(t,e){h.forEach((function(r){t.on(r,(function(){!function(t,e){var r;const i=t.levels[t.currentLevel];if(!i||!t.subtitleTracks.length||i.attrs.SUB)return;const n=null===(r=null==i?void 0:i.attrs)||void 0===r?void 0:r.SUBTITLES;if(!n)return e.emit("tracks:text:all",[]);const s=t.subtitleTracks.filter((function(t){return t.groupId==n})).map((function(t){return e.textTracks[t.id]}));e.emit("tracks:text:all",s)}(t,e)}))}))}var g=Object.assign(Object.assign({},{404:"the video was not found",403:"access to this video was denied",410:"the video no longer exists",0:"no internet connection detected"}),{keySystemNoKeys:"no keys",keySystemNoAccess:"no access to key system",keySystemNoSession:"no session for key system",keySystemLicenseRequestFailed:"license request failed",keyLoadError:"decrypt key load failed",keyLoadTimeOut:"decrypt key load timed outs"});var v;function p(t,r,i){if(!t.reaper||!i.src)return;t.hls&&(t.emit("recover",{type:"hls"}),t.hls.destroy());const n="live"in r==0;if(i.drm&&"https:"!==location.protocol&&"localhost"!==location.hostname&&"127.0.0.1"!==location.hostname)return t.emit("error",{message:"Secure page required for DRM"});const s=t.hls=new e(function(t){return Object.assign(Object.assign({autoStartLoad:!1},t.hls),{startPosition:t.start_time||-1})}(r));s.subtitleDisplay=!1,s.attachMedia(t),s.loadSource(i.src),t.emit("hls:attached",{hls:s}),function(t,r){t.on(e.Events.AUDIO_TRACKS_UPDATED,(function(t,e){r.emit(c,e.audioTracks)})),t.on(e.Events.AUDIO_TRACK_SWITCHING,(function(t,e){r.emit(d,e)})),t.on(e.Events.MANIFEST_PARSED,(function(t,e){e.audioTracks&&r.emit(c,e.audioTracks)})),t.on(e.Events.LEVEL_SWITCHED,(function(e,i){const n=t.levels[i.level];n&&r.emit(c,t.audioTracks.filter((function(t){return t.groupId&&~(n.audioGroupIds||[]).indexOf(t.groupId)})))}))}(s,t),f(s,t);const a=function(t){var e;const r=null===(e=t.data)||void 0===e?void 0:e.level;"number"==typeof r&&(s.levels[r]||-1===r?s.nextLevel=r:console.error(new Error("skipping invalid quality: "+t.data)))},o=function(t){var e;const r=null===(e=t.data)||void 0===e?void 0:e.id;"number"==typeof r&&r!=s.audioTrack&&setTimeout((function(){s.audioTrack=r}),0)};t.on("quality:set",a),t.on(u,o),t.on("src",(function(){t.hls&&t.hls.destroy(),t.off("quality:set",a),t.off(u,o)})),t.on("audioonlysource",(function(){})),t.on("reap",(function(){s&&s.destroy()})),t.on("remotesession:started",()=>{t.hls&&t.hls.stopLoad()}),t.on("remotesession:ended",()=>{t.hls&&m(t)}),n&&s.on(e.Events.LEVEL_LOADED,(function(e,r){t.setOpts({live:r.details.live})})),s.on(e.Events.MANIFEST_PARSED,(function(e,i){const n=i.levels.slice(0).reduce((t,e,r)=>[...t,{level:r,text:e.name||e.width+"",width:e.width,height:e.height,videoCodec:e.videoCodec||""}],[{text:"AUTO",level:-1,width:0,height:0,videoCodec:""}]).sort((t,e)=>e.width-t.width);t.emit("qualities",n),function(t,e,r){if(!t.hls)return;void 0!==e.start_quality&&(v.HIGH&e.start_quality&&(t.hls.startLevel=r[0].level),v.LOW&e.start_quality&&(t.hls.startLevel=r[r.length-1].level),v.MEDIUM&e.start_quality&&(t.hls.startLevel=r[Math.ceil(r.length/2)-1].level));if("none"===e.preload&&!e.autoplay)return;m(t,e.start_time||-1)}(t,r,n.slice(0,-1));const s=n.find(t=>!!t.videoCodec);s||t.emit("audioonlysource"),!t.opt("ratio")&&s&&0!=s.width&&0!=s.height&&t.setOpts({ratio:s.width+":"+s.height})})),s.on(e.Events.INIT_PTS_FOUND,(function(t,e){e.frag.duration})),s.on(e.Events.ERROR,(function(r,i){!function(t,r,i,n){if(0==t.reaper)return;if(0==r.fatal)return;switch(r.type){case e.ErrorTypes.MEDIA_ERROR:return function(t,e){var r;t.emit("error",{fatal:!0,message:"Unrecoverable error occurred while playing media"}),null===(r=t.hls)||void 0===r||r.destroy()}(t);case e.ErrorTypes.NETWORK_ERROR:return function(t,e){var r;const i=null===(r=e.networkDetails)||void 0===r?void 0:r.status;t.emit("error",{fatal:!0,code:"http:"+i.toString(),message:g[i]||"an error occurred while loading this video"})}(t,r);case e.ErrorTypes.KEY_SYSTEM_ERROR:(function(t,e){var r;t.emit("error",{fatal:!0,message:g[e.details]||"an error occurred while accessing this video"}),null===(r=t.hls)||void 0===r||r.destroy()})(t,r)}}(t,i,t.original_src,s.config)})),s.on(e.Events.LEVEL_SWITCHING,(e,r)=>{const i=s.levels[s.currentLevel],n=s.levels[r.level];t.emit("qualitychange",{before:i,after:n,kind:"hls"})});const l=t.opt("start_time");l&&t.once("loadedmetadata",(function(){t.currentTime=l})),"none"===r.preload&&t.once("beforeplay",()=>{m(t,r.start_time||-1)})}function m(t,e){var r;t.setState("is-loading",!0),null===(r=t.hls)||void 0===r||r.startLoad(e)}!function(t){t[t.LOW=1]="LOW",t[t.MEDIUM=2]="MEDIUM",t[t.HIGH=4]="HIGH"}(v||(v={}));class HLS{init(){}onload(t,e,r,i){p(r,t,i)}wants(t,r,i){return e.isSupported()&&l(r,i)}}return HLS.events=r,HLS.version=e.version,function(t,e){if("object"==typeof exports&&"undefined"!=typeof module)return e;"flowplayer"in t||(t.flowplayer={extensions:[]});const r=t.flowplayer;"function"==typeof r?r(e):(Array.isArray(r.extensions)||(r.extensions=[]),~r.extensions.indexOf(e)||r.extensions.push(e))}(window,HLS),HLS}));
|
package/plugins/ovp.js
CHANGED
|
@@ -12,4 +12,4 @@
|
|
|
12
12
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
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}}function n(t){return fetch(t).then(t=>t.json())}function o(){let t=[].join.call(arguments,"/");return"/"!==t[0]&&(t="/"+t),i()+"/web/public/native/config"+t}const i=()=>"https://ljsp.lwcdn.com";function r(t){return~t.indexOf("/")?t:"/media/"+t}var s={404:"media not found",402:"invalid subscription",400:"bad request",415:"unsupported media type"};function a(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 l(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},s={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)||{})}},a=n.embed||{};return delete a.src,e(s,r,t,(delete(l=n).src,delete l.metadata,delete l.title,delete l.description,delete l.duration,delete l.poster,l),a);var l}const c=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/;function d(t){return"object"==typeof t&&"ovp/base64"==t.type}function u(t,e){return function(t,e){return!(~t.indexOf(".")||!c.test(t))&&(e.type="video/ovp",!0)}(t,e)||d(e)}function p(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 m(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 f(t){return t.live}var v=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 y(t,e){const n=null==e?void 0:e.src;if(d(e))return function(t,e){const n=p(e.src||"");if(function(t){return"string"==typeof t.err}(n))return console.error(n.err);h(t,n)}(t,e);n&&Pipe.of(n).fmap(r).fmap(o).fmap(t=>fetch(t)).fmap(e=>e.then(t=>Promise.all([t.status,t.json()])).then(([e,n])=>200==e?h(t,n):w(t,n)))}function h(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"),w(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),s=((null==r?void 0:r.playlist)||[]).map(t=>l(t,o));return Object.assign(r,{playlist:s})}(t.opts,n))}(t,n):f(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(m).unwrap());t.emit("ovp:live:countdown:start",Pipe.of(e).fmap(l,t.opts).fmap(a).unwrap())}(t,n):function(t,e){t.emit("ovp:request:media:complete",Pipe.of(e).fmap(l,t.opts).fmap(a).unwrap())}(t,n)}function w(t,e){return e.message?t.emit("ovp:error",e):e.status?t.emit("ovp:error",new Error(s[e.status])):t.emit("ovp:error",e)}const _={};function g(t,e,n){"object"!=typeof _[e]&&(_[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 b=!1;function O(t,e,i){E()||Pipe.of("recommendation").fmap(o,e,i).fmap(n).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(P))}function E(){return b}function P(t){b=!0,console.error("Failed to load recommendations: %j",t)}function j(t){const e="number"==typeof t?t:parseInt(t,10);return(e>9?"":"0")+e}function A(t,e){const n=t._customElements.get(e);return n&&t.root.querySelector(n)||void 0}const T="flowplayer-live-countdown";function C(t){return t&&t.live_start_time&&t.live_start_time-Date.now()>0}function L(t,e){let o=0;function r(){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 s(){const n=r();if(n<0||isNaN(n)||0===t.reaper)return clearInterval(o),function(t,e){t.emit("ovp:live:countdown:complete");const n=A(t,T);n&&n.remove(),t.root.classList.remove("is-livecountdown"),t.emit("ovp:request:media:complete",e)}(t,e);var i,s,a;i=t,s=t.root,a=n,s.classList.add("is-livecountdown"),i.emit("ovp:live:countdown:tick",{remaining_time:x(a+1)}),i.hasState("is-starting")||i.setState("is-starting",!0)}var a;a=e,n(i()+"/web/public/countdown/time.json").then(t=>Object.assign(a,{server_time_offset:Date.now()-t.millisUtc})),s(),o=setInterval(s,250)}function x(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+j(e.hours)+":"+j(e.minutes)+":"+j(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 M=(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})}}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,T,FlowplayerLiveCountdown)}onload(t,e,n,o){if("string"==typeof o.src)return"string"!=typeof t.player_id||0===o.src.indexOf(t.player_id)||d(o)||(o.src=[t.player_id,o.src].join("/")),y(n,o)}wants(t,e,n){return u(t,e)}init(t,i,r){const s=new WebsocketBridge(r);let a=Object.assign({},t);const l=function(t){if(!a)return t;delete a.src;const n=e(t,a);return a=!1,n};r.on("ovp:error",(function(t){r.emit("error",t.data)})),r.on("ovp:request:start",(function(){r.setState("is-waiting",!0),t.recommendations&&(t.recommendations=!1)})),r.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&&(s.disconnect(),s.connect(n))})),r.on("ovp:message:realtime",(function({data:e}){var n;const o=null==e?void 0:e.event,i=null==e?void 0:e.value,s=r.opt("metadata",{live_start_time:""});switch(o){case"METADATA":{const e=Object.assign(s,i),o=Object.assign(t,{metadata:e});o.live&&(null===(n=null==o?void 0:o.metadata)||void 0===n?void 0:n.live_start_time)&&(o.live_start_time=m(o.metadata.live_start_time)),r.setOpts(o);break}}})),r.on("beforeplay",(function(e){const n=t;if(f(n)){if(S(n))return;e.preventDefault()}})),r.on("ovp:request:media:complete",(function(t){const e=t.data;if(!e)return;if(0==r.reaper||"object"!=typeof t.data||C(t.data))return;const n=l(e);r.setOpts(n),r.setAttrs(n),n.src&&r.setSrc(n.src),n.autoplay&&r.togglePlay(!0)})),r.on("config",(function({data:e}){var i;if("string"==typeof t.src&&u(t.src,{}))return;if(t.src&&D(t.src))return;const s=null==e?void 0:e.brand_color;return s&&r.root.style.setProperty("--fp-brand-color","#"==s[0]?s:"#"+s),"string"==typeof t.player_id&&(null===(i=null==t?void 0:t.metadata)||void 0===i?void 0:i.player_id)!==t.player_id?function(t,e){if("object"==typeof _[e])return console.debug("using Cache(%s)",e),g(t,e,_[e]);Pipe.of(e).fmap(o).fmap(n).fmap(n=>n.then(n=>g(t,e,n)).catch(console.error))}(r,t.player_id):void 0})),r.on("ovp:request:playlist:complete",(function(t){const e=t.data;if(!e||0==r.reaper)return;const{playlist:n}=e,o=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"]),i=l({playlist:o});Array.isArray(i.playlist)&&(i.playlist=o),r.setOpts(i);const s={type:"flowplayer/playlist",items:n};r.setSrc(s)})),r.on("ovp:live:countdown:start",(function(e){const n=e.data;if(!n||0==r.reaper)return;const o=l(n);if(r.setOpts(o),r.setAttrs(o),!C(n))return r.emit("ovp:request:media:complete",n);A(r,T)||(i.appendChild(M(r,T)),L(r,t))})),r.on("timeupdate",(function(){var e,n,o;const i=t;f(i)?S(i)||(r.togglePlay(!1),r.emit("ended")):t.recommendations&&((null===(e=null==t?void 0:t.metadata)||void 0===e?void 0:e.media_id)||Array.isArray(t.recommendations)||r.currentTime/r.duration<.8||E()||(null===(n=null==t?void 0:t.metadata)||void 0===n?void 0:n.media_id)&&(null===(o=null==t?void 0:t.metadata)||void 0===o?void 0:o.player_id)&&O(r,t.metadata.media_id,t.metadata.player_id))})),r.on("reap",(function(){s.disconnect()}))}}function S(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)||m(o)>Date.now()}OVP.events=v;const D=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}));
|
|
15
|
+
***************************************************************************** */function t(t,e,n,o){return new(n||(n=Promise))((function(i,r){function s(t){try{c(o.next(t))}catch(t){r(t)}}function a(t){try{c(o.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((o=o.apply(t,e||[])).next())}))}const e=t=>"object"==typeof t&&null!==t&&!Array.isArray(t),n=(...t)=>t.reduce((t,o)=>e(o)?(Object.keys(o).forEach(i=>{if(e(t[i])&&e(o[i]))return t[i]=n(t[i],o[i]);t[i]=o[i]}),t):t,{});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 o="https://ljsp.lwcdn.com".concat("/web/public/countdown/time.json"),i=window,r=i._flowplayerTimekeeper||(i._flowplayerTimekeeper={});function s(t){return fetch(t).then(t=>t.json())}function a(){let t=[].join.call(arguments,"/");return"/"!==t[0]&&(t="/"+t),c()+"/web/public/native/config"+t}const c=()=>"https://ljsp.lwcdn.com";function l(e){(function(){return t(this,void 0,void 0,(function*(){const t=r.cachedServerOffset;if(t)return t;const e=r.pendingRequest||(r.pendingRequest=fetch(o)),n=yield e,i=parseInt(n.headers.get("age")||"0"),s=yield n.json(),a=Date.now()-s.millisUtc-1e3*i;return r.cachedServerOffset=a,r.cachedServerOffset}))})().then(t=>Object.assign(e,{server_time_offset:t}))}function d(t){return~t.indexOf("/")?t:"/media/"+t}var u={404:"media not found",402:"invalid subscription",400:"bad request",415:"unsupported media type"};function p(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 f(t,e){var o,i;e="object"==typeof e?e:{};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},s={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)||{})}},a=e.embed||{};return delete a.src,n(s,r,t,(delete(c=e).src,delete c.metadata,delete c.title,delete c.description,delete c.duration,delete c.poster,c),a);var c}const m=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/;function v(t){return"object"==typeof t&&"ovp/base64"==t.type}function y(t,e){return function(t,e){return!(~t.indexOf(".")||!m.test(t))&&(e.type="video/ovp",!0)}(t,e)||v(e)}function h(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 w(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 _(t){return t.live}var g=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 b(t,e){const n=null==e?void 0:e.src;if(v(e))return function(t,e){const n=h(e.src||"");if(function(t){return"string"==typeof t.err}(n))return console.error(n.err);O(t,n)}(t,e);n&&Pipe.of(n).fmap(d).fmap(a).fmap(t=>fetch(t)).fmap(e=>e.then(t=>Promise.all([t.status,t.json()])).then(([e,n])=>200==e?O(t,n):E(t,n)))}function O(t,e){return t.emit("ovp:media:changed",e),function(t){return Array.isArray(t.playlist)}(e)?function(t,e){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,e){const o=Object.assign({},t),i=(null==t?void 0:t.playlist)||{},r=n(e,i),s=((null==r?void 0:r.playlist)||[]).map(t=>f(t,o));return Object.assign(r,{playlist:s})}(t.opts,e))}(t,e):_(e)?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(w).unwrap());t.emit("ovp:live:countdown:start",Pipe.of(e).fmap(f,t.opts).fmap(p).unwrap())}(t,e):function(t,e){t.emit("ovp:request:media:complete",Pipe.of(e).fmap(f,t.opts).fmap(p).unwrap())}(t,e)}function E(t,e){return e.message?t.emit("ovp:error",e):e.status?t.emit("ovp:error",new Error(u[e.status])):t.emit("ovp:error",e)}const P={};function j(t,e,n){"object"!=typeof P[e]&&(P[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 A=!1;function T(t,e,n){x()||Pipe.of("recommendation").fmap(a,e,n).fmap(s).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(S))}function x(){return A}function S(t){A=!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 L(t,e){const n=t._customElements.get(e);return n&&t.root.querySelector(n)||void 0}const M="flowplayer-live-countdown";function D(t){return t&&t.live_start_time&&t.live_start_time-Date.now()>0}function I(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=L(t,M);n&&n.remove(),t.root.classList.remove("is-livecountdown"),t.emit("ovp:request:media:complete",e)}(t,e);var r,s,a;r=t,s=t.root,a=i,s.classList.add("is-livecountdown"),r.emit("ovp:live:countdown:tick",{remaining_time:q(a+1)}),r.hasState("is-starting")||r.setState("is-starting",!0)}l(e),i(),n=setInterval(i,250)}function q(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 V=(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})}}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,M,FlowplayerLiveCountdown)}onload(t,e,n,o){if("string"==typeof o.src)return"string"!=typeof t.player_id||0===o.src.indexOf(t.player_id)||v(o)||(o.src=[t.player_id,o.src].join("/")),b(n,o)}wants(t,e,n){return y(t,e)}init(t,e,o){const i=new WebsocketBridge(o);let r=Object.assign({},t);const c=function(t){if(!r)return t;delete r.src;const e=n(t,r);return r=!1,e};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,s=o.opt("metadata",{live_start_time:""});switch(i){case"METADATA":{const e=Object.assign(s,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=w(i.metadata.live_start_time)),o.setOpts(i);break}}})),o.on("beforeplay",(function(e){const n=t;if(_(n)){if(k(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||D(t.data))return;const n=c(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 n;if("string"==typeof t.src&&y(t.src,{}))return;if(t.src&&R(t.src))return;const i=null==e?void 0:e.brand_color;return i&&o.root.style.setProperty("--fp-brand-color","#"==i[0]?i:"#"+i),"string"==typeof t.player_id&&(null===(n=null==t?void 0:t.metadata)||void 0===n?void 0:n.player_id)!==t.player_id?function(t,e){if("object"==typeof P[e])return console.debug("using Cache(%s)",e),j(t,e,P[e]);Pipe.of(e).fmap(a).fmap(s).fmap(n=>n.then(n=>j(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=c({playlist:i});Array.isArray(r.playlist)&&(r.playlist=i),o.setOpts(r);const s={type:"flowplayer/playlist",items:n};o.setSrc(s)})),o.on("ovp:live:countdown:start",(function(n){const i=n.data;if(!i||0==o.reaper)return;const r=c(i);if(o.setOpts(r),o.setAttrs(r),!D(i))return o.emit("ovp:request:media:complete",i);L(o,M)||(e.appendChild(V(o,M)),I(o,t))})),o.on("timeupdate",(function(){var e,n,i;const r=t;_(r)?k(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||x()||(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)&&T(o,t.metadata.media_id,t.metadata.player_id))})),o.on("reap",(function(){i.disconnect()}))}}function k(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)||w(o)>Date.now()}OVP.events=g;const R=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/preview.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,
|
|
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";const e=1,i=2;var t=Object.freeze({__proto__:null,MOUSEOVER:e,MOBILE_VIEWPORT_VISIBLE:i,VIEWPORT_VISIBLE:4});class PreviewPlugin{constructor(){this.disablePreview=this.disablePreview.bind(this),this.enablePreview=this.enablePreview.bind(this)}init(e,i,t){t.on("config",({data:e})=>{e&&this.configure(e)}),this.configure(e),this.root=i,this.player=t}configure(t){var o,n,r,s,l;if(!1===t.preview||!t.poster)return this.shutdown();if(void 0===t.preview)return;this.shutdown(),this.config=t;const{type:a="image/gif",trigger:d=e|i,src:u}=t.preview;if(!/^image/.test(a))return console.warn("flowplayer[preview] - only image/* supported");this.previewSource=u,e&d&&(null===(o=this.root)||void 0===o||o.addEventListener("mouseenter",this.enablePreview),null===(n=this.root)||void 0===n||n.addEventListener("mouseleave",this.disablePreview)),(4&d||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),o=/Android/.test(i)&&!/Firefox/.test(i),n=/^((?!chrome|android).)*safari/i.test(i),r=/SamsungBrowser/.test(i),s=r&&/SMART-TV/.test(i);return{controls:!t,video:function(i){return e&&document.createElement("video").canPlayType(i)},lang:e&&window.navigator.language,android:o,iphone:t,safari:n,ios:e&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,samsung:r,samsung_tv:r&&s,touch:!!("ontouchstart"in window)}}().touch&&i&d)&&(null===(r=this.player)||void 0===r||r.on("viewenter",this.enablePreview),null===(s=this.player)||void 0===s||s.on("viewleave",this.disablePreview),(null===(l=this.player)||void 0===l?void 0:l.in_viewport)&&this.enablePreview())}shutdown(){var e,i,t,o;null===(e=this.root)||void 0===e||e.removeEventListener("mouseenter",this.enablePreview),null===(i=this.root)||void 0===i||i.removeEventListener("mouseleave",this.disablePreview),null===(t=this.player)||void 0===t||t.off("viewenter",this.enablePreview),null===(o=this.player)||void 0===o||o.off("viewleave",this.disablePreview)}enablePreview(){this.root&&(this.root.style.backgroundImage=`url('${this.previewSource}')`)}disablePreview(){this.root&&this.config&&(this.root.style.backgroundImage=`url('${this.config.poster}')`)}}return PreviewPlugin.trigger=t,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)}));
|