swarmcloud-hls 2.7.13 → 2.8.4

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/README.md CHANGED
@@ -7,14 +7,14 @@
7
7
  <a href="https://www.jsdelivr.com/package/npm/swarmcloud-hls"><img src="https://data.jsdelivr.com/v1/package/npm/swarmcloud-hls/badge" alt="jsdelivr"></a>
8
8
  </p>
9
9
 
10
- This SDK integrates 2 p2p streaming engines, one is [hlsjs based](https://swarmcloud.net/views/web/introduction.html), another is [ServiceWorker based](https://swarmcloud.net/views/hls-sw/introduction.html).
10
+ This SDK integrates 2 p2p streaming engines, one is [hlsjs based](https://swarmcloud.net/views/web/introduction.html), another is ServiceWorker based.
11
11
  <br>
12
12
  As you might expect, it supports all modern browsers (including iOS Safari) and all web players (including players without hls.js built-in)!
13
13
 
14
14
  ## Browser Support
15
15
  WebRTC has already been incorporated into the HTML5 standard and it is broadly deployed in modern browsers. The compatibility of SwarmCloud depends on the browser support of WebRTC, MediaSource API or Service Worker.
16
16
 
17
- Compatibility|Chrome | Firefox | macOS Safari | Opera | Edge | iOS Safari | IE |
17
+ Compatibility|Chrome | Firefox | macOS Safari | Opera | Edge | iOS Safari | IE |
18
18
  :-: | :-: | :-: | :-: | :-: | :-:| :-:| :-:
19
19
  WebRTC Datachannel | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ❌ |
20
20
  MSE | ✔ | ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
package/dist/hls-proxy.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.HlsProxy=t():e.HlsProxy=t()}(self,(()=>(()=>{var e={622:function(e){var t,r,n,o,i;t=/^(?=((?:[a-zA-Z0-9+\-.]+:)?))\1(?=((?:\/\/[^\/?#]*)?))\2(?=((?:(?:[^?#\/]*\/)*[^;?#\/]*)?))\3((?:;[^?#]*)?)(\?[^#]*)?(#[^]*)?$/,r=/^(?=([^\/?#]*))\1([^]*)$/,n=/(?:\/|^)\.(?=\/)/g,o=/(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g,i={buildAbsoluteURL:function(e,t,n){if(n=n||{},e=e.trim(),!(t=t.trim())){if(!n.alwaysNormalize)return e;var o=i.parseURL(e);if(!o)throw new Error("Error trying to parse base URL.");return o.path=i.normalizePath(o.path),i.buildURLFromParts(o)}var s=i.parseURL(t);if(!s)throw new Error("Error trying to parse relative URL.");if(s.scheme)return n.alwaysNormalize?(s.path=i.normalizePath(s.path),i.buildURLFromParts(s)):t;var a=i.parseURL(e);if(!a)throw new Error("Error trying to parse base URL.");if(!a.netLoc&&a.path&&"/"!==a.path[0]){var u=r.exec(a.path);a.netLoc=u[1],a.path=u[2]}a.netLoc&&!a.path&&(a.path="/");var f={scheme:a.scheme,netLoc:s.netLoc,path:null,params:s.params,query:s.query,fragment:s.fragment};if(!s.netLoc&&(f.netLoc=a.netLoc,"/"!==s.path[0]))if(s.path){var l=a.path,c=l.substring(0,l.lastIndexOf("/")+1)+s.path;f.path=i.normalizePath(c)}else f.path=a.path,s.params||(f.params=a.params,s.query||(f.query=a.query));return null===f.path&&(f.path=n.alwaysNormalize?i.normalizePath(s.path):s.path),i.buildURLFromParts(f)},parseURL:function(e){var r=t.exec(e);return r?{scheme:r[1]||"",netLoc:r[2]||"",path:r[3]||"",params:r[4]||"",query:r[5]||"",fragment:r[6]||""}:null},normalizePath:function(e){for(e=e.split("").reverse().join("").replace(n,"");e.length!==(e=e.replace(o,"")).length;);return e.split("").reverse().join("")},buildURLFromParts:function(e){return e.scheme+e.netLoc+e.path+e.params+e.query+e.fragment}},e.exports=i},47:(e,t)=>{"use strict";var r=2147483647;function n(e){if(e>r)throw new RangeError('The value "'+e+'" is invalid for option "size"');var t=new Uint8Array(e);return t.__proto__=o.prototype,t}function o(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return a(e)}return i(e,t,r)}function i(e,t,r){if("string"==typeof e)return function(e,t){"string"==typeof t&&""!==t||(t="utf8");if(!o.isEncoding(t))throw new TypeError("Unknown encoding: "+t);var r=0|l(e,t),i=n(r),s=i.write(e,t);s!==r&&(i=i.slice(0,s));return i}(e,t);if(ArrayBuffer.isView(e))return u(e);if(null==e)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(y(e,ArrayBuffer)||e&&y(e.buffer,ArrayBuffer))return function(e,t,r){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');var n;n=void 0===t&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,t):new Uint8Array(e,t,r);return n.__proto__=o.prototype,n}(e,t,r);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');var i=e.valueOf&&e.valueOf();if(null!=i&&i!==e)return o.from(i,t,r);var s=function(e){if(o.isBuffer(e)){var t=0|f(e.length),r=n(t);return 0===r.length||e.copy(r,0,0,t),r}if(void 0!==e.length)return"number"!=typeof e.length||_(e.length)?n(0):u(e);if("Buffer"===e.type&&Array.isArray(e.data))return u(e.data)}(e);if(s)return s;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return o.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function s(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function a(e){return s(e),n(e<0?0:0|f(e))}function u(e){for(var t=e.length<0?0:0|f(e.length),r=n(t),o=0;o<t;o+=1)r[o]=255&e[o];return r}function f(e){if(e>=r)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+r.toString(16)+" bytes");return 0|e}function l(e,t){if(o.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||y(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);var r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;for(var i=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return g(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;default:if(i)return n?-1:g(e).length;t=(""+t).toLowerCase(),i=!0}}function c(e,t,r,n){r=Number(r)||0;const o=e.length-r;n?(n=Number(n))>o&&(n=o):n=o;const i=t.length;let s;for(n>i/2&&(n=i/2),s=0;s<n;++s){const n=parseInt(t.substr(2*s,2),16);if(_(n))return s;e[r+s]=n}return s}function h(e,t,r,n){return E(g(t,e.length-r),e,r,n)}function p(e,t,r,n){return E(function(e){const t=[];for(let r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function d(e,t,r,n){return E(function(e,t){let r,n,o;const i=[];for(let s=0;s<e.length&&!((t-=2)<0);++s)r=e.charCodeAt(s),n=r>>8,o=r%256,i.push(o),i.push(n);return i}(t,e.length-r),e,r,n)}function E(e,t,r,n){let o;for(o=0;o<n&&!(o+r>=t.length||o>=e.length);++o)t[o+r]=e[o];return o}function g(e,t){var r;t=t||1/0;for(var n=e.length,o=null,i=[],s=0;s<n;++s){if((r=e.charCodeAt(s))>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(t-=3)>-1&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((t-=1)<0)break;i.push(r)}else if(r<2048){if((t-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function y(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function _(e){return e!=e}"undefined"!=typeof Symbol&&null!=Symbol.species&&o[Symbol.species]===o&&Object.defineProperty(o,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),o.from=function(e,t,r){return i(e,t,r)},o.prototype.__proto__=Uint8Array.prototype,o.__proto__=Uint8Array,o.alloc=function(e,t,r){return function(e,t,r){return s(e),e<=0?n(e):void 0!==t?"string"==typeof r?n(e).fill(t,r):n(e).fill(t):n(e)}(e,t,r)},o.allocUnsafe=function(e){return a(e)},o.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==o.prototype},o.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},o.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return o.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=o.allocUnsafe(t),i=0;for(r=0;r<e.length;++r){var s=e[r];if(y(s,Uint8Array)&&(s=o.from(s)),!o.isBuffer(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(n,i),i+=s.length}return n},o.byteLength=l,o.prototype._isBuffer=!0,o.prototype.copy=function(e,t,r,n){if(!o.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);var i=n-r;if(this===e&&"function"==typeof Uint8Array.prototype.copyWithin)this.copyWithin(t,r,n);else if(this===e&&r<t&&t<n)for(var s=i-1;s>=0;--s)e[s+t]=this[s+r];else Uint8Array.prototype.set.call(e,this.subarray(r,n),t);return i},o.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const o=this.length-t;if((void 0===r||r>o)&&(r=o),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let i=!1;for(;;)switch(n){case"hex":return c(this,e,t,r);case"utf8":case"utf-8":return h(this,e,t,r);case"ascii":case"latin1":case"binary":return p(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return d(this,e,t,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}}}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,r),i.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var n={};return(()=>{"use strict";r.d(n,{default:()=>m});class e{static insertTimeOffsetTag(e,t){const r=e.split("\n");for(let e=0;e<r.length;e++)if(r[e].startsWith("#EXT-X-VERSION")){r[e]=`${r[e]}\n#EXT-X-START:TIME-OFFSET=${t}`;break}return r.join("\n")}}const t={DC_SIGNAL:"SIGNAL",DC_OPEN:"OPEN",DC_REQUEST:"REQUEST",DC_SEND_REQUEST:"SEND_REQUEST",DC_PIECE_NOT_FOUND:"PIECE_NOT_FOUND",DC_PIECE_ABORT:"PIECE_ABORT",DC_PIECE_CANCEL:"PIECE_CANCEL",DC_CLOSE:"CLOSE",DC_RESPONSE:"RESPONSE",DC_ERROR:"ERROR",DC_PIECE:"PIECE",DC_PIECE_DATA:"PIECE_DATA",DC_TIMEOUT:"TIMEOUT",DC_PIECE_ACK:"PIECE_ACK",DC_METADATA:"METADATA",DC_PLAT_ANDROID:"ANDROID",DC_PLAT_IOS:"IOS",DC_PLAT_WEB:"WEB",DC_CHOKE:"CHOKE",DC_UNCHOKE:"UNCHOKE",DC_HAVE:"HAVE",DC_HAVE_REVERSE:"HAVE_REVERSE",DC_LOST:"LOST",DC_GET_PEERS:"GET_PEERS",DC_PEERS:"PEERS",DC_STATS:"STATS",DC_PEER_SIGNAL:"PEER_SIGNAL",DC_PLAYLIST:"PLAYLIST",BM_LOST:"lost",BM_ADDED_SEG_:"BM_ADDED_SEG_",BM_ADDED_SN_:"BM_ADDED_SN_",BM_SEG_ADDED:"BM_SEG_ADDED",FRAG_CHANGED:"FRAG_CHANGED",FRAG_LOADED:"FRAG_LOADED",FRAG_LOADING:"FRAG_LOADING",RESTART_P2P:"RESTART_P2P",EXCEPTION:"exception",REQUESTING_MAP_HAVE:"REQUESTING_MAP_HAVE",BUILDER_MAP_HAVE:"BUILDER_MAP_HAVE",SYN_OUTPUT:"SYN_OUTPUT",SYN_ERROR:"SYN_ERROR",SYN_PARTIAL:"SYN_PARTIAL",SCH_DCHAVE:"SCH_DCHAVE",SCH_WAIT_PEER:"SCH_WAIT_PEER",SW_PLAYLIST:"SW_PLAYLIST",SW_GET_PLAYLIST:"SW_GET_PLAYLIST",SW_GET_MEDIA:"SW_GET_MEDIA",LEVEL_LOADED:"LEVEL_LOADED",MANIFEST_PARSED:"MANIFEST_PARSED"};var o=r(622);function i(e,t="."){const r=o.parseURL(e);return r.path.substring(r.path.lastIndexOf(t)+1)}r(47);let s=["m3u8"];let a=["ts","mp4","m4s","fmp4"];const u="#EXT-X-ENDLIST\n";let f=.01,l=".",c=!1,h=!1;const p=new Map,d=new class{constructor(){this.sendMessageToClient=this.sendMessageToClient.bind(this)}async sendMessageToClient(e,t,r,n=[]){return e?new Promise(((o,i)=>{const s=new MessageChannel;let a;const u=(e,t)=>setTimeout((()=>{s.port1.close(),s.port2.close(),i(`MessageChannel ${t} timed out after ${e} ms`)}),e);s.port1.onmessage=function(e){const n=e.data;n?n.pong?(clearTimeout(a),a=u(r,`${t.action}-data`)):o({data:n.data}):i("no data in event")},s.port1.onmessageerror=function(e){i(e)},e.postMessage(t,[s.port2].concat(n)),a=u(50,`${t.action}-pong`)})):Promise.reject("client is null")}};let E=!1,g=null,y=null,_=!1;class m{constructor(e={}){g=e.httpHeadersForPlaylist||null,y=e.httpHeadersForMediaFile||null,!0===e.insertTimeOffsetTag?(_=!0,e.playlistTimeOffset&&(f=e.playlistTimeOffset)):_=!1,e.allowedMediaFiles&&e.allowedMediaFiles.length>0&&(a=[...e.allowedMediaFiles]),e.allowedPlaylistSuffix&&e.allowedPlaylistSuffix.length>0&&(s=[...e.allowedPlaylistSuffix]),e.mediaFileSeparator&&(l=e.mediaFileSeparator)}}self.addEventListener("install",(()=>{self.skipWaiting()})),self.addEventListener("activate",(e=>e.waitUntil(self.clients.claim()))),self.addEventListener("fetch",(function(r){const{request:n,clientId:o}=r,{headers:m,url:w}=n;if("GET"!==n.method)return;let A=i(w);if(s.includes(A))return c&&console.info(`sw onFetch playlist ${w}`),r.respondWith(async function(r,n){p.size>50&&p.clear();const{url:o,headers:i}=r,s=await clients.get(n);if(h&&s)try{const r=await d.sendMessageToClient(s,{action:t.SW_GET_PLAYLIST,data:{url:o}},200),{data:n}=r;if(n&&n.text){let{text:t}=n;return _&&!t.endsWith(u)&&(t=e.insertTimeOffsetTag(t,f)),new Response(t,{status:200,statusText:"OK",headers:{"Content-Type":"application/vnd.apple.mpegurl"}})}}catch(e){console.error(e)}let a;g&&(a=new Headers,c&&console.info(`set additional header for ${o}`),g(o,a,i));return fetch(new Request(o,{mode:"cors",headers:a})).then((async r=>{if(r.ok&&s)try{const i=await r.clone().text();let a;r.redirected&&(c&&console.info(`resp redirected to url ${r.url} `),a=r.url);const l=await d.sendMessageToClient(s,{action:t.SW_PLAYLIST,data:{url:o,redirectedUrl:a,ver:"2.7.13",text:i}},200),{data:E}=l;if(c||(c=E&&E.debug),!E.active)return c&&console.warn("window client is not active"),p.delete(n),r;if(p.set(n,s),h=!!E.sharePlaylist,_&&!i.endsWith(u)){const t=e.insertTimeOffsetTag(i,f);return new Response(t,{status:200,statusText:"OK",headers:r.headers})}}catch(e){c&&console.warn(e),p.delete(n)}return r}))}(n,o));"."!==l&&(A=i(w,l));if(a.includes(A)){let e;if(y&&(e=new Headers,c&&console.info(`set additional header for ${w}`),y(w,e,m)),p.has(o)){let n,i,s=m.get("Range")||void 0;c&&console.info(`sw onFetch media ${w} range ${s}`);try{const{start:e,end:t}=function(e){if(!e)return{};const t=e.trim().toLowerCase();if(!t.startsWith("bytes="))throw new Error("unit-must-be-bytes",{normalizedRangeHeader:t});if(t.includes(","))throw new Error("single-range-only",{normalizedRangeHeader:t});const r=/(\d*)-(\d*)/.exec(t);if(!r||!r[1]&&!r[2])throw new Error("invalid-range-values",{normalizedRangeHeader:t});return{start:""===r[1]?void 0:Number(r[1]),end:""===r[2]?void 0:Number(r[2])}}(s);n=e,i=t}catch(e){return void console.error(e)}return"bypass"===m.get("__sw_proxy__")?(s&&(e||(e=new Headers),e.set("Range",s)),r.respondWith(fetch(new Request(w,{mode:"cors",headers:e})))):r.respondWith(function(e,r,n,o,i,s){c&&E&&console.warn("hls proxy is loading");let a=!1;i||s?(i||s)&&(a=!0):(o=void 0,0===i&&void 0===s&&(c&&console.warn(`request ${e} with range 0-`),a=!0));return E=!0,d.sendMessageToClient(n,{action:t.SW_GET_MEDIA,data:{url:e,range:o}},7e3).then((async t=>{if(E=!1,t&&t.data&&(t.data.buffer||t.data.incomplete)){const{data:e}=t,{buffer:r}=e;if(a&&r.byteLength!==s-i+1)return void console.error("buffer size is not equal to range length "+(s-i+1));const n={status:a?206:200,statusText:a?"Partial Content":"OK",headers:{"Accept-Ranges":"bytes","Content-Length":r.byteLength}};return a&&(n.headers["Content-Range"]=`bytes ${i}-${s}/${r.byteLength}`),new Response(r,n)}return fetch(new Request(e,{mode:"cors",headers:r}))})).catch((t=>(console.error(t),E=!1,c&&(console.warn(t),console.warn(`while requesting ${e}`)),fetch(new Request(e,{mode:"cors",headers:r})))))}(w,e,p.get(o),s,n,i))}return c&&console.warn("windowClient not exist when get media"),r.respondWith(fetch(new Request(w,{mode:"cors",headers:e})))}})),self.addEventListener("message",(async function({data:e}){})),m.version="2.7.13"})(),n=n.default})()));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.HlsProxy=t():e.HlsProxy=t()}(self,(()=>(()=>{var e={622:function(e){var t,r,n,o,i;t=/^(?=((?:[a-zA-Z0-9+\-.]+:)?))\1(?=((?:\/\/[^\/?#]*)?))\2(?=((?:(?:[^?#\/]*\/)*[^;?#\/]*)?))\3((?:;[^?#]*)?)(\?[^#]*)?(#[^]*)?$/,r=/^(?=([^\/?#]*))\1([^]*)$/,n=/(?:\/|^)\.(?=\/)/g,o=/(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g,i={buildAbsoluteURL:function(e,t,n){if(n=n||{},e=e.trim(),!(t=t.trim())){if(!n.alwaysNormalize)return e;var o=i.parseURL(e);if(!o)throw new Error("Error trying to parse base URL.");return o.path=i.normalizePath(o.path),i.buildURLFromParts(o)}var s=i.parseURL(t);if(!s)throw new Error("Error trying to parse relative URL.");if(s.scheme)return n.alwaysNormalize?(s.path=i.normalizePath(s.path),i.buildURLFromParts(s)):t;var a=i.parseURL(e);if(!a)throw new Error("Error trying to parse base URL.");if(!a.netLoc&&a.path&&"/"!==a.path[0]){var u=r.exec(a.path);a.netLoc=u[1],a.path=u[2]}a.netLoc&&!a.path&&(a.path="/");var f={scheme:a.scheme,netLoc:s.netLoc,path:null,params:s.params,query:s.query,fragment:s.fragment};if(!s.netLoc&&(f.netLoc=a.netLoc,"/"!==s.path[0]))if(s.path){var l=a.path,c=l.substring(0,l.lastIndexOf("/")+1)+s.path;f.path=i.normalizePath(c)}else f.path=a.path,s.params||(f.params=a.params,s.query||(f.query=a.query));return null===f.path&&(f.path=n.alwaysNormalize?i.normalizePath(s.path):s.path),i.buildURLFromParts(f)},parseURL:function(e){var r=t.exec(e);return r?{scheme:r[1]||"",netLoc:r[2]||"",path:r[3]||"",params:r[4]||"",query:r[5]||"",fragment:r[6]||""}:null},normalizePath:function(e){for(e=e.split("").reverse().join("").replace(n,"");e.length!==(e=e.replace(o,"")).length;);return e.split("").reverse().join("")},buildURLFromParts:function(e){return e.scheme+e.netLoc+e.path+e.params+e.query+e.fragment}},e.exports=i},47:(e,t)=>{"use strict";var r=2147483647;function n(e){if(e>r)throw new RangeError('The value "'+e+'" is invalid for option "size"');var t=new Uint8Array(e);return t.__proto__=o.prototype,t}function o(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return a(e)}return i(e,t,r)}function i(e,t,r){if("string"==typeof e)return function(e,t){"string"==typeof t&&""!==t||(t="utf8");if(!o.isEncoding(t))throw new TypeError("Unknown encoding: "+t);var r=0|l(e,t),i=n(r),s=i.write(e,t);s!==r&&(i=i.slice(0,s));return i}(e,t);if(ArrayBuffer.isView(e))return u(e);if(null==e)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(y(e,ArrayBuffer)||e&&y(e.buffer,ArrayBuffer))return function(e,t,r){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');var n;n=void 0===t&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,t):new Uint8Array(e,t,r);return n.__proto__=o.prototype,n}(e,t,r);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');var i=e.valueOf&&e.valueOf();if(null!=i&&i!==e)return o.from(i,t,r);var s=function(e){if(o.isBuffer(e)){var t=0|f(e.length),r=n(t);return 0===r.length||e.copy(r,0,0,t),r}if(void 0!==e.length)return"number"!=typeof e.length||_(e.length)?n(0):u(e);if("Buffer"===e.type&&Array.isArray(e.data))return u(e.data)}(e);if(s)return s;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return o.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function s(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function a(e){return s(e),n(e<0?0:0|f(e))}function u(e){for(var t=e.length<0?0:0|f(e.length),r=n(t),o=0;o<t;o+=1)r[o]=255&e[o];return r}function f(e){if(e>=r)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+r.toString(16)+" bytes");return 0|e}function l(e,t){if(o.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||y(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);var r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;for(var i=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return g(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;default:if(i)return n?-1:g(e).length;t=(""+t).toLowerCase(),i=!0}}function c(e,t,r,n){r=Number(r)||0;const o=e.length-r;n?(n=Number(n))>o&&(n=o):n=o;const i=t.length;let s;for(n>i/2&&(n=i/2),s=0;s<n;++s){const n=parseInt(t.substr(2*s,2),16);if(_(n))return s;e[r+s]=n}return s}function h(e,t,r,n){return d(g(t,e.length-r),e,r,n)}function p(e,t,r,n){return d(function(e){const t=[];for(let r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function E(e,t,r,n){return d(function(e,t){let r,n,o;const i=[];for(let s=0;s<e.length&&!((t-=2)<0);++s)r=e.charCodeAt(s),n=r>>8,o=r%256,i.push(o),i.push(n);return i}(t,e.length-r),e,r,n)}function d(e,t,r,n){let o;for(o=0;o<n&&!(o+r>=t.length||o>=e.length);++o)t[o+r]=e[o];return o}function g(e,t){var r;t=t||1/0;for(var n=e.length,o=null,i=[],s=0;s<n;++s){if((r=e.charCodeAt(s))>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(t-=3)>-1&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((t-=1)<0)break;i.push(r)}else if(r<2048){if((t-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function y(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function _(e){return e!=e}"undefined"!=typeof Symbol&&null!=Symbol.species&&o[Symbol.species]===o&&Object.defineProperty(o,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),o.from=function(e,t,r){return i(e,t,r)},o.prototype.__proto__=Uint8Array.prototype,o.__proto__=Uint8Array,o.alloc=function(e,t,r){return function(e,t,r){return s(e),e<=0?n(e):void 0!==t?"string"==typeof r?n(e).fill(t,r):n(e).fill(t):n(e)}(e,t,r)},o.allocUnsafe=function(e){return a(e)},o.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==o.prototype},o.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},o.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return o.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=o.allocUnsafe(t),i=0;for(r=0;r<e.length;++r){var s=e[r];if(y(s,Uint8Array)&&(s=o.from(s)),!o.isBuffer(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(n,i),i+=s.length}return n},o.byteLength=l,o.prototype._isBuffer=!0,o.prototype.copy=function(e,t,r,n){if(!o.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);var i=n-r;if(this===e&&"function"==typeof Uint8Array.prototype.copyWithin)this.copyWithin(t,r,n);else if(this===e&&r<t&&t<n)for(var s=i-1;s>=0;--s)e[s+t]=this[s+r];else Uint8Array.prototype.set.call(e,this.subarray(r,n),t);return i},o.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const o=this.length-t;if((void 0===r||r>o)&&(r=o),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let i=!1;for(;;)switch(n){case"hex":return c(this,e,t,r);case"utf8":case"utf-8":return h(this,e,t,r);case"ascii":case"latin1":case"binary":return p(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return E(this,e,t,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}}}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,r),i.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var n={};return(()=>{"use strict";r.d(n,{default:()=>A});class e{static insertTimeOffsetTag(e,t){const r=e.split("\n");for(let e=0;e<r.length;e++)if(r[e].startsWith("#EXT-X-VERSION")){r[e]=`${r[e]}\n#EXT-X-START:TIME-OFFSET=${t}`;break}return r.join("\n")}}const t={DC_SIGNAL:"SIGNAL",DC_OPEN:"OPEN",DC_REQUEST:"REQUEST",DC_SEND_REQUEST:"SEND_REQUEST",DC_PIECE_NOT_FOUND:"PIECE_NOT_FOUND",DC_PIECE_ABORT:"PIECE_ABORT",DC_PIECE_CANCEL:"PIECE_CANCEL",DC_CLOSE:"CLOSE",DC_RESPONSE:"RESPONSE",DC_ERROR:"ERROR",DC_PIECE:"PIECE",DC_PIECE_DATA:"PIECE_DATA",DC_TIMEOUT:"TIMEOUT",DC_PIECE_ACK:"PIECE_ACK",DC_METADATA:"METADATA",DC_PLAT_ANDROID:"ANDROID",DC_PLAT_IOS:"IOS",DC_PLAT_WEB:"WEB",DC_CHOKE:"CHOKE",DC_UNCHOKE:"UNCHOKE",DC_HAVE:"HAVE",DC_HAVE_REVERSE:"HAVE_REVERSE",DC_LOST:"LOST",DC_GET_PEERS:"GET_PEERS",DC_PEERS:"PEERS",DC_STATS:"STATS",DC_PEER_SIGNAL:"PEER_SIGNAL",DC_PLAYLIST:"PLAYLIST",BM_LOST:"lost",BM_ADDED_SEG_:"BM_ADDED_SEG_",BM_ADDED_SN_:"BM_ADDED_SN_",BM_SEG_ADDED:"BM_SEG_ADDED",FRAG_CHANGED:"FRAG_CHANGED",FRAG_LOADED:"FRAG_LOADED",FRAG_LOADING:"FRAG_LOADING",RESTART_P2P:"RESTART_P2P",EXCEPTION:"exception",REQUESTING_MAP_HAVE:"REQUESTING_MAP_HAVE",BUILDER_MAP_HAVE:"BUILDER_MAP_HAVE",SYN_OUTPUT:"SYN_OUTPUT",SYN_ERROR:"SYN_ERROR",SYN_PARTIAL:"SYN_PARTIAL",SCH_DCHAVE:"SCH_DCHAVE",SCH_WAIT_PEER:"SCH_WAIT_PEER",SW_PLAYLIST:"SW_PLAYLIST",SW_GET_PLAYLIST:"SW_GET_PLAYLIST",SW_GET_MEDIA:"SW_GET_MEDIA",LEVEL_LOADED:"LEVEL_LOADED",MANIFEST_PARSED:"MANIFEST_PARSED"};var o=r(622);const i="__PROXY_IDENTIFIER__";function s(e,t="."){const r=o.parseURL(e);return r.path.substring(r.path.lastIndexOf(t)+1)}r(47);const a="__sw_proxy__";let u=["m3u8"];let f=["ts","mp4","m4s","fmp4"];const l="#EXT-X-ENDLIST\n";let c=.01,h=".",p=!1,E=!1;const d=new Map,g=new class{constructor(){this.sendMessageToClient=this.sendMessageToClient.bind(this)}async sendMessageToClient(e,t,r,n=[]){return e?new Promise(((o,i)=>{const s=new MessageChannel;let a;const u=(e,t)=>setTimeout((()=>{s.port1.close(),s.port2.close(),i(`MessageChannel ${t} timed out after ${e} ms`)}),e);s.port1.onmessage=function(e){const n=e.data;n?n.pong?(clearTimeout(a),a=u(r,`${t.action}-data`)):o({data:n.data}):i("no data in event")},s.port1.onmessageerror=function(e){i(e)},e.postMessage(t,[s.port2].concat(n)),a=u(50,`${t.action}-pong`)})):Promise.reject("client is null")}};let y=!1,_=null,m=null,w=!1;class A{constructor(e={}){_=e.httpHeadersForPlaylist||null,m=e.httpHeadersForMediaFile||null,!0===e.insertTimeOffsetTag?(w=!0,e.playlistTimeOffset&&(c=e.playlistTimeOffset)):w=!1,e.allowedMediaFiles&&e.allowedMediaFiles.length>0&&(f=[...e.allowedMediaFiles]),e.allowedPlaylistSuffix&&e.allowedPlaylistSuffix.length>0&&(u=[...e.allowedPlaylistSuffix]),e.mediaFileSeparator&&(h=e.mediaFileSeparator)}}self.addEventListener("install",(()=>{self.skipWaiting()})),self.addEventListener("activate",(e=>e.waitUntil(self.clients.claim()))),self.addEventListener("fetch",(r=>{const n=function(r){const{request:n,clientId:o}=r,{headers:A,url:T}=n;if("GET"!==n.method)return;if(T.includes(self.registration.scope+`${i}/keepalive/`))return new Response;let R=s(T);if(u.includes(R))return p&&console.info(`sw onFetch playlist ${T}`),async function(r,n){d.size>50&&d.clear();const{url:o,headers:i}=r,s=await clients.get(n);if(E&&s)try{const r=await g.sendMessageToClient(s,{action:t.SW_GET_PLAYLIST,data:{url:o}},200),{data:n}=r;if(n&&n.text){let{text:t}=n;return w&&!t.endsWith(l)&&(t=e.insertTimeOffsetTag(t,c)),new Response(t,{status:200,statusText:"OK",headers:{"Content-Type":"application/vnd.apple.mpegurl"}})}}catch(e){console.error(e)}let a;_&&(a=new Headers,p&&console.info(`set additional header for ${o}`),_(o,a,i));return fetch(new Request(o,{mode:"cors",headers:a})).then((async r=>{if(r.ok&&s)try{const i=await r.clone().text();let a;r.redirected&&(p&&console.info(`resp redirected to url ${r.url} `),a=r.url);const u=await g.sendMessageToClient(s,{action:t.SW_PLAYLIST,data:{url:o,redirectedUrl:a,ver:"2.8.4",text:i}},200),{data:f}=u;if(p||(p=f&&f.debug),!f.active)return p&&console.warn("window client is not active"),d.delete(n),r;if(d.set(n,s),E=!!f.sharePlaylist,w&&!i.endsWith(l)){const t=e.insertTimeOffsetTag(i,c);return new Response(t,{status:200,statusText:"OK",headers:r.headers})}}catch(e){p&&console.warn(e),d.delete(n)}return r}))}(n,o);"."!==h&&(R=s(T,h));if(f.includes(R)){let e;m&&(e=new Headers,p&&console.info(`set additional header for ${T}`),m(T,e,A));let r=A.get("Range")||void 0;if(r&&(e||(e=new Headers),e.set("Range",r)),d.has(o)){let n,i;p&&console.info(`sw onFetch media ${T} range ${r}`);try{const{start:e,end:t}=function(e){if(!e)return{};const t=e.trim().toLowerCase();if(!t.startsWith("bytes="))throw new Error("unit-must-be-bytes",{normalizedRangeHeader:t});if(t.includes(","))throw new Error("single-range-only",{normalizedRangeHeader:t});const r=/(\d*)-(\d*)/.exec(t);if(!r||!r[1]&&!r[2])throw new Error("invalid-range-values",{normalizedRangeHeader:t});return{start:""===r[1]?0:Number(r[1]),end:""===r[2]?void 0:Number(r[2])}}(r);n=e,i=t}catch(e){return void console.error(e)}if(i-n<=1)return;return"bypass"===A.get(a)?fetch(new Request(T,{mode:"cors",headers:e})):function(e,r,n,o,i,s){p&&y&&console.warn("hls proxy is loading");let a=!1;i||s?(i||s)&&(a=!0):(o=void 0,0===i&&void 0===s&&(p&&console.warn(`request ${e} with range 0-`),a=!0));return y=!0,g.sendMessageToClient(n,{action:t.SW_GET_MEDIA,data:{url:e,range:o}},7e3).then((async t=>{if(y=!1,t&&t.data&&t.data.buffer){const{data:e}=t,{buffer:r}=e;if(a&&r.byteLength!==s-i+1)return void console.error("buffer size is not equal to range length "+(s-i+1));const n={status:a?206:200,statusText:a?"Partial Content":"OK",headers:{"Accept-Ranges":"bytes","Content-Length":r.byteLength}};return a&&(n.headers["Content-Range"]=`bytes ${i}-${s}/${r.byteLength}`),new Response(r,n)}return fetch(new Request(e,{mode:"cors",headers:r}))})).catch((t=>(console.error(t),y=!1,p&&(console.warn(t),console.warn(`while requesting ${e}`)),fetch(new Request(e,{mode:"cors",headers:r})))))}(T,e,d.get(o),r,n,i)}return p&&console.warn("windowClient not exist when get media"),fetch(new Request(T,{mode:"cors",headers:e}))}}(r);n&&r.respondWith(n)})),self.addEventListener("message",(async function({data:e}){})),A.version="2.8.4"})(),n=n.default})()));