@flowplayer/player 3.17.0-rc.1 → 3.17.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.js +1 -1
- package/default.js +1 -1
- package/embed.js +2 -2
- package/package.json +1 -1
- package/plugins/ads.js +2 -2
- package/plugins/analytics.js +1 -1
- package/plugins/chromecast.js +1 -1
- package/plugins/health.js +1 -1
- package/plugins/hls.js +1 -1
- package/plugins/rts.js +21 -2
- package/plugins/ssai.js +1 -1
- package/plugins/vtsel.js +1 -1
package/plugins/analytics.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.analytics=t())}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){var t={exports:{}};return e(t,t.exports),t.exports}var n,r=t((function(t,n){var r=e&&e.__assign||function(){return(r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};n.__esModule=!0,n.remove=n.downcase=n.pluck=n.merge=void 0,n.merge=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return e.reduce((function(e,t){return r(r({},e),t)}),{})},n.pluck=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return Object.keys(e).filter((function(e){return~t.indexOf(e)})).reduce((function(t,r){var i;return n.merge(t,((i={})[r]=e[r],i))}),{})},n.downcase=function(e){return(e||"").toString().toLowerCase()},n.remove=function(e,t){var n=e.lastIndexOf(t);return~n&&e.splice(n,1),e}})),i=t((function(t,n){var i=e&&e.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=e&&e.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=e&&e.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.hasOwnProperty.call(e,n)&&i(t,e,n);return o(t,e),t};n.__esModule=!0;var u=a(r),s=function(){function e(){this.pending=[],this.open=[],this.stats={failures:0,ttl:0}}return e.of=function(){return new e},e.is_empty=function(e){return 0==e.pending.length},e.is_high_water=function(t){return t.open.length==e.MAX_OPEN_REQUESTS},e.maybe_spawn_req=function(t){if(e.is_empty(t))return t;if(e.is_high_water(t))return t;try{var n=e.lpop(t);n&&e.request(t,n)}catch(e){}},e.increment_failures=function(t){return t.stats.failures++,t.stats.failures>e.MAX_FAILURE_COUNT&&(t.stats.ttl=Date.now()+e.REQUEST_TTL_MS),t},e.handle_error=function(t,n){e.rm(t,n),e.increment_failures(t)},e.request=function(t,n){var r=n[0],i=n[1],o=n[2];if(!(Date.now()<t.stats.ttl)){var a=new XMLHttpRequest;t.open.push(a),a.timeout=e.REQUEST_TIMEOUT_MS,a.ontimeout=function(){e.handle_error(t,a)},a.onerror=function(n){e.handle_error(t,a)},a.onreadystatechange=function(){a.readyState==XMLHttpRequest.DONE&&e.rm(t,a),Math.floor(a.status/100)},a.onload=function(){e.rm(t,a),t.stats.failures&&t.stats.failures--},a.open(i,r),a.setRequestHeader("Content-Type","text/plain;charset=UTF-8");try{a.send(JSON.stringify(o))}catch(e){}}},e.rpush=function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return n.forEach((function(n){t.pending.length>=e.MAX_PENDING||(t.pending.push(n),e.maybe_spawn_req(t))})),t},e.lpop=function(e){return e.pending.shift()},e.rm=function(e,t){return u.remove(e.open,t),e},e.MAX_OPEN_REQUESTS=3,e.MAX_PENDING=5,e.REQUEST_TIMEOUT_MS=4e3,e.REQUEST_TTL_MS=5e3,e.MAX_FAILURE_COUNT=3,e}();n.default=s})),o=t((function(t,n){var r=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};n.__esModule=!0;var o=r(i);n.default=o.default.of()})),a=t((function(e,t){t.__esModule=!0,t.prepare_url=t.URL_PARAM=void 0,t.URL_PARAM=/:([a-zA-Z_]+)/g,t.prepare_url=function(e,n){return e.url.replace(t.URL_PARAM,(function(t){if((t=t.slice(1,t.length))in n)return n[t].toString();e.log.error(new Error("\n preparing url["+e.url+"] failed\n \n parameter["+t+"] not detected in params:\n \n "+JSON.stringify(n,null,2)+"\n "))}))}})),u=t((function(e,t){t.__esModule=!0,t.Log=void 0;var n=function(){function e(e){this.emitter=e}return e.prepare=function(e,t){var n=document.createEvent("Event");return n.initEvent(e,!1,!0),n.ns=e,n.data=t,n},e.of=function(t){return new e(t)},e.prototype.info=function(t){this.emitter.dispatchEvent(e.prepare(e.NAMESPACE.INFO,t))},e.prototype.error=function(t){this.emitter.dispatchEvent(e.prepare(e.NAMESPACE.ERROR,t))},e.prototype.warn=function(t){this.emitter.dispatchEvent(e.prepare(e.NAMESPACE.WARN,t))},e.NAMESPACE={INFO:"tracker:info",ERROR:"tracker:err",WARN:"tracker:warn"},e}();t.Log=n})),s=t((function(e,t){var n;t.__esModule=!0,t.Verb=void 0,(n=t.Verb||(t.Verb={})).POST="POST",n.PUT="PUT",n.GET="GET"})),d=t((function(t,n){var d=e&&e.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),c=e&&e.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),f=e&&e.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.hasOwnProperty.call(e,n)&&d(t,e,n);return c(t,e),t},l=e&&e.__spreadArrays||function(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),i=0;for(t=0;t<n;t++)for(var o=arguments[t],a=0,u=o.length;a<u;a++,i++)r[i]=o[a];return r},p=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};n.__esModule=!0;var _=p(o),v=p(i),m=f(a),h=f(r),y=function(){function e(t,n){var r=this;void 0===n&&(n={});var i=this;if(this.emitter=t,this.url=n.url,this.log=u.Log.of(this.emitter),this.verb=n.verb,this.metadata=h.merge({},n.metadata||{}),this.rq=n.rq||_.default,this.events=n.events||[],this.required_keys=n.required_keys||[],this.optional_keys=n.optional_keys||[],this.listeners=[],this.valid_keys=this.required_keys.slice(0).concat(this.optional_keys),e.assert_emitter_api(this.emitter),void 0===e.verb[this.verb])throw new Error("invalid HTTP verb["+this.verb+"] passed");if("string"!=typeof this.url)throw new Error("invalid API url["+this.url+"] passed");e.TRACKERS.push(this),i.events.forEach((function(t){e.create_listener(r,t,(function(n){void 0===n&&(n={});var o=h.merge(i.metadata,{event_type:t},n.data||n),a=m.prepare_url(i,o),u=e.pluck_valid_keys(i,o),s=e.ensure_required_keys(i,u);if(s.length)return i.log.error("Tracker.validate_metadata() failed for \n Event["+t+"]\n missing keys: "+s+"\n payload:\n "+JSON.stringify(u,null,2));v.default.rpush(r.rq,[a,r.verb,u])}))}))}return e.of=function(t,n){return new e(t,n)},e.ensure_required_keys=function(e,t){return e.required_keys.filter((function(e){return!(e in t)}))},e.pluck_valid_keys=function(e,t){return h.pluck.apply(h,l([t],e.valid_keys))},e.merge_metadata=function(t,n){return void 0===n&&(n={}),t.metadata=e.pluck_valid_keys(t,h.merge(t.metadata,n)),t},e.assert_emitter_api=function(e){if("function"!=typeof(e||{}).addEventListener)throw new Error("Tracker() received an emitter that does not implement the addEventListener method");if("function"!=typeof(e||{}).removeEventListener)throw new Error("Tracker() received an emitter that does not implement the removeEventListener method")},e.create_listener=function(e,t,n){e.listeners.push([t,n]),e.emitter.addEventListener(t,n)},e.prototype.destroy=function(){var t=this;this.listeners.forEach((function(e){var n=e[0],r=e[1];return t.emitter.removeEventListener(n,r)})),delete this.rq,delete this.emitter,h.remove(e.TRACKERS,this)},e.prototype.put=function(t){return void 0===t&&(t={}),e.merge_metadata(this,t),this},e.TRACKERS=[],e.QUEUE=_.default,e.verb=s.Verb,e}();n.default=y})),c=t((function(t,n){var r=e&&e.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),i=e&&e.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=e&&e.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.hasOwnProperty.call(e,n)&&r(t,e,n);return i(t,e),t},u=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};n.__esModule=!0,n.API=n.Tracker=void 0;var s=u(d);n.Tracker=s.default;var c=o(a);n.API=c}));!function(e){e[e.ADS=2]="ADS",e[e.ANALYTICS=4]="ANALYTICS",e[e.NO_METERING=8]="NO_METERING",e[e.DEVELOPER_PLAN=16]="DEVELOPER_PLAN",e[e.WOWZA_VIDEO=32]="WOWZA_VIDEO"}(n||(n={}));const f=["localhost","127.0.0.1","0.0.0.0","s.codepen.io","cdpn.io","try.flowplayer.com"];function l(e,t){return!!~f.indexOf(e)||e.indexOf(t)===e.length-t.length}l.check_whitelist=function(e){return!!~f.indexOf(e)};function p(e){this.message=e}p.prototype=new Error,p.prototype.name="InvalidCharacterError";var _="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new p("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,r,i=0,o=0,a="";r=t.charAt(o++);~r&&(n=i%4?64*n+r:r,i++%4)?a+=String.fromCharCode(255&n>>(-2*i&6)):0)r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(r);return a};var v=function(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw"Illegal base64url string!"}try{return function(e){return decodeURIComponent(_(e).replace(/(.)/g,(function(e,t){var n=t.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(t)}catch(e){return _(t)}};function m(e){this.message=e}m.prototype=new Error,m.prototype.name="InvalidTokenError";var h=function(e,t){if("string"!=typeof e)throw new m("Invalid token specified");var n=!0===(t=t||{}).header?0:1;try{return JSON.parse(v(e.split(".")[n]))}catch(e){throw new m("Invalid token specified: "+e.message)}};h.InvalidTokenError=m;const y="production";function g(e,t){const n={valid_jwt:!1,raw:"",data:{acl:0},exp:0};let r={c:"{}",exp:0};t=t||{};try{r=h(e),n.valid_jwt=!0}catch(e){}return n.raw=e,n.data=JSON.parse(r.c),n.exp=r.exp,t.require_valid_token&&g.validate(n),n}function w(e){return{grant:e,is_granted:t=>(e&t)===t}}function k(e,t,n){const r=function(e){return Array.isArray(e)?e.slice(0):e.split(".")}(t);for(;r.length;){if(null==e)return n;const t=r.shift();if("string"!=typeof t)return n;e=e[t]}return null==e?n:e}g.validate=function(e){if("string"==typeof e&&(e=g(e)),!e||!e.raw){if(l.check_whitelist(window.location.hostname)||"dev"===y.toString())return!0;throw new Error("No token provided in configuration")}if(!e.valid_jwt)throw new Error("Invalid token provided");const t=window.location.hostname,n=l.bind(null,t);if("dev"!==y.toString()&&e.data.domain&&e.data.domain.length&&!e.data.domain.some(n))throw new Error("Domain not allowed");if("dev"!==y.toString()&&1e3*e.exp-Date.now()<0)throw new Error("Expired token");return!0},g.id=function(e){if(e)return"string"==typeof e&&(e=g(e)),e.data.id},w.of=w,w.from_token=function(e){const t=g(e,{require_valid_token:!0});return w.of(t.data.acl)},w.permissions=n;var E="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};var b="ping",O="display",A="view";const T=["sitegroup_id","session_id","media_id","site_id","player_id","video_type"],S=["created","position"],M=["player_version","created","source","category","category_id","autoplay","muted","customer_user_id"];function P(e,t){return e.duration/1===e.duration&&Object.assign(t,function(e){const t=e/100;return{segment_duration:t,breakpoints:Array(...Array(100)).map((function(e,n){return Math.floor(n*t*1e3)/1e3}))}}(e.duration))}function R(e,t,n){if(!t.segment_duration&&!P(e,t))return;const r=function(e,t,n){const r=t.last_idx,i=n?99:x(e,t);return t.last_idx=i,i<=r?[]:t.breakpoints.slice(r,99==i?100:i).map((function(e){return t.breakpoints.indexOf(e)}))}(e,t,n);0!=r.length&&e.emit(b,{position:r})}function x(e,t){return Math.min(Math.floor(e.currentTime/t.segment_duration),99)}function N(){try{const e=window.location!==window.parent.location?document.referrer:document.location.href;return"string"==typeof e&&e.slice(0,200)}catch(e){return!1}}const I="vod",L="live",j=[O,b,A];function q(e,t,n){switch(null==t?void 0:t.kind){case"live":return function(e,t){const n=Date.now();n-t.last_tracked_ts<6e4||(t.last_tracked_ts=n,++t.ticks,e.emit(b,{position:60*t.ticks}))}(e,t);case"vod":return R(e,t,"boolean"==typeof n&&n)}}function U(e){const t=e.ads;return void 0!==t&&(void 0!==t.schedule&&("function"==typeof t.hasPreroll&&(t.currentRequests?t.currentRequests:!!t.adPlaying||!(!t.hasPreroll()||0!=t.nextIndex))))}return function(e,t){if("object"==typeof exports&&"undefined"!=typeof module)return t;if(null===document.currentScript)return t;"flowplayer"in e||(e.flowplayer={extensions:[]});const n=e.flowplayer;return"function"==typeof n?(n(t),t):(Array.isArray(n.extensions)||(n.extensions=[]),~n.extensions.indexOf(t)||n.extensions.push(t),t)}("undefined"!=typeof window?window:void 0!==E?E:{},class Analytics{init(e,t,n){if(!w.from_token(e.token||"").is_granted(w.permissions.ANALYTICS))return;if(n.hasState("consent-no-tracking"))return;if(n.analytics)return;const r=n.analytics={ticker:void 0,last_media_id:"",ended:!1},i={locked:!1,ttl:6e3,task:()=>{q(n,r.ticker)}};const o={session_id:n.deviceId(),autoplay:n.autoplay,muted:n.muted,player_id:e.player_id,customer_user_id:e.customer_user_id,player_version:"3.17.0-rc.1"},a=c.Tracker.of(n,{verb:c.Tracker.verb.POST,url:"https://ptm.flowplayer.com/:video_type/:sitegroup_id/:event_type",events:j,required_keys:T,optional_keys:M.concat(S).slice(0),metadata:o});n.on("reap",(function(){a&&a.destroy()})),n.on("config",(function(t){if(!a)return;const i=k(t,"data.metadata",{});if(!i.media_id)return;const o=k(a,"metadata.media_id");if(o&&i.media_id==o)return;const u=k(e,"analytics",{});a.put(i),a.put(u);const s=k(e,"metadata.live_start_time",e.live)?L:I;a.put({video_type:s,source:e.source||N()||""}),r.ticker=e.live?{ticks:0,last_tracked_ts:Date.now(),kind:"live"}:{last_idx:0,segment_duration:0,breakpoints:[],kind:"vod"},r.ended=!1,n.emit(O)}));let u=0;n.on("playing",(function(){if(!a)return;if(u||function(e,t){return e.metadata.media_id&&e.metadata.media_id==t.last_media_id}(a,r))return;a.put({muted:n.muted});const e=U(n);if(e)return u=Promise.resolve(e).then((function(){r.last_media_id=a.metadata.media_id,n.emit(A),u=0})).catch((function(){u=0}));r.last_media_id=a.metadata.media_id,n.emit(A)})),n.on("timeupdate",(function(){var t;a&&(u||U(n)||r.ended||(!e.live&&n.currentTime+.25>=n.duration&&q(n,r.ticker,!0),(t=i).locked||(t.locked=setTimeout((function(){return t.task(),function(e){return e.locked=!1,e}(t)}),t.ttl))))})),n.on("seeked",(function(){a&&r.ticker&&"vod"==r.ticker.kind&&function(e,t){P(e,t),t.last_idx=x(e,t)}(n,r.ticker)})),n.on("ended",(function(){a&&function(e,t){t.ended||(t.ended=!0,q(e,t.ticker))}(n,r)}))}})}));
|
|
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.analytics=t())}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){var t={exports:{}};return e(t,t.exports),t.exports}var n,r=t((function(t,n){var r=e&&e.__assign||function(){return(r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};n.__esModule=!0,n.remove=n.downcase=n.pluck=n.merge=void 0,n.merge=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return e.reduce((function(e,t){return r(r({},e),t)}),{})},n.pluck=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return Object.keys(e).filter((function(e){return~t.indexOf(e)})).reduce((function(t,r){var i;return n.merge(t,((i={})[r]=e[r],i))}),{})},n.downcase=function(e){return(e||"").toString().toLowerCase()},n.remove=function(e,t){var n=e.lastIndexOf(t);return~n&&e.splice(n,1),e}})),i=t((function(t,n){var i=e&&e.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=e&&e.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=e&&e.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.hasOwnProperty.call(e,n)&&i(t,e,n);return o(t,e),t};n.__esModule=!0;var u=a(r),s=function(){function e(){this.pending=[],this.open=[],this.stats={failures:0,ttl:0}}return e.of=function(){return new e},e.is_empty=function(e){return 0==e.pending.length},e.is_high_water=function(t){return t.open.length==e.MAX_OPEN_REQUESTS},e.maybe_spawn_req=function(t){if(e.is_empty(t))return t;if(e.is_high_water(t))return t;try{var n=e.lpop(t);n&&e.request(t,n)}catch(e){}},e.increment_failures=function(t){return t.stats.failures++,t.stats.failures>e.MAX_FAILURE_COUNT&&(t.stats.ttl=Date.now()+e.REQUEST_TTL_MS),t},e.handle_error=function(t,n){e.rm(t,n),e.increment_failures(t)},e.request=function(t,n){var r=n[0],i=n[1],o=n[2];if(!(Date.now()<t.stats.ttl)){var a=new XMLHttpRequest;t.open.push(a),a.timeout=e.REQUEST_TIMEOUT_MS,a.ontimeout=function(){e.handle_error(t,a)},a.onerror=function(n){e.handle_error(t,a)},a.onreadystatechange=function(){a.readyState==XMLHttpRequest.DONE&&e.rm(t,a),Math.floor(a.status/100)},a.onload=function(){e.rm(t,a),t.stats.failures&&t.stats.failures--},a.open(i,r),a.setRequestHeader("Content-Type","text/plain;charset=UTF-8");try{a.send(JSON.stringify(o))}catch(e){}}},e.rpush=function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return n.forEach((function(n){t.pending.length>=e.MAX_PENDING||(t.pending.push(n),e.maybe_spawn_req(t))})),t},e.lpop=function(e){return e.pending.shift()},e.rm=function(e,t){return u.remove(e.open,t),e},e.MAX_OPEN_REQUESTS=3,e.MAX_PENDING=5,e.REQUEST_TIMEOUT_MS=4e3,e.REQUEST_TTL_MS=5e3,e.MAX_FAILURE_COUNT=3,e}();n.default=s})),o=t((function(t,n){var r=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};n.__esModule=!0;var o=r(i);n.default=o.default.of()})),a=t((function(e,t){t.__esModule=!0,t.prepare_url=t.URL_PARAM=void 0,t.URL_PARAM=/:([a-zA-Z_]+)/g,t.prepare_url=function(e,n){return e.url.replace(t.URL_PARAM,(function(t){if((t=t.slice(1,t.length))in n)return n[t].toString();e.log.error(new Error("\n preparing url["+e.url+"] failed\n \n parameter["+t+"] not detected in params:\n \n "+JSON.stringify(n,null,2)+"\n "))}))}})),u=t((function(e,t){t.__esModule=!0,t.Log=void 0;var n=function(){function e(e){this.emitter=e}return e.prepare=function(e,t){var n=document.createEvent("Event");return n.initEvent(e,!1,!0),n.ns=e,n.data=t,n},e.of=function(t){return new e(t)},e.prototype.info=function(t){this.emitter.dispatchEvent(e.prepare(e.NAMESPACE.INFO,t))},e.prototype.error=function(t){this.emitter.dispatchEvent(e.prepare(e.NAMESPACE.ERROR,t))},e.prototype.warn=function(t){this.emitter.dispatchEvent(e.prepare(e.NAMESPACE.WARN,t))},e.NAMESPACE={INFO:"tracker:info",ERROR:"tracker:err",WARN:"tracker:warn"},e}();t.Log=n})),s=t((function(e,t){var n;t.__esModule=!0,t.Verb=void 0,(n=t.Verb||(t.Verb={})).POST="POST",n.PUT="PUT",n.GET="GET"})),d=t((function(t,n){var d=e&&e.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),c=e&&e.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),f=e&&e.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.hasOwnProperty.call(e,n)&&d(t,e,n);return c(t,e),t},l=e&&e.__spreadArrays||function(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),i=0;for(t=0;t<n;t++)for(var o=arguments[t],a=0,u=o.length;a<u;a++,i++)r[i]=o[a];return r},p=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};n.__esModule=!0;var _=p(o),v=p(i),m=f(a),h=f(r),y=function(){function e(t,n){var r=this;void 0===n&&(n={});var i=this;if(this.emitter=t,this.url=n.url,this.log=u.Log.of(this.emitter),this.verb=n.verb,this.metadata=h.merge({},n.metadata||{}),this.rq=n.rq||_.default,this.events=n.events||[],this.required_keys=n.required_keys||[],this.optional_keys=n.optional_keys||[],this.listeners=[],this.valid_keys=this.required_keys.slice(0).concat(this.optional_keys),e.assert_emitter_api(this.emitter),void 0===e.verb[this.verb])throw new Error("invalid HTTP verb["+this.verb+"] passed");if("string"!=typeof this.url)throw new Error("invalid API url["+this.url+"] passed");e.TRACKERS.push(this),i.events.forEach((function(t){e.create_listener(r,t,(function(n){void 0===n&&(n={});var o=h.merge(i.metadata,{event_type:t},n.data||n),a=m.prepare_url(i,o),u=e.pluck_valid_keys(i,o),s=e.ensure_required_keys(i,u);if(s.length)return i.log.error("Tracker.validate_metadata() failed for \n Event["+t+"]\n missing keys: "+s+"\n payload:\n "+JSON.stringify(u,null,2));v.default.rpush(r.rq,[a,r.verb,u])}))}))}return e.of=function(t,n){return new e(t,n)},e.ensure_required_keys=function(e,t){return e.required_keys.filter((function(e){return!(e in t)}))},e.pluck_valid_keys=function(e,t){return h.pluck.apply(h,l([t],e.valid_keys))},e.merge_metadata=function(t,n){return void 0===n&&(n={}),t.metadata=e.pluck_valid_keys(t,h.merge(t.metadata,n)),t},e.assert_emitter_api=function(e){if("function"!=typeof(e||{}).addEventListener)throw new Error("Tracker() received an emitter that does not implement the addEventListener method");if("function"!=typeof(e||{}).removeEventListener)throw new Error("Tracker() received an emitter that does not implement the removeEventListener method")},e.create_listener=function(e,t,n){e.listeners.push([t,n]),e.emitter.addEventListener(t,n)},e.prototype.destroy=function(){var t=this;this.listeners.forEach((function(e){var n=e[0],r=e[1];return t.emitter.removeEventListener(n,r)})),delete this.rq,delete this.emitter,h.remove(e.TRACKERS,this)},e.prototype.put=function(t){return void 0===t&&(t={}),e.merge_metadata(this,t),this},e.TRACKERS=[],e.QUEUE=_.default,e.verb=s.Verb,e}();n.default=y})),c=t((function(t,n){var r=e&&e.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),i=e&&e.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=e&&e.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.hasOwnProperty.call(e,n)&&r(t,e,n);return i(t,e),t},u=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};n.__esModule=!0,n.API=n.Tracker=void 0;var s=u(d);n.Tracker=s.default;var c=o(a);n.API=c}));!function(e){e[e.ADS=2]="ADS",e[e.ANALYTICS=4]="ANALYTICS",e[e.NO_METERING=8]="NO_METERING",e[e.DEVELOPER_PLAN=16]="DEVELOPER_PLAN",e[e.WOWZA_VIDEO=32]="WOWZA_VIDEO"}(n||(n={}));const f=["localhost","127.0.0.1","0.0.0.0","s.codepen.io","cdpn.io","try.flowplayer.com"];function l(e,t){return!!~f.indexOf(e)||e.indexOf(t)===e.length-t.length}l.check_whitelist=function(e){return!!~f.indexOf(e)};function p(e){this.message=e}p.prototype=new Error,p.prototype.name="InvalidCharacterError";var _="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new p("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,r,i=0,o=0,a="";r=t.charAt(o++);~r&&(n=i%4?64*n+r:r,i++%4)?a+=String.fromCharCode(255&n>>(-2*i&6)):0)r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(r);return a};var v=function(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw"Illegal base64url string!"}try{return function(e){return decodeURIComponent(_(e).replace(/(.)/g,(function(e,t){var n=t.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(t)}catch(e){return _(t)}};function m(e){this.message=e}m.prototype=new Error,m.prototype.name="InvalidTokenError";var h=function(e,t){if("string"!=typeof e)throw new m("Invalid token specified");var n=!0===(t=t||{}).header?0:1;try{return JSON.parse(v(e.split(".")[n]))}catch(e){throw new m("Invalid token specified: "+e.message)}};h.InvalidTokenError=m;const y="production";function g(e,t){const n={valid_jwt:!1,raw:"",data:{acl:0},exp:0};let r={c:"{}",exp:0};t=t||{};try{r=h(e),n.valid_jwt=!0}catch(e){}return n.raw=e,n.data=JSON.parse(r.c),n.exp=r.exp,t.require_valid_token&&g.validate(n),n}function w(e){return{grant:e,is_granted:t=>(e&t)===t}}function k(e,t,n){const r=function(e){return Array.isArray(e)?e.slice(0):e.split(".")}(t);for(;r.length;){if(null==e)return n;const t=r.shift();if("string"!=typeof t)return n;e=e[t]}return null==e?n:e}g.validate=function(e){if("string"==typeof e&&(e=g(e)),!e||!e.raw){if(l.check_whitelist(window.location.hostname)||"dev"===y.toString())return!0;throw new Error("No token provided in configuration")}if(!e.valid_jwt)throw new Error("Invalid token provided");const t=window.location.hostname,n=l.bind(null,t);if("dev"!==y.toString()&&e.data.domain&&e.data.domain.length&&!e.data.domain.some(n))throw new Error("Domain not allowed");if("dev"!==y.toString()&&1e3*e.exp-Date.now()<0)throw new Error("Expired token");return!0},g.id=function(e){if(e)return"string"==typeof e&&(e=g(e)),e.data.id},w.of=w,w.from_token=function(e){const t=g(e,{require_valid_token:!0});return w.of(t.data.acl)},w.permissions=n;var E="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};var b="ping",O="display",A="view";const T=["sitegroup_id","session_id","media_id","site_id","player_id","video_type"],S=["created","position"],M=["player_version","created","source","category","category_id","autoplay","muted","customer_user_id"];function P(e,t){return e.duration/1===e.duration&&Object.assign(t,function(e){const t=e/100;return{segment_duration:t,breakpoints:Array(...Array(100)).map((function(e,n){return Math.floor(n*t*1e3)/1e3}))}}(e.duration))}function R(e,t,n){if(!t.segment_duration&&!P(e,t))return;const r=function(e,t,n){const r=t.last_idx,i=n?99:x(e,t);return t.last_idx=i,i<=r?[]:t.breakpoints.slice(r,99==i?100:i).map((function(e){return t.breakpoints.indexOf(e)}))}(e,t,n);0!=r.length&&e.emit(b,{position:r})}function x(e,t){return Math.min(Math.floor(e.currentTime/t.segment_duration),99)}function N(){try{const e=window.location!==window.parent.location?document.referrer:document.location.href;return"string"==typeof e&&e.slice(0,200)}catch(e){return!1}}const I="vod",L="live",j=[O,b,A];function q(e,t,n){switch(null==t?void 0:t.kind){case"live":return function(e,t){const n=Date.now();n-t.last_tracked_ts<6e4||(t.last_tracked_ts=n,++t.ticks,e.emit(b,{position:60*t.ticks}))}(e,t);case"vod":return R(e,t,"boolean"==typeof n&&n)}}function U(e){const t=e.ads;return void 0!==t&&(void 0!==t.schedule&&("function"==typeof t.hasPreroll&&(t.currentRequests?t.currentRequests:!!t.adPlaying||!(!t.hasPreroll()||0!=t.nextIndex))))}return function(e,t){if("object"==typeof exports&&"undefined"!=typeof module)return t;if(null===document.currentScript)return t;"flowplayer"in e||(e.flowplayer={extensions:[]});const n=e.flowplayer;return"function"==typeof n?(n(t),t):(Array.isArray(n.extensions)||(n.extensions=[]),~n.extensions.indexOf(t)||n.extensions.push(t),t)}("undefined"!=typeof window?window:void 0!==E?E:{},class Analytics{init(e,t,n){if(!w.from_token(e.token||"").is_granted(w.permissions.ANALYTICS))return;if(n.hasState("consent-no-tracking"))return;if(n.analytics)return;const r=n.analytics={ticker:void 0,last_media_id:"",ended:!1},i={locked:!1,ttl:6e3,task:()=>{q(n,r.ticker)}};const o={session_id:n.deviceId(),autoplay:n.autoplay,muted:n.muted,player_id:e.player_id,customer_user_id:e.customer_user_id,player_version:"3.17.0"},a=c.Tracker.of(n,{verb:c.Tracker.verb.POST,url:"https://ptm.flowplayer.com/:video_type/:sitegroup_id/:event_type",events:j,required_keys:T,optional_keys:M.concat(S).slice(0),metadata:o});n.on("reap",(function(){a&&a.destroy()})),n.on("config",(function(t){if(!a)return;const i=k(t,"data.metadata",{});if(!i.media_id)return;const o=k(a,"metadata.media_id");if(o&&i.media_id==o)return;const u=k(e,"analytics",{});a.put(i),a.put(u);const s=k(e,"metadata.live_start_time",e.live)?L:I;a.put({video_type:s,source:e.source||N()||""}),r.ticker=e.live?{ticks:0,last_tracked_ts:Date.now(),kind:"live"}:{last_idx:0,segment_duration:0,breakpoints:[],kind:"vod"},r.ended=!1,n.emit(O)}));let u=0;n.on("playing",(function(){if(!a)return;if(u||function(e,t){return e.metadata.media_id&&e.metadata.media_id==t.last_media_id}(a,r))return;a.put({muted:n.muted});const e=U(n);if(e)return u=Promise.resolve(e).then((function(){r.last_media_id=a.metadata.media_id,n.emit(A),u=0})).catch((function(){u=0}));r.last_media_id=a.metadata.media_id,n.emit(A)})),n.on("timeupdate",(function(){var t;a&&(u||U(n)||r.ended||(!e.live&&n.currentTime+.25>=n.duration&&q(n,r.ticker,!0),(t=i).locked||(t.locked=setTimeout((function(){return t.task(),function(e){return e.locked=!1,e}(t)}),t.ttl))))})),n.on("seeked",(function(){a&&r.ticker&&"vod"==r.ticker.kind&&function(e,t){P(e,t),t.last_idx=x(e,t)}(n,r.ticker)})),n.on("ended",(function(){a&&function(e,t){t.ended||(t.ended=!0,q(e,t.ticker))}(n,r)}))}})}));
|
package/plugins/chromecast.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.chromecast=t())}(this,(function(){"use strict";function e(e){const t=document.createElement("a");t.href=e;const n=t.pathname&&t.pathname.split(".");return n.length>1&&n[n.length-1]}function t(e){switch(e){case"video/mpd":return"application/dash+xml";case"video/m3u8":return"application/x-mpegurl";default:return e}}const n=n=>{var{src:r}=n,o=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}(n,["src"]);return[Object.assign({src:r,type:r?t("video/"+e(r)):""},o)]};function r(e){return n({src:e})}class Pipe{constructor(e){this.data=e}static of(e){return new Pipe(e)}static maybe(e,t,...n){return null==e?e:t.apply(e,[e,...n])}tap(e,...t){return e.apply(this,[this.data,...t]),new Pipe(this.data)}fmap(e,...t){const n=e.apply(this,[this.data,...t]);return new Pipe(n)}unwrap(){return this.data}}const o="chromecast:idle";var a=Object.freeze({__proto__:null,CAST_AVAILABLE:"chromecast:available",CAST_UNAVAILABLE:"chromecast:unavailable",CAST_START_CASTING:"chromecast:start",CAST_IDLE:o,CAST_STATE_CHANGED:"chromecast:state:changed",CAST_SESSION_CHANGED:"chromecast:session:changed",CAST_FIELD_UPDATE:"chromecast:field:update",CAST_MEDIA_LOAD_REQUEST:"chromecast:media"});const s=/(video\/mp4)|(application\/x-mpegurl)|(video\/mpd)|(application\/dash\+xml)/;function i(){var e;return(null===(e=f())||void 0===e?void 0:e.getCurrentSession())||null}function c(e){return p(e).unwrap().shift()}function l(){var e;return(null===(e=i())||void 0===e?void 0:e.getMediaSession())||null}function u(e){var t,n;const r=p(e).unwrap().map((function(e){return null==e?void 0:e.src})),o=null===(n=null===(t=l())||void 0===t?void 0:t.media)||void 0===n?void 0:n.contentId;return!!o&&!!~r.indexOf(o)}function d(e){var t;return(null===(t=e.type)||void 0===t?void 0:t.match(s))||!1}function m(e,t){if(!t.opts.src)return e;const n=(Array.isArray(t.opts.src)?t.opts.src:[t.opts.src]).map(e=>"string"==typeof e?r(e)[0]:e);return e.map(e=>{const t=n.find(t=>t.src===e.src);return t&&t.drm?Object.assign(Object.assign({},e),{drm:t.drm}):e})}function p(e){return Pipe.of(e).fmap(()=>e.original_src||[]).fmap((function(e){return"string"==typeof e?r(e):e})).fmap(m,e).fmap((function(e){return e.filter(d)}))}function f(){var e,t,n;return null===(n=null===(t=null===(e=window.cast)||void 0===e?void 0:e.framework)||void 0===t?void 0:t.CastContext)||void 0===n?void 0:n.getInstance()}function v(e){return e.filter((function(e){return u(e)}))}function h(e){return e.filter((function(e){return!u(e)}))}function y(e,t,n){v(e).forEach((function(e){e.emit(t,n)}))}function S(e,t,n){h(e).forEach((function(e){e.emit(t,n)}))}function E(e,t,n){e.forEach((function(e){e.emit(t,n)}))}const g={PAUSED:"isPaused",CURRENT_TIME:"currentTime",DURATION:"duration",CONNECTED:"isConnected",PLAYER_STATE:"playerState",SAVED_STATE:"savedPlayerState",DISPLAY_NAME:"displayName",STATUS:"statusText",VOLUME:"volumeLevel",MUTE:"isMuted",LIVE_RANGES:"liveSeekableRange"},w={player:void 0,controller:void 0,listener:void 0};function _(e){w.controller&&w.listener&&w.controller.removeEventListener(cast.framework.RemotePlayerEventType.ANY_CHANGE,w.listener),w.player=new cast.framework.RemotePlayer,w.controller=new cast.framework.RemotePlayerController(w.player),w.listener=T.bind(null,e),w.controller.addEventListener(cast.framework.RemotePlayerEventType.ANY_CHANGE,w.listener)}function T(e,t){if("IDLE"===t.value)return S(e,o);y(e,"chromecast:field:update",t)}function b(e){return Array.from(e.textTracks).filter(e=>["subtitles","captions"].includes(e.kind))}function A(e){return b(e).flatMap((t,n)=>{try{const r=e.querySelector("#"+t.id);if(!(r instanceof HTMLTrackElement&&r.lang))return[];const o=new chrome.cast.media.Track(n+1e3,chrome.cast.media.TrackType.TEXT);return o.trackContentType="text/vtt",o.subtype=chrome.cast.media.TextTrackType.SUBTITLES,o.trackContentId=r.src,o.name=r.label,o.language=r.lang,o}catch(e){return[]}})}function C(e){var t;const n=new chrome.cast.media.EditTracksInfoRequest(e);null===(t=l())||void 0===t||t.editTracksInfo(n,console.debug,console.error)}var k=Object.freeze({__proto__:null,getCurrentSession:i,getMedia:c,getMediaSession:l,isSame:u,is_supported_media:d,injectDRMConfiguration:m,normalizeSrc:p,getCastContext:f,casting_players:v,idle_players:h,broadcast_to_active:y,broadcast_to_idle:S,broadcast:E,FIELDS:g,SINGLETONS:w,refresh_singletons:_,onremotechange:T,tracks:b,cast_tracks:A,editTracks:C});function O(e,t,n,r){var a,s,l,u,d;const m=i();if(!m)return;const p=c(e);if(!p||!p.src)return;const f=new chrome.cast.media.MediaInfo(p.src,p.type||"");f.metadata=new chrome.cast.media.GenericMediaMetadata;const v={health:e.health,text_tracks:A(e),active_tracks:{active_audio:(null===(s=null===(a=null==e?void 0:e.asel)||void 0===a?void 0:a.active_track)||void 0===s?void 0:s.name)||(null===(u=null===(l=null==e?void 0:e.asel)||void 0===l?void 0:l.active_track)||void 0===u?void 0:u.lang),active_text:null===(d=b(e).find(e=>e.is_active))||void 0===d?void 0:d.label}};p.drm&&(v.drm=p.drm),localStorage.__fpChromecastDebug&&(v.debug=!0),e.opt("ads")&&(v.ads=e.opt("ads")),f.customData=v;const h=new chrome.cast.media.LoadRequest(f);isNaN(e.currentTime)||(h.currentTime=e.currentSessionTime),h.customData=e.opt("chromecast",{}),h.customData.metadata=e.opt("metadata"),e.emit("chromecast:media",{request:h}),console.debug("cast:request(%o)",h),m.loadMedia(h).then((function(){_(t);const n=w.player;n&&(e.volume=n.volumeLevel,e.muted=n.isMuted),S(t,o)}),r)}function L(){return!!l()}function I(){return!!i()}function N(){var e;return(null===(e=null==k?void 0:i())||void 0===e?void 0:e.getMediaSession()).getEstimatedLiveSeekableRange()}function D(){var e;return null===(e=l())||void 0===e?void 0:e.media.duration}function P(){var e;return null===(e=l())||void 0===e?void 0:e.playerState}function x(e){var t;return e?M(e):null===(t=l())||void 0===t?void 0:t.getEstimatedTime()}function M(e){const t=l();if(!t)return e;const n=new chrome.cast.media.SeekRequest;return n.currentTime=e,t.seek(n,console.debug,console.error),e}function R(){var e;return null===(e=l())||void 0===e?void 0:e.play(new chrome.cast.media.PlayRequest,console.debug,console.error)}function j(){var e;return null===(e=l())||void 0===e?void 0:e.pause(new chrome.cast.media.PauseRequest,console.debug,console.error)}var U=Object.freeze({__proto__:null,load:O,has_media:L,exists:I,device_name:function(){var e;return null===(e=i())||void 0===e?void 0:e.getCastDevice().friendlyName},seekable_ranges:N,duration:D,state:P,currentTime:x,seek:M,play:R,pause:j});class Sender{constructor(e){this.video=e}static of(e){return e.sender||(e.sender=new Sender(e)),e.sender}static maybe(e,t){e.sender&&t(e.sender,e)}static getEstimatedTime(){var e;return null===(e=l())||void 0===e?void 0:e.getEstimatedTime()}static load(e,t){O(e,t,console.debug,console.error)}static destroy(e){e.video=void 0}}var G=Object.freeze({__proto__:null,STABLE:"940D4BE4",CANARY:"6F71FA7C",LOCAL:"5258CA32"});const q="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1";function H(e,t,n){if(document.querySelector("script[src='"+q+"']"))return F(n);!function(){const e=document.createElement("script");e.async=!0,e.src=q,document.head.appendChild(e)}(),window.__onGCastApiAvailable=function(){!function(e,t,n){var r;if(!V())return;const o=(null===(r=e.chromecast)||void 0===r?void 0:r.app)||"940D4BE4",a=f();if(!a)return;a.setOptions({receiverApplicationId:o,autoJoinPolicy:chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED}),a.addEventListener(cast.framework.CastContextEventType.CAST_STATE_CHANGED,(function(e){E(n,"chromecast:state:changed",e)})),a.addEventListener(cast.framework.CastContextEventType.SESSION_STATE_CHANGED,(function(e){_(n),E(n,"chromecast:session:changed",e)}))}(e,0,n),F(n)}}function V(){return"object"==typeof window.cast&&"object"==typeof chrome.cast}function F(e){if(V())return E(e,"chromecast:available");E(e,"chromecast:unavailable")}function B(e,t){const n={play:function(){return new Promise(n=>u(e)?n(R()):L()?n(Sender.load(e,t)):(Sender.load(e,t),void n()))},pause:function(){return u(e)?j():HTMLMediaElement.prototype.pause.call(e)}};n.currentTime={get:x,set:x},n.seekable={get:()=>{const e=N();return{start:()=>(null==e?void 0:e.start)||0,end:()=>(null==e?void 0:e.end)||0,length:1}}},n.duration={get:D},n.paused={get:function(){return"PAUSED"===P()}},n.playing={get:function(){return"PLAYING"===P()}},Object.keys(n).forEach((function(t){if("object"==typeof n[t])return Object.defineProperty(e,t,{get:function(){var r,o;return u(e)?n[t].get():null===(o=null===(r=Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype,t))||void 0===r?void 0:r.get)||void 0===o?void 0:o.call(this)},set:function(r){var o,a;return u(e)?n[t].set(r):null===(a=null===(o=Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype,t))||void 0===o?void 0:o.set)||void 0===a?void 0:a.call(this,r)}});const r=e[t];e[t]=function(){const o=[].slice.apply(arguments);return I()?n[t].apply(e,o):r.apply(e,o)}}))}const Y=(e,t)=>new(((e,t)=>{const n=e.get(t);if(!n)throw new Error(`no flowplayer component with the name ${t} exists`);const r=window.customElements.get(t);if(!r)throw new Error(`no default flowplayer component with the name ${t} exists`);const o=window.customElements.get(n);return"function"!=typeof o?r:o})(e._customElements,t))(e);class FlowplayerComponent extends HTMLElement{constructor(e){super(),this.player=e}}class FlowplayerChromecastIcon extends FlowplayerComponent{constructor(e){super(e),this.classList.add("fp-cast-button"),this.setAttribute("tabindex","-1"),this.setAttribute("role","button"),this.setAttribute("aria-hidden","true"),this.cast_launcher=document.createElement("google-cast-launcher"),this.cast_launcher.setAttribute("inert","true"),this.append(this.cast_launcher),this.addEventListener("click",t=>{const n=i();if(n)return n.endSession(!0);e.emit("chromecast:start"),t.target===this&&this.cast_launcher.click()}),e.on("chromecast:state:changed",t=>{const n=t.detail.castState;n&&(this.setAttribute("tabindex",n===cast.framework.CastState.NO_DEVICES_AVAILABLE?"-1":"0"),this.setAttribute("aria-hidden",(n===cast.framework.CastState.NO_DEVICES_AVAILABLE)+""),this.setAttribute("aria-label",n===cast.framework.CastState.NOT_CONNECTED?e.i18n("chromecast.start","start casting"):e.i18n("chromecast.stop","stop casting")))})}}function z(e,t){const n=e._customElements.get(t);return n&&e.root.querySelector(n)||void 0}class ChromecastPlugin{constructor(e){var t,n,r;this.flowplayer=e,t=e,n="flowplayer-chromecast-icon",r=FlowplayerChromecastIcon,window.customElements.get(n)||window.customElements.define(n,r),t.customElements.get(n)||t.customElements.set(n,n)}init(e,t,n){if("https:"!==location.protocol&&"localhost"!==location.hostname&&"127.0.0.1"!==location.hostname)return console.warn("Secure URL required to enable Chromecast");H(e,0,this.flowplayer.instances);const r={pending:void 0};n.on("reap",(function(){Sender.maybe(n,Sender.destroy)})),n.on("mount",(function(){const t=z(n,"flowplayer-middle");t&&function(e,t){const n=document.createElement("div");n.className="fp-chromecast";const r=document.createElement("p");t.poster&&(n.style.backgroundImage=["url(",t.poster,")"].join("")),n.append(r),e.prepend(n)}(t,{poster:e.poster});const r=z(n,"flowplayer-header-right-zone");r&&r.prepend(Y(n,"flowplayer-chromecast-icon"))})),n.on("chromecast:available",()=>{n.setState("is-cast-available",!0),Sender.of(n),B(n,this.flowplayer.instances)}),n.on("chromecast:unavailable",(function(){n.setState("is-cast-available",!1),Sender.maybe(n,Sender.destroy)})),n.on("chromecast:start",()=>{if(this.flowplayer.instances.forEach(e=>{e.togglePlay(!1),e.currentSessionTime=e.hasState("is-ended")?0:e.currentTime}),L())return Sender.load(n,this.flowplayer.instances);r.pending=!0}),n.on("volumechange",()=>{const e=w.player,t=w.controller;if(!L()||!e||!t)return;const r=n.volume,o=n.muted;r!==e.volumeLevel&&(e.volumeLevel=r,t.setVolumeLevel()),o!==e.isMuted&&t.muteOrUnmute()}),n.on("tracks:text:updated",(function(e){var t;if(L())return e.data?void C((null===(t=l())||void 0===t?void 0:t.media.tracks.filter(e=>"TEXT"===e.type).filter(e=>{var t;return e.name===(null===(t=b(n).find(e=>e.is_active))||void 0===t?void 0:t.label)}).map(e=>e.trackId))||[]):C([])})),n.on("audio:update",()=>{L()&&setTimeout(()=>{var e,t,r;const o=null===(e=null==n?void 0:n.asel)||void 0===e?void 0:e.active_track,a=null===(r=null===(t=l())||void 0===t?void 0:t.media.tracks.filter(e=>"AUDIO"===e.type).find(e=>void 0!==e.name?e.name===(null==o?void 0:o.name):e.language===(null==o?void 0:o.lang)))||void 0===r?void 0:r.trackId;"number"==typeof a&&C([a])},0)}),n.on(o,()=>{this.reset_state(n);const e=n.opt("duration");"number"==typeof e&&Math.abs(e-n.currentSessionTime)<=1&&(n.currentSessionTime=0,n.setState("is-paused",!1),n.emit("ended"))}),n.on("chromecast:field:update",(function(e){if(!e.data)return;const{field:t,value:r}=e.data;switch(t){case g.MUTE:return n.muted=r;case g.VOLUME:return n.volume=r;case g.CURRENT_TIME:{Math.abs(r-n.currentSessionTime)>=1.5&&n.emit("seeked"),n.currentSessionTime=r,n.emit("timeupdate",r);const e=N();if(e){n.opts.live||n.setOpts({live:!0});const t=e.end,r=e.start;if("number"!=typeof r||"number"!=typeof t)return;n.emit("dvr/window",t-r)}return}case g.PLAYER_STATE:return"PLAYING"==r?n.emit("playing"):"PAUSED"==r?n.emit("pause"):void 0;case"videoInfo":var o=(r||{}).fake_session||U;return function(e,t){if(!e.root)return;const n=e.root.querySelector(".fp-chromecast p");if(!n)return;let r="";r=e.i18n("chromecast.message","{{state}} on {{device}}").replace("{{device}}",(null==t?void 0:t.device)||"chromecast"),r=r.replace("{{state}}",((null==t?void 0:t.state)||"").toLowerCase()),n.textContent=r}(n,{device:o.device_name(),state:o.state()}),o.hide_controls&&n.setState("no-chromecast-controls",!0),n.setState("is-starting",!1),n.hasState("is-loaded")||-1===n.duration||n.setOpts({duration:n.duration}),n.setState("is-chromecast-playing",!0)}})),n.on("chromecast:session:changed",e=>{if(e.data)switch(e.detail.sessionState){case cast.framework.SessionState.SESSION_ENDED:return n.emit("remotesession:ended",{currentTime:n.currentSessionTime}),n.setState("is-casting",!1),this.reset_state(n);case cast.framework.SessionState.SESSION_RESUMED:case cast.framework.SessionState.SESSION_STARTED:r.pending&&(r.pending=!1,Sender.load(n,this.flowplayer.instances),n.emit("remotesession:started"),n.setState("is-casting",!0))}})}reset_state(e){e.setState("is-chromecast-playing",!1),e.setState("is-playing",!1),e.setState("is-paused",!0),e.setState("is-starting",!0)}}ChromecastPlugin.apps=G,ChromecastPlugin.events=a;return function(e,t){if("object"==typeof exports&&"undefined"!=typeof module)return t;if(null===document.currentScript)return t;"flowplayer"in e||(e.flowplayer={extensions:[]});const n=e.flowplayer;return"function"==typeof n?(n(t),t):(Array.isArray(n.extensions)||(n.extensions=[]),~n.extensions.indexOf(t)||n.extensions.push(t),t)}(window,ChromecastPlugin)}));
|
|
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.chromecast=t())}(this,(function(){"use strict";function e(e){const t=document.createElement("a");t.href=e;const n=t.pathname&&t.pathname.split(".");return n.length>1&&n[n.length-1]}function t(e){switch(e){case"video/mpd":return"application/dash+xml";case"video/m3u8":return"application/x-mpegurl";default:return e}}const n=n=>{var{src:r}=n,o=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}(n,["src"]);return[Object.assign({src:r,type:r?t("video/"+e(r)):""},o)]};function r(e){return n({src:e})}class Pipe{constructor(e){this.data=e}static of(e){return new Pipe(e)}static maybe(e,t,...n){return null==e?e:t.apply(e,[e,...n])}tap(e,...t){return e.apply(this,[this.data,...t]),new Pipe(this.data)}fmap(e,...t){const n=e.apply(this,[this.data,...t]);return new Pipe(n)}unwrap(){return this.data}}const o="chromecast:idle";var a=Object.freeze({__proto__:null,CAST_AVAILABLE:"chromecast:available",CAST_UNAVAILABLE:"chromecast:unavailable",CAST_START_CASTING:"chromecast:start",CAST_IDLE:o,CAST_STATE_CHANGED:"chromecast:state:changed",CAST_SESSION_CHANGED:"chromecast:session:changed",CAST_FIELD_UPDATE:"chromecast:field:update",CAST_MEDIA_LOAD_REQUEST:"chromecast:media"});const i=/(video\/mp4)|(application\/x-mpegurl)|(video\/mpd)|(application\/dash\+xml)/;function s(){var e;return(null===(e=f())||void 0===e?void 0:e.getCurrentSession())||null}function c(e){return p(e).unwrap().shift()}function l(){var e;return(null===(e=s())||void 0===e?void 0:e.getMediaSession())||null}function u(e){var t,n;const r=p(e).unwrap().map((function(e){return null==e?void 0:e.src})),o=null===(n=null===(t=l())||void 0===t?void 0:t.media)||void 0===n?void 0:n.contentId;return!!o&&!!~r.indexOf(o)}function d(e){var t;return(null===(t=e.type)||void 0===t?void 0:t.match(i))||!1}function m(e,t){if(!t.opts.src)return e;const n=(Array.isArray(t.opts.src)?t.opts.src:[t.opts.src]).map(e=>"string"==typeof e?r(e)[0]:e);return e.map(e=>{const t=n.find(t=>t.src===e.src);return t&&t.drm?Object.assign(Object.assign({},e),{drm:t.drm}):e})}function p(e){return Pipe.of(e).fmap(()=>e.original_src||[]).fmap((function(e){return"string"==typeof e?r(e):e})).fmap(m,e).fmap((function(e){return e.filter(d)}))}function f(){var e,t,n;return null===(n=null===(t=null===(e=window.cast)||void 0===e?void 0:e.framework)||void 0===t?void 0:t.CastContext)||void 0===n?void 0:n.getInstance()}function v(e){return e.filter((function(e){return u(e)}))}function h(e){return e.filter((function(e){return!u(e)}))}function y(e,t,n){v(e).forEach((function(e){e.emit(t,n)}))}function S(e,t,n){h(e).forEach((function(e){e.emit(t,n)}))}function g(e,t,n){e.forEach((function(e){e.emit(t,n)}))}const w={player:void 0,controller:void 0,listener:void 0};function _(e){w.controller&&w.listener&&w.controller.removeEventListener(cast.framework.RemotePlayerEventType.ANY_CHANGE,w.listener),w.player=new cast.framework.RemotePlayer,w.controller=new cast.framework.RemotePlayerController(w.player),w.listener=E.bind(null,e),w.controller.addEventListener(cast.framework.RemotePlayerEventType.ANY_CHANGE,w.listener)}function E(e,t){if("IDLE"===t.value)return S(e,o);y(e,"chromecast:field:update",t)}function b(e){return Array.from(e.textTracks).filter(e=>["subtitles","captions"].includes(e.kind))}function T(e){return b(e).flatMap((t,n)=>{try{const r=e.querySelector("#"+t.id);if(!(r instanceof HTMLTrackElement&&r.lang))return[];const o=new chrome.cast.media.Track(n+1e3,chrome.cast.media.TrackType.TEXT);return o.trackContentType="text/vtt",o.subtype=chrome.cast.media.TextTrackType.SUBTITLES,o.trackContentId=r.src,o.name=r.label,o.language=r.lang,o}catch(e){return[]}})}function A(e){var t;const n=new chrome.cast.media.EditTracksInfoRequest(e);null===(t=l())||void 0===t||t.editTracksInfo(n,console.debug,console.error)}var C=Object.freeze({__proto__:null,getCurrentSession:s,getMedia:c,getMediaSession:l,isSame:u,is_supported_media:d,injectDRMConfiguration:m,normalizeSrc:p,getCastContext:f,casting_players:v,idle_players:h,broadcast_to_active:y,broadcast_to_idle:S,broadcast:g,SINGLETONS:w,refresh_singletons:_,onremotechange:E,tracks:b,cast_tracks:T,editTracks:A});const k="is-chromecast-playing";function O(e,t){const n=e.seekable;if("object"!=typeof e.opts||0==n.length)return{head:0,tail:0};const r=function(e){var t;const n=e.seekable;return n.length?e.hasState(k)||!(null===(t=e.hls)||void 0===t?void 0:t.liveSyncPosition)?n.end(n.length-1):e.hls.liveSyncPosition:0}(e),o=t||e.live_state.dvr_window;return{head:r,tail:"number"!=typeof o||r-o<0?n.start(0):r-o}}function L(e){const t=e.currentTime,n=O(e);return{progress:Math.min(100,Math.max(0,(t-n.tail)/(n.head-n.tail)*100)),is_live:t-n.head>=-10}}const I={player:void 0,listener:void 0};function x(e,t,n,r){var a,i,u,d,m;const p=s();if(!p)return;const f=c(e);if(!f||!f.src)return;const v=new chrome.cast.media.MediaInfo(f.src,f.type||"");v.metadata=new chrome.cast.media.GenericMediaMetadata,function(e){I.player&&I.listener&&I.player.off("playing",I.listener);const t={currentTime:e.currentSessionTime,liveState:e.live_state,progress:L(e).progress};I.player=e,I.listener=()=>{setTimeout(()=>{!function(e,t){const n=l();if(!n)return;if(-1!==n.media.duration)return e.currentTime=t.currentTime;const r=n.liveSeekableRange;if(!r||"number"!=typeof r.end||"number"!=typeof r.start)return;if(void 0===t.liveState.dvr_window||!t.liveState.dvr)return;e.currentTime=(r.end-r.start)*(t.progress/100)}(e,t)},1e3)},e.once("playing",I.listener)}(e);const h={health:e.health,text_tracks:T(e),active_tracks:{active_audio:(null===(i=null===(a=null==e?void 0:e.asel)||void 0===a?void 0:a.active_track)||void 0===i?void 0:i.name)||(null===(d=null===(u=null==e?void 0:e.asel)||void 0===u?void 0:u.active_track)||void 0===d?void 0:d.lang),active_text:null===(m=b(e).find(e=>e.is_active))||void 0===m?void 0:m.label}};f.drm&&(h.drm=f.drm),localStorage.__fpChromecastDebug&&(h.debug=!0),e.opt("ads")&&(h.ads=e.opt("ads")),v.customData=h;const y=new chrome.cast.media.LoadRequest(v);y.customData=e.opt("chromecast",{}),y.customData.metadata=e.opt("metadata"),e.emit("chromecast:media",{request:y}),console.debug("cast:request(%o)",y),p.loadMedia(y).then(()=>{e.emit("remotesession:started"),e.setState("has-casted",!0),e.setState("is-casting",!0),_(t);const n=w.player;n&&(e.volume=n.volumeLevel,e.muted=n.isMuted),S(t,o)},r)}function P(){return!!l()}function D(){return!!s()}function N(){var e;return(null===(e=null==C?void 0:s())||void 0===e?void 0:e.getMediaSession()).getEstimatedLiveSeekableRange()}function M(){var e;return null===(e=l())||void 0===e?void 0:e.media.duration}function j(){var e;return null===(e=l())||void 0===e?void 0:e.playerState}function R(e){var t;return e?G(e):null===(t=l())||void 0===t?void 0:t.getEstimatedTime()}function G(e){const t=l();if(!t)return e;const n=new chrome.cast.media.SeekRequest;return n.currentTime=e,t.seek(n,console.debug,console.error),e}function q(){var e;return null===(e=l())||void 0===e?void 0:e.play(new chrome.cast.media.PlayRequest,console.debug,console.error)}function H(){var e;return null===(e=l())||void 0===e?void 0:e.pause(new chrome.cast.media.PauseRequest,console.debug,console.error)}var U=Object.freeze({__proto__:null,load:x,has_media:P,exists:D,device_name:function(){var e;return null===(e=s())||void 0===e?void 0:e.getCastDevice().friendlyName},seekable_ranges:N,duration:M,state:j,currentTime:R,seek:G,play:q,pause:H});class Sender{constructor(e){this.video=e}static of(e){return e.sender||(e.sender=new Sender(e)),e.sender}static maybe(e,t){e.sender&&t(e.sender,e)}static getEstimatedTime(){var e;return null===(e=l())||void 0===e?void 0:e.getEstimatedTime()}static load(e,t){x(e,t,console.debug,console.error)}static destroy(e){e.video=void 0}}var B=Object.freeze({__proto__:null,STABLE:"940D4BE4",CANARY:"6F71FA7C",LOCAL:"5258CA32"});const F="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1";function V(e,t,n){if(document.querySelector("script[src='"+F+"']"))return Y(n);!function(){const e=document.createElement("script");e.async=!0,e.src=F,document.head.appendChild(e)}(),window.__onGCastApiAvailable=function(){!function(e,t,n){var r;if(!z())return;const o=(null===(r=e.chromecast)||void 0===r?void 0:r.app)||"940D4BE4",a=f();if(!a)return;a.setOptions({receiverApplicationId:o,autoJoinPolicy:chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED}),a.addEventListener(cast.framework.CastContextEventType.CAST_STATE_CHANGED,(function(e){g(n,"chromecast:state:changed",e)})),a.addEventListener(cast.framework.CastContextEventType.SESSION_STATE_CHANGED,(function(e){_(n),g(n,"chromecast:session:changed",e)}))}(e,0,n),Y(n)}}function z(){return"object"==typeof window.cast&&"object"==typeof chrome.cast}function Y(e){if(z())return g(e,"chromecast:available");g(e,"chromecast:unavailable")}function J(e,t){const n={play:function(){return new Promise(n=>u(e)?n(q()):P()?n(Sender.load(e,t)):(Sender.load(e,t),void n()))},pause:function(){return u(e)?H():HTMLMediaElement.prototype.pause.call(e)}};n.currentTime={get:R,set:R},n.seekable={get:()=>{const e=N();return{start:()=>(null==e?void 0:e.start)||0,end:()=>(null==e?void 0:e.end)||0,length:1}}},n.duration={get:M},n.paused={get:function(){return"PAUSED"===j()}},n.playing={get:function(){return"PLAYING"===j()}},Object.keys(n).forEach((function(t){if("object"==typeof n[t])return Object.defineProperty(e,t,{get:function(){var r,o;return u(e)?n[t].get():null===(o=null===(r=Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype,t))||void 0===r?void 0:r.get)||void 0===o?void 0:o.call(this)},set:function(r){var o,a;return u(e)?n[t].set(r):null===(a=null===(o=Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype,t))||void 0===o?void 0:o.set)||void 0===a?void 0:a.call(this,r)}});const r=e[t];e[t]=function(){const o=[].slice.apply(arguments);return D()?n[t].apply(e,o):r.apply(e,o)}}))}const X="currentTime",$="duration",Q="playerState",K="videoInfo",W="volumeLevel",Z="isMuted",ee="liveSeekableRange",te=(e,t)=>new(((e,t)=>{const n=e.get(t);if(!n)throw new Error(`no flowplayer component with the name ${t} exists`);const r=window.customElements.get(t);if(!r)throw new Error(`no default flowplayer component with the name ${t} exists`);const o=window.customElements.get(n);return"function"!=typeof o?r:o})(e._customElements,t))(e);class FlowplayerComponent extends HTMLElement{constructor(e){super(),this.player=e}}class FlowplayerChromecastIcon extends FlowplayerComponent{constructor(e){super(e),this.classList.add("fp-cast-button"),this.setAttribute("tabindex","-1"),this.setAttribute("role","button"),this.setAttribute("aria-hidden","true"),this.cast_launcher=document.createElement("google-cast-launcher"),this.cast_launcher.setAttribute("inert","true"),this.append(this.cast_launcher),this.addEventListener("click",t=>{const n=s();if(n)return n.endSession(!0);e.emit("chromecast:start"),t.target===this&&this.cast_launcher.click()}),e.on("chromecast:state:changed",t=>{const n=t.detail.castState;n&&(this.setAttribute("tabindex",n===cast.framework.CastState.NO_DEVICES_AVAILABLE?"-1":"0"),this.setAttribute("aria-hidden",(n===cast.framework.CastState.NO_DEVICES_AVAILABLE)+""),this.setAttribute("aria-label",n===cast.framework.CastState.NOT_CONNECTED?e.i18n("chromecast.start","start casting"):e.i18n("chromecast.stop","stop casting")))})}}function ne(e,t){const n=e._customElements.get(t);return n&&e.root.querySelector(n)||void 0}class ChromecastPlugin{constructor(e){var t,n,r;this.flowplayer=e,t=e,n="flowplayer-chromecast-icon",r=FlowplayerChromecastIcon,window.customElements.get(n)||window.customElements.define(n,r),t.customElements.get(n)||t.customElements.set(n,n)}init(e,t,n){if("https:"!==location.protocol&&"localhost"!==location.hostname&&"127.0.0.1"!==location.hostname)return console.warn("Secure URL required to enable Chromecast");V(e,0,this.flowplayer.instances);const r={pending:void 0};n.on("reap",(function(){Sender.maybe(n,Sender.destroy)})),n.on("mount",(function(){const t=ne(n,"flowplayer-middle");t&&function(e,t){const n=document.createElement("div");n.className="fp-chromecast";const r=document.createElement("p");t.poster&&(n.style.backgroundImage=["url(",t.poster,")"].join("")),n.append(r),e.prepend(n)}(t,{poster:e.poster});const r=ne(n,"flowplayer-header-right-zone");r&&r.prepend(te(n,"flowplayer-chromecast-icon"))})),n.on("chromecast:available",()=>{n.setState("is-cast-available",!0),Sender.of(n),J(n,this.flowplayer.instances)}),n.on("chromecast:unavailable",(function(){n.setState("is-cast-available",!1),Sender.maybe(n,Sender.destroy)})),n.on("chromecast:start",()=>{if(this.flowplayer.instances.forEach(e=>{e.togglePlay(!1),e.currentSessionTime=e.hasState("is-ended")?0:e.currentTime}),P())return Sender.load(n,this.flowplayer.instances);r.pending=!0}),n.on("volumechange",()=>{const e=w.player,t=w.controller;if(!P()||!e||!t)return;const r=n.volume,o=n.muted;r!==e.volumeLevel&&(e.volumeLevel=r,t.setVolumeLevel()),o!==e.isMuted&&t.muteOrUnmute()}),n.on("tracks:text:updated",(function(e){var t;if(P())return e.data?void A((null===(t=l())||void 0===t?void 0:t.media.tracks.filter(e=>"TEXT"===e.type).filter(e=>{var t;return e.name===(null===(t=b(n).find(e=>e.is_active))||void 0===t?void 0:t.label)}).map(e=>e.trackId))||[]):A([])})),n.on("audio:update",()=>{P()&&setTimeout(()=>{var e,t,r;const o=null===(e=null==n?void 0:n.asel)||void 0===e?void 0:e.active_track,a=null===(r=null===(t=l())||void 0===t?void 0:t.media.tracks.filter(e=>"AUDIO"===e.type).find(e=>void 0!==e.name?e.name===(null==o?void 0:o.name):e.language===(null==o?void 0:o.lang)))||void 0===r?void 0:r.trackId;"number"==typeof a&&A([a])},0)}),n.on(o,()=>{if(n.setState("is-starting",!0),!n.hasState("is-casting"))return;const e=n.opt("duration");"number"==typeof e&&Math.abs(e-n.currentSessionTime)<=1&&(n.currentSessionTime=0,n.setState("is-paused",!1),n.emit("ended")),n.emit("remotesession:ended",{currentTime:n.currentSessionTime}),this.reset_state(n)}),n.on("chromecast:field:update",(function(e){if(!e.data)return;const{field:t,value:r}=e.data;switch(t){case $:return void(-1!==r||n.opts.live||n.setOpts({live:!0}));case Z:return n.muted=r;case W:return n.volume=r;case ee:return n.emit("dvr/window",r.end-r.start);case X:return Math.abs(r-n.currentSessionTime)>=1.5&&n.emit("seeked"),n.currentSessionTime=r,n.emit("timeupdate",r);case Q:return"PLAYING"==r?n.emit("playing"):"PAUSED"==r?n.emit("pause"):void 0;case K:var o=(r||{}).fake_session||U;return function(e,t){if(!e.root)return;const n=e.root.querySelector(".fp-chromecast p");if(!n)return;let r="";r=e.i18n("chromecast.message","{{state}} on {{device}}").replace("{{device}}",(null==t?void 0:t.device)||"chromecast"),r=r.replace("{{state}}",((null==t?void 0:t.state)||"").toLowerCase()),n.textContent=r}(n,{device:o.device_name(),state:o.state()}),o.hide_controls&&n.setState("no-chromecast-controls",!0),n.setState("is-starting",!1),n.hasState("is-loaded")||-1===n.duration||n.setOpts({duration:n.duration}),n.setState(k,!0)}})),n.on("chromecast:session:changed",e=>{if(e.data)switch(e.detail.sessionState){case cast.framework.SessionState.SESSION_ENDED:if(!n.hasState("is-casting"))return;return n.emit("remotesession:ended",{currentTime:n.currentSessionTime}),this.reset_state(n);case cast.framework.SessionState.SESSION_RESUMED:case cast.framework.SessionState.SESSION_STARTED:r.pending&&(r.pending=!1,Sender.load(n,this.flowplayer.instances))}})}reset_state(e){e.setState(k,!1),e.setState("is-casting",!1),e.setState("is-playing",!1),e.setState("is-paused",!0),e.setState("is-starting",!0)}}ChromecastPlugin.apps=B,ChromecastPlugin.events=a;return function(e,t){if("object"==typeof exports&&"undefined"!=typeof module)return t;if(null===document.currentScript)return t;"flowplayer"in e||(e.flowplayer={extensions:[]});const n=e.flowplayer;return"function"==typeof n?(n(t),t):(Array.isArray(n.extensions)||(n.extensions=[]),~n.extensions.indexOf(t)||n.extensions.push(t),t)}(window,ChromecastPlugin)}));
|
package/plugins/health.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.health=e())}(this,(function(){"use strict";const t="rebuffer",e="rebuffer:ended",i="insights:ttff",n="insights:time_to_first_frag_loaded",s="insights:watched_interval";var a=Object.freeze({__proto__:null,RECORD:"health:record",REBUFFER:t,REBUFFER_ENDED:e,DISPLAY:"display",TIME_TO_FIRST_FRAME:i,TIME_TO_FIRST_FRAGMENT_LOADED:n,WATCHED_INTERVAL:s});const r="fullscreenenter",o="fullscreenexit",d="loadedmetadata",c="loadeddata",l="progress",h="loadstart",u="pause",_="playing",m="waiting",p="canplay",f="ended",y="seeked",g="seeking",v="content:loadstart",E=[v,"error","src"];function T(t){try{return!!new URL(t)}catch(t){return!1}}function S(t,e){const i=function(){try{return localStorage.getItem("flowplayer/debug")}catch(t){return""}}(),n=(n,...s)=>{try{const a=(null==e?void 0:e.debug)||i;a&&t.match(a)&&console.log(`flowplayer/${t} -- ${n}`,...s)}catch(t){console.warn(t)}};return n.log=n,n}const w=navigator;function R(t){var e,i;const n=null===(e=t.hls)||void 0===e?void 0:e.bandwidthEstimate;return n?1e-6*n:(null===(i=w.connection)||void 0===i?void 0:i.downlink)||-1}function A(t,e){return async function(t,e){try{await fetch(t,{body:e,method:"POST",mode:"no-cors"})}catch(t){}}(t,JSON.stringify({events:e}))}var I;!function(t){t[t.OFF=0]="OFF",t[t.ON=1]="ON",t[t.AUDIO_REQUIRED=2]="AUDIO_REQUIRED"}(I||(I={}));const W=t=>{switch(t){case!0:return I.ON;case!1:return I.OFF;default:return t}};function O(){try{const t=window.location!==window.parent.location?document.referrer:document.location.href;return"string"==typeof t&&t.slice(0,200)}catch(t){return!1}}const D=[],N="https://ihi.flowplayer.com/v1/health/events";function M(t){if(t.suspended)return;const e=D.slice(0);D.length=0,0!=e.length&&(t.logger.log(`:dispatch events={${e.length}}`),A(function(){try{return"undefined"==typeof window?N:window.__FLOWPLAYER_INSIGHTS_URL?window.__FLOWPLAYER_INSIGHTS_URL:N}catch(t){return N}}(),e))}async function b(t,e,i){const n=await C();D.push(Object.assign(e,n)),t.logger.log(":enqueue",e.event,e),D.length<10&&!i||M(t)}const U=()=>{var t,e;try{const i=window;return null===(e=null===(t=null==i?void 0:i.google)||void 0===t?void 0:t.ima)||void 0===e?void 0:e.VERSION}catch(t){return}},C=async()=>({client_time:Date.now()}),F=(t,e)=>Object.assign(t,{detail:e}),L=(t,{event:e,media_session_id:i,session_id:n,play_range_id:s})=>({event:e,media_session_id:i,session_id:n,play_range_id:s,device_id:t.deviceId(),version:"3.17.0-rc.1",commit:"f7c4c74c2d28d3951aa492db119fb2c84eea83c2",ima_sdk_version:U(),preload:t.opt("preload"),autoplay:W(t.opt("autoplay")),live:t.opt("live"),dvr:!!t.live_state.dvr,source:t.original_src,downlink_mbs:R(t),page_url:O(),player_id:t.opt("metadata.player_id"),media_id:t.opt("metadata.media_id"),site_id:t.opt("metadata.site_id"),category_id:t.opt("metadata.category_id"),sitegroup_id:t.opt("metadata.sitegroup_id"),token:t.token,plugins:t.plugins.map(t=>t.constructor.name).sort((t,e)=>t.localeCompare(e)),current_time:t.currentTime,external_media_id:t.opt("external_media_id")}),k=t=>({bitrate:null==t?void 0:t.bitrate,resolution:null==t?void 0:t.attrs.RESOLUTION,frame_rate:null==t?void 0:t.attrs["FRAME-RATE"]});function P(t,e,i,n){const s=L(e,t.eventInfo(i)),{before:a,after:r}=n;b(t,((t,e,i)=>Object.assign(t,{state:{before:e,after:i}}))(s,k(a),k(r)))}const x=[1e7]+""+-1e3+-4e3+-8e3+-1e11,B=()=>"undefined"==typeof crypto?"":x.replace(/[018]/g,t=>(t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16));var H;function G(t){switch(t){case H.MEDIA_PLAYBACK_ABORTED:return"media playback was aborted";case H.MEDIA_ERR_NETWORK:return"a network error occurred";case H.MEDIA_ERR_DECODE:return"unable to decode media content";case H.MEDIA_ERR_SRC_NOT_SUPPORTED:return"unsupported media type";case H.NO_INTERNET:return"no internet connection detected";case H.MIXED_CONTENT:return"cannot load insecure content in a secure context";default:return"an unknown error occurred"}}!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.MEDIA_PLAYBACK_ABORTED=1]="MEDIA_PLAYBACK_ABORTED",t[t.MEDIA_ERR_NETWORK=2]="MEDIA_ERR_NETWORK",t[t.MEDIA_ERR_DECODE=3]="MEDIA_ERR_DECODE",t[t.MEDIA_ERR_SRC_NOT_SUPPORTED=4]="MEDIA_ERR_SRC_NOT_SUPPORTED",t[t.MIXED_CONTENT=1001]="MIXED_CONTENT",t[t.NO_INTERNET=1002]="NO_INTERNET"}(H||(H={}));const j=(t,e)=>{let i=null;return(...n)=>{null!==i&&(clearTimeout(i),i=null),i=setTimeout(()=>e(...n),t)}};var K;!function(t){t[t.Starting=0]="Starting",t[t.ConfigFinalized=1]="ConfigFinalized",t[t.TimerStartedWithAdsAutoplay=2]="TimerStartedWithAdsAutoplay",t[t.TimerStartedWithContentAutoplay=3]="TimerStartedWithContentAutoplay",t[t.TimerStartedWithUserGesture=4]="TimerStartedWithUserGesture",t[t.MetricReported=5]="MetricReported"}(K||(K={}));class TimeToFirstFrame{constructor(t=K.Starting,e=!1,i=!1){this.state=t,this.loadedAd=e,this.requiresUserGesture=i}reset(){this.state=K.Starting,this.loadedAd=!1,this.elapsed=void 0}toJSON(){var t;return{ad_was_requested:this.loadedAd,ms_to_first_frame:Math.round((null===(t=this.elapsed)||void 0===t?void 0:t.duration)||-1)}}startTimer(t){this.state==K.ConfigFinalized&&(this.state=t,performance.mark("ttff:start"))}hasStarted(){return[K.TimerStartedWithAdsAutoplay,K.TimerStartedWithContentAutoplay,K.TimerStartedWithUserGesture].includes(this.state)}stopTimer(t){if(this.hasStarted()){performance.mark("ttff:end");const e=this.elapsed=performance.measure("ttff","ttff:start","ttff:end");this.state=K.MetricReported,t(e)}}}function z(t){return Math.round(1e3*t)/1e3}class EWMA{constructor(t){this.tickInterval=t,this.ewma=0,this.startTime=Date.now()}decay(){const t=Date.now()-this.startTime;return Math.pow(2,-t/(4*this.tickInterval))}update(t){const e=this.decay();return this.ewma=e*this.ewma+(1-e)*t,this.ewma}toJSON(){return this.ewma}}class WatchedState{constructor(t){this.player=t,this.marchingInterval=void 0,this.lastWatchedPoint=void 0,this.watchedSum=0,this.lastReportedSum=0,this.ewmaTickWatched=new EWMA(WatchedState.AccuracyMilliseconds)}reset(){this.onNotWatching(),this.watchedSum=0,this.lastReportedSum=0,this.lastWatchedPoint=void 0}onNotWatching(){this.marchingInterval&&(this.updateWatched(),this.marchingInterval=clearInterval(this.marchingInterval))}onWatching(){this.marchingInterval||(this.lastWatchedPoint=this.createWatchedPoint(),this.marchingInterval=setInterval(()=>{this.updateWatched()},WatchedState.AccuracyMilliseconds))}createWatchedPoint(){return{currentTime:this.player.currentTime,paused:this.player.paused}}updateWatched(){const t=this.createWatchedPoint();this.lastWatchedPoint&&this.calculateTimeWatched(this.lastWatchedPoint,t),this.lastWatchedPoint=t}calculateTimeWatched(t,e){const i=e.currentTime-t.currentTime,n=this.ewmaTickWatched.update(i);if(!(i<0)&&!(1e3*i>1.3*WatchedState.AccuracyMilliseconds)&&(this.watchedSum+=i,this.watchedSum!=this.lastReportedSum&&(this.watchedSum>this.lastReportedSum+WatchedState.ReportingIntervalSeconds||this.player.ended))){const t=z(n),e={total_watched_seconds:z(this.watchedSum),tick_watched_seconds:t,batch_watched_seconds:z(this.watchedSum-this.lastReportedSum)};this.lastReportedSum=this.watchedSum,this.player.emit(s,e)}}}WatchedState.ReportingIntervalSeconds=5,WatchedState.AccuracyMilliseconds=160;const q=B();class Health{constructor(t,e){let i;this.session_id=q,this.suspended=!1,this.logger=S("health",e.opts),this.media_session_id=B(),this.play_range_id=B(),this.analyticsLoop=setInterval(()=>M(this),2e3),e.on("reap",()=>clearInterval(this.analyticsLoop)),e.on(_,()=>{i!==this.media_session_id&&(i=this.media_session_id,this.first_playing_event_timestamp=Date.now()),this.play_range_id=B()});let n=Date.now()-1e3;e.on("timeupdate",t=>{if(i!==this.media_session_id)return;const s=Date.now();if(s<n)return;n=Date.now()+5e3;const a=L(e,this.eventInfo(t.type)),r=F(a,{duration:(o=e.duration,Number.isFinite(o)?o:o===1/0?-1:void 0)});var o;this.first_playing_event_timestamp&&(Object.assign(r,{ms_since_first_playing:s-this.first_playing_event_timestamp}),this.first_playing_event_timestamp=void 0),b(this,r)});const s=this;if(e.health={get media_session_id(){return s.media_session_id},set media_session_id(t){s.media_session_id=t},get session_id(){return s.session_id},set session_id(t){s.session_id=t},toggle(t){t?s.resume():s.suspend()}},!Health._UNLOAD_SUBSCRIBED){Health._UNLOAD_SUBSCRIBED=!0;const e=e=>t.instances.forEach(t=>t.emit(e.type));document.addEventListener("visibilitychange",t=>{"hidden"==document.visibilityState&&e(t)}),window.addEventListener("pagehide",e)}}eventInfo(t){return{event:t,media_session_id:this.media_session_id,session_id:this.session_id,play_range_id:this.play_range_id}}suspend(){this.suspended=!0,clearInterval(this.analyticsLoop)}resume(){this.suspended=!1,this.analyticsLoop=setInterval(()=>M(this),2e3)}init(a,S,w){if(O().toString().startsWith("data:"))return this.suspend();!function(i){let n=null;const s=()=>{n=null};i.on(m,(function(e){i.seeking||i.networkState===i.NETWORK_LOADING&&(i.readyState<HTMLMediaElement.HAVE_CURRENT_DATA||i.emit(t))})),i.on(t,t=>{n=t}),i.on(p,t=>{if(n){const a=t.timeStamp-n.timeStamp;if(s(),a<31)return;if(a>3e5)return;i.emit(e,{rebuffer_duration:a/1e3})}}),E.forEach(t=>i.on(t,s))}(w),function(t){let e;[p,v].forEach(i=>{t.on(i,i=>{const s=Date.now();switch(i.type){case v:return e=s;case p:if(e)return t.emit(n,{ms_since_loading_started:s-e}),e=null}})})}(w),function(t){if(void 0===window.performance)return;const e=new TimeToFirstFrame;t.on("ovp:config:finalized",t=>{e.reset(),e.state=K.ConfigFinalized,e.requiresUserGesture=!t.detail.autoplay}),t.on(v,()=>{t.root.classList.contains("ad-hide-first-frame")&&e.startTimer(K.TimerStartedWithAdsAutoplay),t.opt("autoplay")&&e.startTimer(K.TimerStartedWithContentAutoplay)}),t.on("click",()=>{t.opt("autoplay")||e.startTimer(K.TimerStartedWithUserGesture)}),t.on("ad-requested",()=>{e.loadedAd=!0}),t.on("timeupdate",()=>{if(!(t.readyState<HTMLMediaElement.HAVE_CURRENT_DATA))switch(e.state){case K.TimerStartedWithContentAutoplay:case K.TimerStartedWithUserGesture:return e.stopTimer(()=>t.emit(i,e.toJSON()))}}),t.on("ad-started",()=>{switch(e.state){case K.TimerStartedWithAdsAutoplay:case K.TimerStartedWithUserGesture:return e.stopTimer(()=>t.emit(i,e.toJSON()))}})}(w),function(t){const e=new WatchedState(t);t.on(v,()=>e.reset()),t.on(_,()=>e.onWatching()),t.on(u,()=>e.onNotWatching()),t.on(g,()=>e.onNotWatching()),t.on(f,()=>e.updateWatched()),t.on("visibilitychange",()=>e.updateWatched())}(w),w.on("display",t=>{b(this,L(w,this.eventInfo(t.type)),!0)}),w.on("health:record",({detail:t})=>{const e=L(w,this.eventInfo(t.event));Object.assign(e,t.detail||{}),b(this,e)}),[h,d,c,l,m,t].forEach(t=>{w.on(t,t=>{b(this,L(w,this.eventInfo(t.type)))})}),[e,i,n,s].forEach(t=>{w.on(t,t=>{const e=L(w,this.eventInfo(t.type));b(this,Object.assign(e,t.detail))})}),[_,u,g,y,f,r,o,p,v].forEach(t=>{w.on(t,t=>{b(this,L(w,this.eventInfo(t.type)))})}),w.on("volumechange",j(800,t=>{const e=L(w,this.eventInfo(t.type));b(this,F(e,{volume:parseFloat(w.volume.toFixed(2)),muted:w.muted}))})),w.on("resize",j(800,t=>{const e=L(w,this.eventInfo(t.type));b(this,F(e,{height:S.clientHeight,width:S.clientWidth}))})),w.on("hls/failover",t=>{const e=L(w,this.eventInfo(t.type)),i=t.detail,{reason:n,from:s}=i;b(this,F(e,{reason:n,from:s}))}),w.on("qualitychange",({type:t,detail:e})=>{switch(e.kind){case"hls":return P(this,w,t,e)}}),w.addEventListener("error",t=>{const e=L(w,this.eventInfo(t.type)),i=t.error||w.error;if(!i)return b(this,e,!0);const n=i.code,s={error_message:i.message||G(n),error_code:n,error_stack:i.stack||""};return b(this,F(e,s),!0)}),w.on("src",t=>{var e;const i=null===(e=t.detail)||void 0===e?void 0:e.src;if("string"!=typeof i)return;if(!T(w.original_src))return;if(!T(i))return;if(i==w.original_src)return;this.media_session_id=B();b(this,L(w,this.eventInfo(t.type))),M(this)}),w.on("visibilitychange",t=>{b(this,L(w,this.eventInfo(t.type))),M(this)})}}return Health.events=a,Health._UNLOAD_SUBSCRIBED=!1,function(t,e){if("object"==typeof exports&&"undefined"!=typeof module)return e;if(null===document.currentScript)return e;"flowplayer"in t||(t.flowplayer={extensions:[]});const i=t.flowplayer;return"function"==typeof i?(i(e),e):(Array.isArray(i.extensions)||(i.extensions=[]),~i.extensions.indexOf(e)||i.extensions.push(e),e)}(window,Health)}));
|
|
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.health=e())}(this,(function(){"use strict";const t="rebuffer",e="rebuffer:ended",i="insights:ttff",n="insights:time_to_first_frag_loaded",s="insights:watched_interval";var a=Object.freeze({__proto__:null,RECORD:"health:record",REBUFFER:t,REBUFFER_ENDED:e,DISPLAY:"display",TIME_TO_FIRST_FRAME:i,TIME_TO_FIRST_FRAGMENT_LOADED:n,WATCHED_INTERVAL:s});const r="fullscreenenter",o="fullscreenexit",d="loadedmetadata",c="loadeddata",l="progress",h="loadstart",u="pause",_="playing",m="waiting",p="canplay",f="ended",y="seeked",g="seeking",v="content:loadstart",E=[v,"error","src"];function T(t){try{return!!new URL(t)}catch(t){return!1}}function S(t,e){const i=function(){try{return localStorage.getItem("flowplayer/debug")}catch(t){return""}}(),n=(n,...s)=>{try{const a=(null==e?void 0:e.debug)||i;a&&t.match(a)&&console.log(`flowplayer/${t} -- ${n}`,...s)}catch(t){console.warn(t)}};return n.log=n,n}const w=navigator;function R(t){var e,i;const n=null===(e=t.hls)||void 0===e?void 0:e.bandwidthEstimate;return n?1e-6*n:(null===(i=w.connection)||void 0===i?void 0:i.downlink)||-1}function A(t,e){return async function(t,e){try{await fetch(t,{body:e,method:"POST",mode:"no-cors"})}catch(t){}}(t,JSON.stringify({events:e}))}var I;!function(t){t[t.OFF=0]="OFF",t[t.ON=1]="ON",t[t.AUDIO_REQUIRED=2]="AUDIO_REQUIRED"}(I||(I={}));const W=t=>{switch(t){case!0:return I.ON;case!1:return I.OFF;default:return t}};function O(){try{const t=window.location!==window.parent.location?document.referrer:document.location.href;return"string"==typeof t&&t.slice(0,200)}catch(t){return!1}}const D=[],N="https://ihi.flowplayer.com/v1/health/events";function b(t){if(t.suspended)return;const e=D.slice(0);D.length=0,0!=e.length&&(t.logger.log(`:dispatch events={${e.length}}`),A(function(){try{return"undefined"==typeof window?N:window.__FLOWPLAYER_INSIGHTS_URL?window.__FLOWPLAYER_INSIGHTS_URL:N}catch(t){return N}}(),e))}async function M(t,e,i){const n=await C();D.push(Object.assign(e,n)),t.logger.log(":enqueue",e.event,e),D.length<10&&!i||b(t)}const U=()=>{var t,e;try{const i=window;return null===(e=null===(t=null==i?void 0:i.google)||void 0===t?void 0:t.ima)||void 0===e?void 0:e.VERSION}catch(t){return}},C=async()=>({client_time:Date.now()}),F=(t,e)=>Object.assign(t,{detail:e}),L=(t,{event:e,media_session_id:i,session_id:n,play_range_id:s})=>({event:e,media_session_id:i,session_id:n,play_range_id:s,device_id:t.deviceId(),version:"3.17.0",commit:"166bb5cdc210ddfabb6e8b6f3a1c02cb3eceaa2c",ima_sdk_version:U(),preload:t.opt("preload"),autoplay:W(t.opt("autoplay")),live:t.opt("live"),dvr:!!t.live_state.dvr,source:t.original_src,downlink_mbs:R(t),page_url:O(),player_id:t.opt("metadata.player_id"),media_id:t.opt("metadata.media_id"),site_id:t.opt("metadata.site_id"),category_id:t.opt("metadata.category_id"),sitegroup_id:t.opt("metadata.sitegroup_id"),token:t.token,plugins:t.plugins.map(t=>t.constructor.name).sort((t,e)=>t.localeCompare(e)),current_time:t.currentTime,external_media_id:t.opt("external_media_id")}),k=t=>({bitrate:null==t?void 0:t.bitrate,resolution:null==t?void 0:t.attrs.RESOLUTION,frame_rate:null==t?void 0:t.attrs["FRAME-RATE"]});function P(t,e,i,n){const s=L(e,t.eventInfo(i)),{before:a,after:r}=n;M(t,((t,e,i)=>Object.assign(t,{state:{before:e,after:i}}))(s,k(a),k(r)))}const x=[1e7]+""+-1e3+-4e3+-8e3+-1e11,B=()=>"undefined"==typeof crypto?"":x.replace(/[018]/g,t=>(t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16));var H;function G(t){switch(t){case H.MEDIA_PLAYBACK_ABORTED:return"media playback was aborted";case H.MEDIA_ERR_NETWORK:return"a network error occurred";case H.MEDIA_ERR_DECODE:return"unable to decode media content";case H.MEDIA_ERR_SRC_NOT_SUPPORTED:return"unsupported media type";case H.NO_INTERNET:return"no internet connection detected";case H.MIXED_CONTENT:return"cannot load insecure content in a secure context";default:return"an unknown error occurred"}}!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.MEDIA_PLAYBACK_ABORTED=1]="MEDIA_PLAYBACK_ABORTED",t[t.MEDIA_ERR_NETWORK=2]="MEDIA_ERR_NETWORK",t[t.MEDIA_ERR_DECODE=3]="MEDIA_ERR_DECODE",t[t.MEDIA_ERR_SRC_NOT_SUPPORTED=4]="MEDIA_ERR_SRC_NOT_SUPPORTED",t[t.MIXED_CONTENT=1001]="MIXED_CONTENT",t[t.NO_INTERNET=1002]="NO_INTERNET"}(H||(H={}));const j=(t,e)=>{let i=null;return(...n)=>{null!==i&&(clearTimeout(i),i=null),i=setTimeout(()=>e(...n),t)}};var K;!function(t){t[t.Starting=0]="Starting",t[t.ConfigFinalized=1]="ConfigFinalized",t[t.TimerStartedWithAdsAutoplay=2]="TimerStartedWithAdsAutoplay",t[t.TimerStartedWithContentAutoplay=3]="TimerStartedWithContentAutoplay",t[t.TimerStartedWithUserGesture=4]="TimerStartedWithUserGesture",t[t.MetricReported=5]="MetricReported"}(K||(K={}));class TimeToFirstFrame{constructor(t=K.Starting,e=!1,i=!1){this.state=t,this.loadedAd=e,this.requiresUserGesture=i}reset(){this.state=K.Starting,this.loadedAd=!1,this.elapsed=void 0}toJSON(){var t;return{ad_was_requested:this.loadedAd,ms_to_first_frame:Math.round((null===(t=this.elapsed)||void 0===t?void 0:t.duration)||-1)}}startTimer(t){this.state==K.ConfigFinalized&&(this.state=t,performance.mark("ttff:start"))}hasStarted(){return[K.TimerStartedWithAdsAutoplay,K.TimerStartedWithContentAutoplay,K.TimerStartedWithUserGesture].includes(this.state)}stopTimer(t){if(this.hasStarted()){performance.mark("ttff:end");const e=this.elapsed=performance.measure("ttff","ttff:start","ttff:end");this.state=K.MetricReported,t(e)}}}function z(t){return Math.round(1e3*t)/1e3}class EWMA{constructor(t){this.tickInterval=t,this.ewma=0,this.startTime=Date.now()}decay(){const t=Date.now()-this.startTime;return Math.pow(2,-t/(4*this.tickInterval))}update(t){const e=this.decay();return this.ewma=e*this.ewma+(1-e)*t,this.ewma}toJSON(){return this.ewma}}class WatchedState{constructor(t){this.player=t,this.marchingInterval=void 0,this.lastWatchedPoint=void 0,this.watchedSum=0,this.lastReportedSum=0,this.ewmaTickWatched=new EWMA(WatchedState.AccuracyMilliseconds)}reset(){this.onNotWatching(),this.watchedSum=0,this.lastReportedSum=0,this.lastWatchedPoint=void 0}onNotWatching(){this.marchingInterval&&(this.updateWatched(),this.marchingInterval=clearInterval(this.marchingInterval))}onWatching(){this.marchingInterval||(this.lastWatchedPoint=this.createWatchedPoint(),this.marchingInterval=setInterval(()=>{this.updateWatched()},WatchedState.AccuracyMilliseconds))}createWatchedPoint(){return{currentTime:this.player.currentTime,paused:this.player.paused}}updateWatched(){const t=this.createWatchedPoint();this.lastWatchedPoint&&this.calculateTimeWatched(this.lastWatchedPoint,t),this.lastWatchedPoint=t}calculateTimeWatched(t,e){const i=e.currentTime-t.currentTime,n=this.ewmaTickWatched.update(i);if(!(i<0)&&!(1e3*i>1.3*WatchedState.AccuracyMilliseconds)&&(this.watchedSum+=i,this.watchedSum!=this.lastReportedSum&&(this.watchedSum>this.lastReportedSum+WatchedState.ReportingIntervalSeconds||this.player.ended))){const t=z(n),e={total_watched_seconds:z(this.watchedSum),tick_watched_seconds:t,batch_watched_seconds:z(this.watchedSum-this.lastReportedSum)};this.lastReportedSum=this.watchedSum,this.player.emit(s,e)}}}WatchedState.ReportingIntervalSeconds=5,WatchedState.AccuracyMilliseconds=160;const q=B();class Health{constructor(t,e){let i;this.session_id=q,this.suspended=!1,this.logger=S("health",e.opts),this.media_session_id=B(),this.play_range_id=B(),this.analyticsLoop=setInterval(()=>b(this),2e3),e.on("reap",()=>clearInterval(this.analyticsLoop)),e.on(_,()=>{i!==this.media_session_id&&(i=this.media_session_id,this.first_playing_event_timestamp=Date.now()),this.play_range_id=B()});let n=Date.now()-1e3;e.on("timeupdate",t=>{if(i!==this.media_session_id)return;const s=Date.now();if(s<n)return;n=Date.now()+5e3;const a=L(e,this.eventInfo(t.type)),r=F(a,{duration:(o=e.duration,Number.isFinite(o)?o:o===1/0?-1:void 0)});var o;this.first_playing_event_timestamp&&(Object.assign(r,{ms_since_first_playing:s-this.first_playing_event_timestamp}),this.first_playing_event_timestamp=void 0),M(this,r)});const s=this;if(e.health={get media_session_id(){return s.media_session_id},set media_session_id(t){s.media_session_id=t},get session_id(){return s.session_id},set session_id(t){s.session_id=t},toggle(t){t?s.resume():s.suspend()}},!Health._UNLOAD_SUBSCRIBED){Health._UNLOAD_SUBSCRIBED=!0;const e=e=>t.instances.forEach(t=>t.emit(e.type));document.addEventListener("visibilitychange",t=>{"hidden"==document.visibilityState&&e(t)}),window.addEventListener("pagehide",e)}}eventInfo(t){return{event:t,media_session_id:this.media_session_id,session_id:this.session_id,play_range_id:this.play_range_id}}suspend(){this.suspended=!0,clearInterval(this.analyticsLoop)}resume(){this.suspended=!1,this.analyticsLoop=setInterval(()=>b(this),2e3)}init(a,S,w){if(O().toString().startsWith("data:"))return this.suspend();!function(i){let n=null;const s=()=>{n=null};i.on(m,(function(e){i.seeking||i.networkState===i.NETWORK_LOADING&&(i.readyState<HTMLMediaElement.HAVE_CURRENT_DATA||i.emit(t))})),i.on(t,t=>{n=t}),i.on(p,t=>{if(n){const a=t.timeStamp-n.timeStamp;if(s(),a<31)return;if(a>3e5)return;i.emit(e,{rebuffer_duration:a/1e3})}}),E.forEach(t=>i.on(t,s))}(w),function(t){let e;[p,v].forEach(i=>{t.on(i,i=>{const s=Date.now();switch(i.type){case v:return e=s;case p:if(e)return t.emit(n,{ms_since_loading_started:s-e}),e=null}})})}(w),function(t){if(void 0===window.performance)return;const e=new TimeToFirstFrame;t.on("ovp:config:finalized",t=>{e.reset(),e.state=K.ConfigFinalized,e.requiresUserGesture=!t.detail.autoplay}),t.on(v,()=>{t.root.classList.contains("ad-hide-first-frame")&&e.startTimer(K.TimerStartedWithAdsAutoplay),t.opt("autoplay")&&e.startTimer(K.TimerStartedWithContentAutoplay)}),t.on("click",()=>{t.opt("autoplay")||e.startTimer(K.TimerStartedWithUserGesture)}),t.on("ad-requested",()=>{e.loadedAd=!0}),t.on("timeupdate",()=>{if(!(t.readyState<HTMLMediaElement.HAVE_CURRENT_DATA))switch(e.state){case K.TimerStartedWithContentAutoplay:case K.TimerStartedWithUserGesture:return e.stopTimer(()=>t.emit(i,e.toJSON()))}}),t.on("ad-started",()=>{switch(e.state){case K.TimerStartedWithAdsAutoplay:case K.TimerStartedWithUserGesture:return e.stopTimer(()=>t.emit(i,e.toJSON()))}})}(w),function(t){const e=new WatchedState(t);t.on(v,()=>e.reset()),t.on(_,()=>e.onWatching()),t.on(u,()=>e.onNotWatching()),t.on(g,()=>e.onNotWatching()),t.on(f,()=>e.updateWatched()),t.on("visibilitychange",()=>e.updateWatched())}(w),w.on("display",t=>{M(this,L(w,this.eventInfo(t.type)),!0)}),w.on("health:record",({detail:t})=>{const e=L(w,this.eventInfo(t.event));Object.assign(e,t.detail||{}),M(this,e)}),[h,d,c,l,m,t].forEach(t=>{w.on(t,t=>{M(this,L(w,this.eventInfo(t.type)))})}),[e,i,n,s].forEach(t=>{w.on(t,t=>{const e=L(w,this.eventInfo(t.type));M(this,Object.assign(e,t.detail))})}),[_,u,g,y,f,r,o,p,v].forEach(t=>{w.on(t,t=>{M(this,L(w,this.eventInfo(t.type)))})}),w.on("volumechange",j(800,t=>{const e=L(w,this.eventInfo(t.type));M(this,F(e,{volume:parseFloat(w.volume.toFixed(2)),muted:w.muted}))})),w.on("resize",j(800,t=>{const e=L(w,this.eventInfo(t.type));M(this,F(e,{height:S.clientHeight,width:S.clientWidth}))})),w.on("hls/failover",t=>{const e=L(w,this.eventInfo(t.type)),i=t.detail,{reason:n,from:s}=i;M(this,F(e,{reason:n,from:s}))}),w.on("qualitychange",({type:t,detail:e})=>{switch(e.kind){case"hls":return P(this,w,t,e)}}),w.addEventListener("error",t=>{const e=L(w,this.eventInfo(t.type)),i=t.error||w.error;if(!i)return M(this,e,!0);const n=i.code,s={error_message:i.message||G(n),error_code:n,error_stack:i.stack||""};return M(this,F(e,s),!0)}),w.on("src",t=>{var e;const i=null===(e=t.detail)||void 0===e?void 0:e.src;if("string"!=typeof i)return;if(!T(w.original_src))return;if(!T(i))return;if(i==w.original_src)return;this.media_session_id=B();M(this,L(w,this.eventInfo(t.type))),b(this)}),w.on("visibilitychange",t=>{M(this,L(w,this.eventInfo(t.type))),b(this)})}}return Health.events=a,Health._UNLOAD_SUBSCRIBED=!1,function(t,e){if("object"==typeof exports&&"undefined"!=typeof module)return e;if(null===document.currentScript)return e;"flowplayer"in t||(t.flowplayer={extensions:[]});const i=t.flowplayer;return"function"==typeof i?(i(e),e):(Array.isArray(i.extensions)||(i.extensions=[]),~i.extensions.indexOf(e)||i.extensions.push(e),e)}(window,Health)}));
|