UNPKG

@flowplayer/player

Version:
2 lines (1 loc) 4.93 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((e="undefined"!=typeof globalThis?globalThis:e||self).flowplayer=e.flowplayer||{},e.flowplayer.qul=t())}(this,(function(){"use strict";const e="application/vnd.apple.mpegURL";document.createElement("video").canPlayType(e);function t(t){var n;return void 0===window.MediaSource&&void 0===window.WebKitMediaSource||function(){const e="undefined"!=typeof document&&"undefined"!=typeof window,t=e?navigator.userAgent:"",n=/iP(hone|od)/i.test(t)&&!/iPad/.test(t)&&!/IEMobile/i.test(t),o=/Android/.test(t)&&!/Firefox/.test(t),i=/^((?!chrome|android).)*safari/i.test(t),r=/chrome|crios/i.test(t)&&!/opr|opera|chromium|edg|ucbrowser|googlebot/i.test(t),s=/firefox|fxios/i.test(t)&&!/seamonkey/i.test(t),d=/edg/i.test(t),a=/opr|opera/i.test(t),u=/SamsungBrowser/.test(t),l=u&&/SMART-TV/.test(t);return{controls:!n,video:function(t){return e&&document.createElement("video").canPlayType(t)},lang:e&&window.navigator.language,android:o,iphone:n,safari:i,edge:d,opera:a,chrome:r,firefox:s,ios:e&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,samsung:u,samsung_tv:u&&l,touch:"ontouchstart"in window,tizen:"tizen"in window,webOS:"webos"in window}}().video(e)&&(null===(n=null==t?void 0:t.hls)||void 0===n?void 0:n.native)}function n(e,t){t.id&&clearInterval(t.id)}function o(e,t){i(e.original_src,(e,o,i)=>{200!=o&&n(0,t)})}function i(e,t){const n=new XMLHttpRequest;n.onload=function(){if(200==n.status)return t(void 0,n.status);try{const e=JSON.parse(n.responseText);t(void 0,"qul:"+n.status,e)}catch(e){t(e)}},n.open("GET",function(e){const t=document.createElement("a");t.href=e;const n="bust="+Date.now();return[t.protocol,"//",t.hostname,t.pathname,t.search,t.search.length?"&":"?",n].join("")}(e)),n.send()}function r(e,t){const n=new CustomEvent(e,{detail:t,cancelable:!0});return t&&Object.defineProperty(n,"data",{get:()=>t}),n}!function(){let e=!1;try{const t=Object.defineProperty({},"passive",{get:function(){e=!0}});window.addEventListener("testPassive",null,t),window.removeEventListener("testPassive",null,t)}catch(e){}}();function s(e,t,n){const o=document.createElement("a");o.href=e;let i=encodeURIComponent(t);return n&&(i+="/dId:"+encodeURIComponent(n)),[o.protocol,"//",o.hostname,o.pathname.replace(a(o.pathname,0),i+"/"+a(o.pathname,0))].join("")}class QULPlugin{init(e,r,a){var u,l,c;const f=(null===(u=e.qul)||void 0===u?void 0:u.device_id)||(null===(l=e.qul)||void 0===l?void 0:l.dId)||a.deviceId();let v,p=null===(c=e.qul)||void 0===c?void 0:c.token;const m={};a.on("src",(function(i){var r;i.data&&(v=null===(r=i.data)||void 0===r?void 0:r.src,n(0,m),"string"==typeof v&&v.match(/\.m3u8$/)&&p&&(i.data.src=s(v,p,f),t(e)&&Object.assign(m,function(e,t){var i;const r=(null===(i=null==t?void 0:t.qul)||void 0===i?void 0:i.interval)||2e4,s={interval:Math.min(2e4,r)};return e.once("reap",(function(){n(0,s)})),s.id=setInterval(o,s.interval,e,s),setTimeout(o,0,e,s),s}(a,a.opts))))})),a.on("config",(function(e){var t,n,o,i,r,d;const u=null===(n=null===(t=e.data)||void 0===t?void 0:t.qul)||void 0===n?void 0:n.token,l=(null===(i=null===(o=e.data)||void 0===o?void 0:o.qul)||void 0===i?void 0:i.device_id)||(null===(d=null===(r=e.data)||void 0===r?void 0:r.qul)||void 0===d?void 0:d.dId);u&&u!==p&&function(e,t){p=e,a.setSrc({type:"application/x-mpegurl",src:s(v,p,t)})}(u,l)})),a.on("error",(function(e){var t,o;const r=((null===(t=e.data)||void 0===t?void 0:t.code)||"").toString();if(!r.match(/^(qul|http)/))return;n(0,m),e.preventDefault();const s=null===(o=e.data)||void 0===o?void 0:o.resp;if(s)return d(a,s,r);i(a.original_src,(e,t,n)=>{!isNaN(Number(t))&&Number(t)<400||d(a,n,null==t?void 0:t.toString())})}))}}QULPlugin.pluginName="qul",QULPlugin.events={QUL_ERROR:"qul:error"};function d(e,t,n){const o=(null==t?void 0:t.message)||"an error occurred during this session",i=(null==t?void 0:t.key)?e.i18n(t.key,o):o;e.pause();const s=r("qul:error",{code:n,resp:t});if(e.dispatchEvent(s),s.defaultPrevented)return;const d=window.customElements.get("flowplayer-error"),a=function(e,t){const n=e._customElements.get(t);return n&&e.root.querySelector(n)||void 0}(e,"flowplayer-ui");if(a&&d){if(e.setState("is-error",!0),!e.root.querySelector("#qul_error")){const t=new d(e);t.id="qul_error",a.append(t)}!function(e,t,n){const o=r(t,n);e.dispatchEvent(o)}(e.root.querySelector("#qul_error"),"error",{formatted_data:{message:i}})}}function a(e,t){return e.split("/").reverse().slice(0,t+1).reverse().join("/")}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,QULPlugin)}));