swarmcloud-hls 2.2.2 → 2.2.8
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 +1 -1
- package/dist/hls-proxy.js +1 -1
- package/dist/hls.light.min.js +1 -1
- package/dist/hls.min.js +1 -1
- package/dist/p2p-engine.min.d.ts +4 -2
- package/dist/p2p-engine.min.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ Service Worker | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ❌ |
|
|
|
22
22
|
SwarmCloud | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ❌ |
|
|
23
23
|
|
|
24
24
|
## Usage
|
|
25
|
-
See [documentation](https://swarmcloud.net/en/views/hls/usage.html)
|
|
25
|
+
See [documentation](https://swarmcloud.net/en/views/hls-de/usage.html)
|
|
26
26
|
|
|
27
27
|
## Related Projects
|
|
28
28
|
- [android-p2p-engine](https://github.com/cdnbye/android-p2p-engine) - Live/VOD P2P Engine for Android and Android TV.
|
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,a;t=/^(?=((?:[a-zA-Z0-9+\-.]+:)?))\1(?=((?:\/\/[^\/?#]*)?))\2(?=((?:(?:[^?#\/]*\/)*[^;?#\/]*)?))\3((?:;[^?#]*)?)(\?[^#]*)?(#[^]*)?$/,r=/^(?=([^\/?#]*))\1([^]*)$/,n=/(?:\/|^)\.(?=\/)/g,o=/(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g,a={buildAbsoluteURL:function(e,t,n){if(n=n||{},e=e.trim(),!(t=t.trim())){if(!n.alwaysNormalize)return e;var o=a.parseURL(e);if(!o)throw new Error("Error trying to parse base URL.");return o.path=a.normalizePath(o.path),a.buildURLFromParts(o)}var i=a.parseURL(t);if(!i)throw new Error("Error trying to parse relative URL.");if(i.scheme)return n.alwaysNormalize?(i.path=a.normalizePath(i.path),a.buildURLFromParts(i)):t;var s=a.parseURL(e);if(!s)throw new Error("Error trying to parse base URL.");if(!s.netLoc&&s.path&&"/"!==s.path[0]){var u=r.exec(s.path);s.netLoc=u[1],s.path=u[2]}s.netLoc&&!s.path&&(s.path="/");var f={scheme:s.scheme,netLoc:i.netLoc,path:null,params:i.params,query:i.query,fragment:i.fragment};if(!i.netLoc&&(f.netLoc=s.netLoc,"/"!==i.path[0]))if(i.path){var l=s.path,c=l.substring(0,l.lastIndexOf("/")+1)+i.path;f.path=a.normalizePath(c)}else f.path=s.path,i.params||(f.params=s.params,i.query||(f.query=s.query));return null===f.path&&(f.path=n.alwaysNormalize?a.normalizePath(i.path):i.path),a.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=a},47:(e,t)=>{"use strict";t.l=o;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 s(e)}return a(e,t,r)}function a(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),a=n(r),i=a.write(e,t);i!==r&&(a=a.slice(0,i));return a}(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(h(e,ArrayBuffer)||e&&h(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 a=e.valueOf&&e.valueOf();if(null!=a&&a!==e)return o.from(a,t,r);var i=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||function(e){return e!=e}(e.length)?n(0):u(e);if("Buffer"===e.type&&Array.isArray(e.data))return u(e.data)}(e);if(i)return i;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 i(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 s(e){return i(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)||h(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 a=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return c(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;default:if(a)return n?-1:c(e).length;t=(""+t).toLowerCase(),a=!0}}function c(e,t){var r;t=t||1/0;for(var n=e.length,o=null,a=[],i=0;i<n;++i){if((r=e.charCodeAt(i))>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&a.push(239,191,189);continue}if(i+1===n){(t-=3)>-1&&a.push(239,191,189);continue}o=r;continue}if(r<56320){(t-=3)>-1&&a.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(t-=3)>-1&&a.push(239,191,189);if(o=null,r<128){if((t-=1)<0)break;a.push(r)}else if(r<2048){if((t-=2)<0)break;a.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;a.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;a.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return a}function h(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}"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 a(e,t,r)},o.prototype.__proto__=Uint8Array.prototype,o.__proto__=Uint8Array,o.alloc=function(e,t,r){return function(e,t,r){return i(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 s(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),a=0;for(r=0;r<e.length;++r){var i=e[r];if(h(i,Uint8Array)&&(i=o.from(i)),!o.isBuffer(i))throw new TypeError('"list" argument must be an Array of Buffers');i.copy(n,a),a+=i.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 a=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 i=a-1;i>=0;--i)e[i+t]=this[i+r];else Uint8Array.prototype.set.call(e,this.subarray(r,n),t);return a}}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var a=t[n]={exports:{}};return e[n].call(a.exports,a,a.exports,r),a.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_PIECE_NOT_FOUND:"PIECE_NOT_FOUND",DC_PIECE_ABORT:"PIECE_ABORT",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",SCH_DCHAVE:"SCH_DCHAVE",SW_PLAYLIST:"SW_PLAYLIST",SW_GET_PLAYLIST:"SW_GET_PLAYLIST",SW_MEDIA:"SW_MEDIA",SW_GET_MEDIA:"SW_GET_MEDIA",LEVEL_LOADED:"LEVEL_LOADED",MANIFEST_PARSED:"MANIFEST_PARSED",FRAG_LOADED:"FRAG_LOADED",SYN_OUTPUT:"SYN_OUTPUT",SYN_ERROR:"SYN_ERROR",SYN_PARTIAL:"SYN_PARTIAL"};var o=r(622);function a(e){const t=new Headers;return e&&t.set("range",e),t}var i=r(47);const s=["m3u8"],u=["ts","mp4","m4s"],f="#EXT-X-ENDLIST\n",l=.01;let c=!0,h=!1;const p=new Map,d=new class{constructor(){this.sendMessageToClient=this.sendMessageToClient.bind(this)}async sendMessageToClient(e,t,r){return e?new Promise(((n,o)=>{const a=new MessageChannel;let i;const s=(e,t)=>setTimeout((()=>{a.port1.close(),a.port2.close(),o(`MessageChannel ${t} timed out after ${e} ms`)}),e);a.port1.onmessage=function(e){const a=e.data;a?a.pong?(clearTimeout(i),i=s(r,`${t.action}-data`)):n({data:a.data}):o("no data in event")},a.port1.onmessageerror=function(e){o(e)},e.postMessage(t,[a.port2]),i=s(50,`${t.action}-pong`)})):Promise.reject("client is null")}};let E=!1,y=null,g=null,_=!0;class m{constructor(e={}){y=e.httpHeadersForPlaylist?e.httpHeadersForPlaylist:null,g=e.httpHeadersForMediaFile?e.httpHeadersForMediaFile:null,!1===e.insertTimeOffsetTag&&(_=!1),e.allowedMediaFiles&&e.allowedMediaFiles.length>0&&u.push(...e.allowedMediaFiles),e.allowedPlaylistSuffix&&e.allowedPlaylistSuffix.length>0&&s.push(...e.allowedPlaylistSuffix)}}self.addEventListener("install",(()=>{self.skipWaiting()})),self.addEventListener("activate",(e=>e.waitUntil(self.clients.claim()))),self.addEventListener("fetch",(function(r){const{request:n,clientId:m}=r;if("GET"!==n.method)return;const{url:w}=n,A=function(e){const t=o.parseURL(e);return t.path.substring(t.path.lastIndexOf(".")+1)}(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}=r,a=await clients.get(n);if(h&&a)try{const r=await d.sendMessageToClient(a,{action:t.SW_GET_PLAYLIST,data:{url:o}},200),{data:n}=r;if(n&&n.text){let{text:t}=n;return _&&!t.endsWith(f)&&(t=e.insertTimeOffsetTag(t,l)),new Response(t,{status:200,statusText:"OK",headers:{"Content-Type":"application/vnd.apple.mpegurl"}})}}catch(e){console.error(e)}let i;y&&(c&&console.info(`set additional header for ${o}`),i=new Headers,y(o,i,r.headers));return fetch(new Request(o,{mode:"cors",headers:i})).then((async r=>{if(r.ok&&a)try{const i=await r.clone().text();let s;r.redirected&&(c&&console.warn(`resp redirected to url ${r.url} `),s=r.url);const u=await d.sendMessageToClient(a,{action:t.SW_PLAYLIST,data:{url:o,redirectedUrl:s,ver:"2.2.2",text:i}},200),{data:E}=u;if(c=E&&E.debug,!E.active)return c&&console.warn("window client is not active"),p.delete(n),r;if(p.set(n,a),h=!!E.sharePlaylist,_&&!i.endsWith(f)){const t=e.insertTimeOffsetTag(i,l);return new Response(t,{status:200,statusText:"OK",headers:r.headers})}}catch(e){c&&console.warn(e),p.delete(n)}return r}))}(n,m));if(u.includes(A)){if(c&&console.info(`sw onFetch media ${w}`),E&&c&&console.warn("sw is loading"),p.has(m)){const{headers:e,url:o}=n;let s,u,f=e.get("range")||void 0;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])}}(f);s=e,u=t}catch(e){return void console.error(e)}if(0===s&&u===s)return;return r.respondWith(function(e,r,n,o,s,u){const f=(i=!1)=>{c&&console.info(`request ${e} from network`),E=!0;let s=a(o);return g&&(c&&console.info(`set additional header for ${e}`),g(e,s,r)),fetch(new Request(e,{headers:s,mode:"cors"})).then((async r=>(E=!1,!i&&r.ok&&n&&d.sendMessageToClient(n,{action:t.SW_MEDIA,data:{url:e,buffer:await r.clone().arrayBuffer(),range:o}},1e3).catch((e=>{c&&console.warn(e)})),r))).catch((e=>(E=!1,console.error(e),new Response(null,{status:502,statusText:"Hls Proxy Error"}))))};let l=!1;s||u?(s||u)&&(l=!0):(o=void 0,0===s&&void 0===u&&(c&&console.warn(`request ${e} with range 0-`),l=!0));return E=!0,d.sendMessageToClient(n,{action:t.SW_GET_MEDIA,data:{url:e,range:o}},9e3).then((async t=>{if(E=!1,t&&t.data&&(t.data.buffer||t.data.incomplete)){const{data:n}=t,{buffer:o,incomplete:h,bufferLeft:p,bufferRight:d,size:E}=n;let y;if(c&&console.info(`hit cache ${e}`),h?E&&(p||d)&&(y=await function(e,t,r,n,o,s,u,f){const l=u+(n?n.byteLength:0),h=function(e,t,r,n=0,o=0){let a="bytes=";return a=t?0===o?`${a}${n}-${r-1-t.byteLength}`:`${a}${n}-${o-t.byteLength}`:0===o?`${a}${n}-`:`${a}${n}-${o}`,a}(0,o,s,l,f);c&&console.warn(`continue download from ${t} range: ${h}`);let p=a(h);g&&(c&&console.info(`set additional header for ${t}`),g(t,p,r));return fetch(t,{headers:p,mode:"cors"}).then((e=>e.arrayBuffer())).then((e=>{let t=i.l.from(e),r=i.l.concat([n,t,o].filter((e=>!!e)));return new Uint8Array(r).buffer})).catch((e=>{console.error(`http partial download error ${e}`)}))}(0,e,r,p,d,E,s||0,u||0)):y=o,l&&y.byteLength!==u-s+1)return console.error("buffer size is not equal to range length "+(u-s+1)),f();const _={status:l?206:200,statusText:l?"Partial Content":"OK",headers:{"Accept-Ranges":"bytes","Content-Length":y.byteLength}};return l&&(_.headers["Content-Range"]=`bytes ${s}-${u}/${y.byteLength}`),new Response(y,_)}return f()})).catch((t=>(E=!1,c&&(console.warn(t),console.warn(`while requesting ${e}`)),f())))}(o,e,p.get(m),f,s,u))}c&&console.warn("windowClient not exist when get media")}})),m.version="2.2.2"})(),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={204:e=>{"use strict";var t,n="object"==typeof Reflect?Reflect:null,i=n&&"function"==typeof n.apply?n.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};t=n&&"function"==typeof n.ownKeys?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var r=Number.isNaN||function(e){return e!=e};function s(){s.init.call(this)}e.exports=s,e.exports.once=function(e,t){return new Promise((function(n,i){function r(n){e.removeListener(t,s),i(n)}function s(){"function"==typeof e.removeListener&&e.removeListener("error",r),n([].slice.call(arguments))}_(e,t,s,{once:!0}),"error"!==t&&function(e,t,n){"function"==typeof e.on&&_(e,"error",t,n)}(e,r,{once:!0})}))},s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var o=10;function a(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function c(e){return void 0===e._maxListeners?s.defaultMaxListeners:e._maxListeners}function l(e,t,n,i){var r,s,o,l;if(a(n),void 0===(s=e._events)?(s=e._events=Object.create(null),e._eventsCount=0):(void 0!==s.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),s=e._events),o=s[t]),void 0===o)o=s[t]=n,++e._eventsCount;else if("function"==typeof o?o=s[t]=i?[n,o]:[o,n]:i?o.unshift(n):o.push(n),(r=c(e))>0&&o.length>r&&!o.warned){o.warned=!0;var h=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");h.name="MaxListenersExceededWarning",h.emitter=e,h.type=t,h.count=o.length,l=h,console&&console.warn&&console.warn(l)}return e}function h(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function u(e,t,n){var i={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},r=h.bind(i);return r.listener=n,i.wrapFn=r,r}function d(e,t,n){var i=e._events;if(void 0===i)return[];var r=i[t];return void 0===r?[]:"function"==typeof r?n?[r.listener||r]:[r]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(r):p(r,r.length)}function f(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function p(e,t){for(var n=new Array(t),i=0;i<t;++i)n[i]=e[i];return n}function _(e,t,n,i){if("function"==typeof e.on)i.once?e.once(t,n):e.on(t,n);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function r(s){i.once&&e.removeEventListener(t,r),n(s)}))}}Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return o},set:function(e){if("number"!=typeof e||e<0||r(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");o=e}}),s.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},s.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||r(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},s.prototype.getMaxListeners=function(){return c(this)},s.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var r="error"===e,s=this._events;if(void 0!==s)r=r&&void 0===s.error;else if(!r)return!1;if(r){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var c=s[e];if(void 0===c)return!1;if("function"==typeof c)i(c,this,t);else{var l=c.length,h=p(c,l);for(n=0;n<l;++n)i(h[n],this,t)}return!0},s.prototype.addListener=function(e,t){return l(this,e,t,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(e,t){return l(this,e,t,!0)},s.prototype.once=function(e,t){return a(t),this.on(e,u(this,e,t)),this},s.prototype.prependOnceListener=function(e,t){return a(t),this.prependListener(e,u(this,e,t)),this},s.prototype.removeListener=function(e,t){var n,i,r,s,o;if(a(t),void 0===(i=this._events))return this;if(void 0===(n=i[e]))return this;if(n===t||n.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(r=-1,s=n.length-1;s>=0;s--)if(n[s]===t||n[s].listener===t){o=n[s].listener,r=s;break}if(r<0)return this;0===r?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,r),1===n.length&&(i[e]=n[0]),void 0!==i.removeListener&&this.emit("removeListener",e,o||t)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(e){var t,n,i;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var r,s=Object.keys(n);for(i=0;i<s.length;++i)"removeListener"!==(r=s[i])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(i=t.length-1;i>=0;i--)this.removeListener(e,t[i]);return this},s.prototype.listeners=function(e){return d(this,e,!0)},s.prototype.rawListeners=function(e){return d(this,e,!1)},s.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):f.call(e,t)},s.prototype.listenerCount=f,s.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]}},622:function(e){var t,n,i,r,s;t=/^(?=((?:[a-zA-Z0-9+\-.]+:)?))\1(?=((?:\/\/[^\/?#]*)?))\2(?=((?:(?:[^?#\/]*\/)*[^;?#\/]*)?))\3((?:;[^?#]*)?)(\?[^#]*)?(#[^]*)?$/,n=/^(?=([^\/?#]*))\1([^]*)$/,i=/(?:\/|^)\.(?=\/)/g,r=/(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g,s={buildAbsoluteURL:function(e,t,i){if(i=i||{},e=e.trim(),!(t=t.trim())){if(!i.alwaysNormalize)return e;var r=s.parseURL(e);if(!r)throw new Error("Error trying to parse base URL.");return r.path=s.normalizePath(r.path),s.buildURLFromParts(r)}var o=s.parseURL(t);if(!o)throw new Error("Error trying to parse relative URL.");if(o.scheme)return i.alwaysNormalize?(o.path=s.normalizePath(o.path),s.buildURLFromParts(o)):t;var a=s.parseURL(e);if(!a)throw new Error("Error trying to parse base URL.");if(!a.netLoc&&a.path&&"/"!==a.path[0]){var c=n.exec(a.path);a.netLoc=c[1],a.path=c[2]}a.netLoc&&!a.path&&(a.path="/");var l={scheme:a.scheme,netLoc:o.netLoc,path:null,params:o.params,query:o.query,fragment:o.fragment};if(!o.netLoc&&(l.netLoc=a.netLoc,"/"!==o.path[0]))if(o.path){var h=a.path,u=h.substring(0,h.lastIndexOf("/")+1)+o.path;l.path=s.normalizePath(u)}else l.path=a.path,o.params||(l.params=a.params,o.query||(l.query=a.query));return null===l.path&&(l.path=i.alwaysNormalize?s.normalizePath(o.path):o.path),s.buildURLFromParts(l)},parseURL:function(e){var n=t.exec(e);return n?{scheme:n[1]||"",netLoc:n[2]||"",path:n[3]||"",params:n[4]||"",query:n[5]||"",fragment:n[6]||""}:null},normalizePath:function(e){for(e=e.split("").reverse().join("").replace(i,"");e.length!==(e=e.replace(r,"")).length;);return e.split("").reverse().join("")},buildURLFromParts:function(e){return e.scheme+e.netLoc+e.path+e.params+e.query+e.fragment}},e.exports=s},47:(e,t)=>{"use strict";t.l=r;var n=2147483647;function i(e){if(e>n)throw new RangeError('The value "'+e+'" is invalid for option "size"');var t=new Uint8Array(e);return t.__proto__=r.prototype,t}function r(e,t,n){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 s(e,t,n)}function s(e,t,n){if("string"==typeof e)return function(e,t){"string"==typeof t&&""!==t||(t="utf8");if(!r.isEncoding(t))throw new TypeError("Unknown encoding: "+t);var n=0|h(e,t),s=i(n),o=s.write(e,t);o!==n&&(s=s.slice(0,o));return s}(e,t);if(ArrayBuffer.isView(e))return c(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,n){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(n||0))throw new RangeError('"length" is outside of buffer bounds');var i;i=void 0===t&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,t):new Uint8Array(e,t,n);return i.__proto__=r.prototype,i}(e,t,n);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');var s=e.valueOf&&e.valueOf();if(null!=s&&s!==e)return r.from(s,t,n);var o=function(e){if(r.isBuffer(e)){var t=0|l(e.length),n=i(t);return 0===n.length||e.copy(n,0,0,t),n}if(void 0!==e.length)return"number"!=typeof e.length||m(e.length)?i(0):c(e);if("Buffer"===e.type&&Array.isArray(e.data))return c(e.data)}(e);if(o)return o;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return r.from(e[Symbol.toPrimitive]("string"),t,n);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function o(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 o(e),i(e<0?0:0|l(e))}function c(e){for(var t=e.length<0?0:0|l(e.length),n=i(t),r=0;r<t;r+=1)n[r]=255&e[r];return n}function l(e){if(e>=n)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+n.toString(16)+" bytes");return 0|e}function h(e,t){if(r.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 n=e.length,i=arguments.length>2&&!0===arguments[2];if(!i&&0===n)return 0;for(var s=!1;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":return g(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;default:if(s)return i?-1:g(e).length;t=(""+t).toLowerCase(),s=!0}}function u(e,t,n,i){n=Number(n)||0;const r=e.length-n;i?(i=Number(i))>r&&(i=r):i=r;const s=t.length;let o;for(i>s/2&&(i=s/2),o=0;o<i;++o){const i=parseInt(t.substr(2*o,2),16);if(m(i))return o;e[n+o]=i}return o}function d(e,t,n,i){return _(g(t,e.length-n),e,n,i)}function f(e,t,n,i){return _(function(e){const t=[];for(let n=0;n<e.length;++n)t.push(255&e.charCodeAt(n));return t}(t),e,n,i)}function p(e,t,n,i){return _(function(e,t){let n,i,r;const s=[];for(let o=0;o<e.length&&!((t-=2)<0);++o)n=e.charCodeAt(o),i=n>>8,r=n%256,s.push(r),s.push(i);return s}(t,e.length-n),e,n,i)}function _(e,t,n,i){let r;for(r=0;r<i&&!(r+n>=t.length||r>=e.length);++r)t[r+n]=e[r];return r}function g(e,t){var n;t=t||1/0;for(var i=e.length,r=null,s=[],o=0;o<i;++o){if((n=e.charCodeAt(o))>55295&&n<57344){if(!r){if(n>56319){(t-=3)>-1&&s.push(239,191,189);continue}if(o+1===i){(t-=3)>-1&&s.push(239,191,189);continue}r=n;continue}if(n<56320){(t-=3)>-1&&s.push(239,191,189),r=n;continue}n=65536+(r-55296<<10|n-56320)}else r&&(t-=3)>-1&&s.push(239,191,189);if(r=null,n<128){if((t-=1)<0)break;s.push(n)}else if(n<2048){if((t-=2)<0)break;s.push(n>>6|192,63&n|128)}else if(n<65536){if((t-=3)<0)break;s.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;s.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return s}function y(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function m(e){return e!=e}"undefined"!=typeof Symbol&&null!=Symbol.species&&r[Symbol.species]===r&&Object.defineProperty(r,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),r.from=function(e,t,n){return s(e,t,n)},r.prototype.__proto__=Uint8Array.prototype,r.__proto__=Uint8Array,r.alloc=function(e,t,n){return function(e,t,n){return o(e),e<=0?i(e):void 0!==t?"string"==typeof n?i(e).fill(t,n):i(e).fill(t):i(e)}(e,t,n)},r.allocUnsafe=function(e){return a(e)},r.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==r.prototype},r.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}},r.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return r.alloc(0);var n;if(void 0===t)for(t=0,n=0;n<e.length;++n)t+=e[n].length;var i=r.allocUnsafe(t),s=0;for(n=0;n<e.length;++n){var o=e[n];if(y(o,Uint8Array)&&(o=r.from(o)),!r.isBuffer(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(i,s),s+=o.length}return i},r.byteLength=h,r.prototype._isBuffer=!0,r.prototype.copy=function(e,t,n,i){if(!r.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),i||0===i||(i=this.length),t>=e.length&&(t=e.length),t||(t=0),i>0&&i<n&&(i=n),i===n)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-t<i-n&&(i=e.length-t+n);var s=i-n;if(this===e&&"function"==typeof Uint8Array.prototype.copyWithin)this.copyWithin(t,n,i);else if(this===e&&n<t&&t<i)for(var o=s-1;o>=0;--o)e[o+t]=this[o+n];else Uint8Array.prototype.set.call(e,this.subarray(n,i),t);return s},r.prototype.write=function(e,t,n,i){if(void 0===t)i="utf8",n=this.length,t=0;else if(void 0===n&&"string"==typeof t)i=t,n=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(n)?(n>>>=0,void 0===i&&(i="utf8")):(i=n,n=void 0)}const r=this.length-t;if((void 0===n||n>r)&&(n=r),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let s=!1;for(;;)switch(i){case"hex":return u(this,e,t,n);case"utf8":case"utf-8":return d(this,e,t,n);case"ascii":case"latin1":case"binary":return f(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return p(this,e,t,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}}},422:e=>{const t={ANDROID_WEB:"android-web",IOS_WEB:"iOS-web",PC_NATIVE:"PC-native",PC_WEB:"PC-web"};var n={getNetType:function(){let e=(new RegExp("nettype\\/(\\w*)").exec(i())||[,""])[1].toLowerCase();if(!e&&navigator.connection){switch(navigator.connection.type){case"ethernet":e="ethernet";break;case"cellular":e="cellular";break;default:e="wifi"}}return e},getPlatform:function(){return n.isAndroid()?t.ANDROID_WEB:n.isIOS()?t.IOS_WEB:n.isElectron()?t.PC_NATIVE:t.PC_WEB},isX5:function(){return this.isAndroid()&&/\s(TBS|X5Core)\/[\w\.\-]+/i.test(i())},isPC:function(){return!s(r("os "))&&!s(r("android[/ ]"))},isIOS:function(){return s(r("os "))},isAndroid:function(){return s(r("android[/ ]"))},isIOSSafari:function(){return this.isIOS()&&this.isSafari()},isElectron:function(){return/electron/i.test(i())},isMobile:function(){return n.isAndroid()||n.isIOS()},isSafari:function(){return/^((?!chrome|android).)*safari/i.test(i())},isFirefox:function(){return/firefox/i.test(i())},isChrome:function(){return/chrome/i.test(i())},isLocalHost:function(){return"localhost"===location.hostname},device:t,getBrowser:function(){return n.isX5()?"X5":n.isChrome()?"Chrome":n.isFirefox()?"Firefox":n.isIOSSafari()?"iOS-Safari":n.isSafari()?"Mac-Safari":"Unknown"}};function i(){return navigator.userAgent.toLowerCase()}function r(e){return""+(new RegExp(e+"(\\d+((\\.|_)\\d+)*)").exec(i())||[,0])[1]||void 0}function s(e){return parseFloat((e||"").replace(/\_/g,"."))||0}e.exports=n},77:e=>{let t;e.exports="function"==typeof queueMicrotask?queueMicrotask.bind(globalThis):e=>(t||(t=Promise.resolve())).then(e).catch((e=>setTimeout((()=>{throw e}),0)))}},t={};function n(i){var r=t[i];if(void 0!==r)return r.exports;var s=t[i]={exports:{}};return e[i].call(s.exports,s,s.exports,n),s.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var i={};return(()=>{"use strict";n.d(i,{default:()=>T});class e{static insertTimeOffsetTag(e,t){const n=e.split("\n");for(let e=0;e<n.length;e++)if(n[e].startsWith("#EXT-X-VERSION")){n[e]=`${n[e]}\n#EXT-X-START:TIME-OFFSET=${t}`;break}return n.join("\n")}}const t={DC_SIGNAL:"SIGNAL",DC_OPEN:"OPEN",DC_REQUEST:"REQUEST",DC_PIECE_NOT_FOUND:"PIECE_NOT_FOUND",DC_PIECE_ABORT:"PIECE_ABORT",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",SCH_DCHAVE:"SCH_DCHAVE",REQUESTING_MAP_HAVE:"REQUESTING_MAP_HAVE",SW_PLAYLIST:"SW_PLAYLIST",SW_GET_PLAYLIST:"SW_GET_PLAYLIST",SW_MEDIA:"SW_MEDIA",SW_GET_MEDIA:"SW_GET_MEDIA",LEVEL_LOADED:"LEVEL_LOADED",MANIFEST_PARSED:"MANIFEST_PARSED",FRAG_LOADED:"FRAG_LOADED",SYN_OUTPUT:"SYN_OUTPUT",SYN_ERROR:"SYN_ERROR",SYN_PARTIAL:"SYN_PARTIAL"};var r=n(622);function s(e){const t=new Headers;return e&&t.set("range",e),t}var o=n(47);var a=n(204),c=n.n(a),l=n(77),h=n.n(l);function u(e){return e.replace(/a=ice-options:trickle\s\n/g,"")}class d extends(c()){constructor(e){super(),this.channelName=e.initiator?e.channelName:null,this.initiator=e.initiator||!1,this.channelConfig=e.channelConfig||d.channelConfig,this.channelNegotiated=this.channelConfig.negotiated,this.config=Object.assign({},d.config,e.config),this.offerOptions=e.offerOptions||{},this.answerOptions=e.answerOptions||{},this.sdpTransform=e.sdpTransform||(e=>e),this.trickle=void 0===e.trickle||e.trickle,this.allowHalfTrickle=void 0!==e.allowHalfTrickle&&e.allowHalfTrickle,this.iceCompleteTimeout=e.iceCompleteTimeout||5e3,this.destroyed=!1,this.destroying=!1,this._connected=!1,this.remoteAddress=void 0,this.remoteFamily=void 0,this.remotePort=void 0,this.localAddress=void 0,this.localFamily=void 0,this.localPort=void 0,this._wrtc=e.wrtc&&"object"==typeof e.wrtc?e.wrtc:function(){if("undefined"==typeof window)return null;var e={RTCPeerConnection:window.RTCPeerConnection||window.mozRTCPeerConnection||window.webkitRTCPeerConnection,RTCSessionDescription:window.RTCSessionDescription||window.mozRTCSessionDescription||window.webkitRTCSessionDescription,RTCIceCandidate:window.RTCIceCandidate||window.mozRTCIceCandidate||window.webkitRTCIceCandidate};return e.RTCPeerConnection?e:null}(),this._pcReady=!1,this._channelReady=!1,this._iceComplete=!1,this._iceCompleteTimer=null,this._channel=null,this._pendingCandidates=[],this._isNegotiating=!1,this._firstNegotiation=!0,this._batchedNegotiation=!1,this._queuedNegotiation=!1,this._sendersAwaitingStable=[],this._senderMap=new Map,this._closingInterval=null,this._remoteTracks=[],this._remoteStreams=[],this._chunk=null,this._cb=null,this._interval=null;try{this._pc=new this._wrtc.RTCPeerConnection(this.config)}catch(e){return void h()((()=>this.destroy(e)))}this._isReactNativeWebrtc="number"==typeof this._pc._peerConnectionId,this._pc.oniceconnectionstatechange=()=>{this._onIceStateChange()},this._pc.onicegatheringstatechange=()=>{this._onIceStateChange()},this._pc.onconnectionstatechange=()=>{this._onConnectionStateChange()},this._pc.onsignalingstatechange=()=>{this._onSignalingStateChange()},this._pc.onicecandidate=e=>{this._onIceCandidate(e)},this.initiator||this.channelNegotiated?this._setupData({channel:this._pc.createDataChannel(this.channelName,this.channelConfig)}):this._pc.ondatachannel=e=>{this._setupData(e)},this._needsNegotiation()}get bufferSize(){return this._channel&&this._channel.bufferedAmount||0}get connected(){return this._connected&&"open"===this._channel.readyState}signal(e){if(this.destroyed)throw new Error("cannot signal after peer is destroyed");if("string"==typeof e)try{e=JSON.parse(e)}catch(t){e={}}e.renegotiate&&this.initiator&&this._needsNegotiation(),e.transceiverRequest&&this.initiator&&this.addTransceiver(e.transceiverRequest.kind,e.transceiverRequest.init),e.candidate&&(this._pc.remoteDescription&&this._pc.remoteDescription.type?this._addIceCandidate(e.candidate):this._pendingCandidates.push(e.candidate)),e.sdp&&this._pc.setRemoteDescription(new this._wrtc.RTCSessionDescription(e)).then((()=>{this.destroyed||(this._pendingCandidates.forEach((e=>{this._addIceCandidate(e)})),this._pendingCandidates=[],"offer"===this._pc.remoteDescription.type&&this._createAnswer())})).catch((e=>{this.destroy(e)})),e.sdp||e.candidate||e.renegotiate||e.transceiverRequest||this.destroy(new Error("signal() called with invalid signal data"))}_addIceCandidate(e){const t=new this._wrtc.RTCIceCandidate(e);this._pc.addIceCandidate(t).catch((e=>{var n;!t.address||t.address.endsWith(".local")?(n="Ignoring unsupported ICE candidate.",console.warn(n)):this.destroy(e)}))}send(e){this._channel.send(e)}addTransceiver(e,t){if(this.initiator)try{this._pc.addTransceiver(e,t),this._needsNegotiation()}catch(e){this.destroy(e)}else this.emit("signal",{type:"transceiverRequest",transceiverRequest:{kind:e,init:t}})}_needsNegotiation(){this._batchedNegotiation||(this._batchedNegotiation=!0,h()((()=>{this._batchedNegotiation=!1,!this.initiator&&this._firstNegotiation||this.negotiate(),this._firstNegotiation=!1})))}negotiate(){this.initiator?this._isNegotiating?this._queuedNegotiation=!0:setTimeout((()=>{this._createOffer()}),0):this._isNegotiating?this._queuedNegotiation=!0:this.emit("signal",{type:"renegotiate",renegotiate:!0}),this._isNegotiating=!0}destroy(e){this._destroy(e,(()=>{}))}_destroy(e,t){this.destroyed||this.destroying||(this.destroying=!0,h()((()=>{if(this.destroyed=!0,this.destroying=!1,this._connected=!1,this._pcReady=!1,this._channelReady=!1,this._remoteTracks=null,this._remoteStreams=null,this._senderMap=null,clearInterval(this._closingInterval),this._closingInterval=null,clearInterval(this._interval),this._interval=null,this._chunk=null,this._cb=null,this._channel){try{this._channel.close()}catch(e){}this._channel.onmessage=null,this._channel.onopen=null,this._channel.onclose=null,this._channel.onerror=null}if(this._pc){try{this._pc.close()}catch(e){}this._pc.oniceconnectionstatechange=null,this._pc.onicegatheringstatechange=null,this._pc.onsignalingstatechange=null,this._pc.onicecandidate=null,this._pc.ontrack=null,this._pc.ondatachannel=null}this._pc=null,this._channel=null,e&&this.emit("error",e),this.emit("close")})))}_setupData(e){if(!e.channel)return this.destroy(new Error("Data channel event is missing `channel` property"));this._channel=e.channel,this._channel.binaryType="arraybuffer","number"==typeof this._channel.bufferedAmountLowThreshold&&(this._channel.bufferedAmountLowThreshold=65536),this.channelName=this._channel.label,this._channel.onmessage=e=>{this._onChannelMessage(e)},this._channel.onbufferedamountlow=()=>{this._onChannelBufferedAmountLow()},this._channel.onopen=()=>{this._onChannelOpen()},this._channel.onclose=()=>{this._onChannelClose()},this._channel.onerror=e=>{this.destroy(e)};let t=!1;this._closingInterval=setInterval((()=>{this._channel&&"closing"===this._channel.readyState?(t&&this._onChannelClose(),t=!0):t=!1}),5e3)}_startIceCompleteTimeout(){this.destroyed||this._iceCompleteTimer||(this._iceCompleteTimer=setTimeout((()=>{this._iceComplete||(this._iceComplete=!0,this.emit("iceTimeout"),this.emit("_iceComplete"))}),this.iceCompleteTimeout))}_createOffer(){this.destroyed||this._pc.createOffer(this.offerOptions).then((e=>{if(this.destroyed)return;this.trickle||this.allowHalfTrickle||(e.sdp=u(e.sdp)),e.sdp=this.sdpTransform(e.sdp);const t=()=>{if(this.destroyed)return;const t=this._pc.localDescription||e;this.emit("signal",{type:t.type,sdp:t.sdp})};this._pc.setLocalDescription(e).then((()=>{this.destroyed||(this.trickle||this._iceComplete?t():this.once("_iceComplete",t))})).catch((e=>{this.destroy(e)}))})).catch((e=>{this.destroy(e)}))}_requestMissingTransceivers(){this._pc.getTransceivers&&this._pc.getTransceivers().forEach((e=>{e.mid||!e.sender.track||e.requested||(e.requested=!0,this.addTransceiver(e.sender.track.kind))}))}_createAnswer(){this.destroyed||this._pc.createAnswer(this.answerOptions).then((e=>{if(this.destroyed)return;this.trickle||this.allowHalfTrickle||(e.sdp=u(e.sdp)),e.sdp=this.sdpTransform(e.sdp);const t=()=>{if(this.destroyed)return;const t=this._pc.localDescription||e;this.emit("signal",{type:t.type,sdp:t.sdp}),this.initiator||this._requestMissingTransceivers()};this._pc.setLocalDescription(e).then((()=>{this.destroyed||(this.trickle||this._iceComplete?t():this.once("_iceComplete",t))})).catch((e=>{this.destroy(e)}))})).catch((e=>{this.destroy(e)}))}_onConnectionStateChange(){this.destroyed||"failed"===this._pc.connectionState&&this.destroy(new Error("Connection failed."))}_onIceStateChange(){if(this.destroyed)return;const e=this._pc.iceConnectionState,t=this._pc.iceGatheringState;this.emit("iceStateChange",e,t),"connected"!==e&&"completed"!==e||(this._pcReady=!0,this._maybeReady()),"failed"===e&&this.destroy(new Error("Ice connection failed.")),"closed"===e&&this.destroy(new Error("Ice connection closed."))}getStats(e){const t=e=>("[object Array]"===Object.prototype.toString.call(e.values)&&e.values.forEach((t=>{Object.assign(e,t)})),e);0===this._pc.getStats.length||this._isReactNativeWebrtc?this._pc.getStats().then((n=>{const i=[];n.forEach((e=>{i.push(t(e))})),e(null,i)}),(t=>e(t))):this._pc.getStats.length>0?this._pc.getStats((n=>{if(this.destroyed)return;const i=[];n.result().forEach((e=>{const n={};e.names().forEach((t=>{n[t]=e.stat(t)})),n.id=e.id,n.type=e.type,n.timestamp=e.timestamp,i.push(t(n))})),e(null,i)}),(t=>e(t))):e(null,[])}_maybeReady(){if(this._connected||this._connecting||!this._pcReady||!this._channelReady)return;this._connecting=!0;const e=()=>{this.destroyed||this.getStats(((t,n)=>{if(this.destroyed)return;t&&(n=[]);const i={},r={},s={};let o=!1;n.forEach((e=>{"remotecandidate"!==e.type&&"remote-candidate"!==e.type||(i[e.id]=e),"localcandidate"!==e.type&&"local-candidate"!==e.type||(r[e.id]=e),"candidatepair"!==e.type&&"candidate-pair"!==e.type||(s[e.id]=e)}));const a=e=>{o=!0;let t=r[e.localCandidateId];t&&(t.ip||t.address)?(this.localAddress=t.ip||t.address,this.localPort=Number(t.port)):t&&t.ipAddress?(this.localAddress=t.ipAddress,this.localPort=Number(t.portNumber)):"string"==typeof e.googLocalAddress&&(t=e.googLocalAddress.split(":"),this.localAddress=t[0],this.localPort=Number(t[1])),this.localAddress&&(this.localFamily=this.localAddress.includes(":")?"IPv6":"IPv4");let n=i[e.remoteCandidateId];n&&(n.ip||n.address)?(this.remoteAddress=n.ip||n.address,this.remotePort=Number(n.port)):n&&n.ipAddress?(this.remoteAddress=n.ipAddress,this.remotePort=Number(n.portNumber)):"string"==typeof e.googRemoteAddress&&(n=e.googRemoteAddress.split(":"),this.remoteAddress=n[0],this.remotePort=Number(n[1])),this.remoteAddress&&(this.remoteFamily=this.remoteAddress.includes(":")?"IPv6":"IPv4")};if(n.forEach((e=>{"transport"===e.type&&e.selectedCandidatePairId&&a(s[e.selectedCandidatePairId]),("googCandidatePair"===e.type&&"true"===e.googActiveConnection||("candidatepair"===e.type||"candidate-pair"===e.type)&&e.selected)&&a(e)})),o||Object.keys(s).length&&!Object.keys(r).length){if(this._connecting=!1,this._connected=!0,this._chunk){try{this.send(this._chunk)}catch(t){return this.destroy(t)}this._chunk=null;const e=this._cb;this._cb=null,e(null)}"number"!=typeof this._channel.bufferedAmountLowThreshold&&(this._interval=setInterval((()=>this._onInterval()),150),this._interval.unref&&this._interval.unref()),this.emit("connect")}else setTimeout(e,100)}))};e()}_onInterval(){!this._cb||!this._channel||this._channel.bufferedAmount>65536||this._onChannelBufferedAmountLow()}_onSignalingStateChange(){this.destroyed||("stable"===this._pc.signalingState&&(this._isNegotiating=!1,this._sendersAwaitingStable.forEach((e=>{this._pc.removeTrack(e),this._queuedNegotiation=!0})),this._sendersAwaitingStable=[],this._queuedNegotiation?(this._queuedNegotiation=!1,this._needsNegotiation()):this.emit("negotiated")),this.emit("signalingStateChange",this._pc.signalingState))}_onIceCandidate(e){this.destroyed||(e.candidate&&this.trickle?this.emit("signal",{type:"candidate",candidate:{candidate:e.candidate.candidate,sdpMLineIndex:e.candidate.sdpMLineIndex,sdpMid:e.candidate.sdpMid}}):e.candidate||this._iceComplete||(this._iceComplete=!0,this.emit("_iceComplete")),e.candidate&&this._startIceCompleteTimeout())}_onChannelMessage(e){if(this.destroyed)return;let t=e.data;t instanceof ArrayBuffer&&(t=o.l.from(t)),this.emit("data",t)}_onChannelBufferedAmountLow(){if(this.destroyed||!this._cb)return;const e=this._cb;this._cb=null,e(null)}_onChannelOpen(){this._connected||this.destroyed||(this._channelReady=!0,this._maybeReady())}_onChannelClose(){this.destroyed||this.destroy()}}d.config={iceServers:[{urls:["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478"]}],sdpSemantics:"unified-plan"},d.channelConfig={};n(422);const f=["m3u8"],p=["ts","mp4","m4s"],_="#EXT-X-ENDLIST\n",g=.01;let y=!1,m=!1;const v=new Map,w=new class{constructor(){this.sendMessageToClient=this.sendMessageToClient.bind(this)}async sendMessageToClient(e,t,n){return e?new Promise(((i,r)=>{const s=new MessageChannel;let o;const a=(e,t)=>setTimeout((()=>{s.port1.close(),s.port2.close(),r(`MessageChannel ${t} timed out after ${e} ms`)}),e);s.port1.onmessage=function(e){const s=e.data;s?s.pong?(clearTimeout(o),o=a(n,`${t.action}-data`)):i({data:s.data}):r("no data in event")},s.port1.onmessageerror=function(e){r(e)},e.postMessage(t,[s.port2]),o=a(50,`${t.action}-pong`)})):Promise.reject("client is null")}};let E=!1,C=null,b=null,A=!0;class T{constructor(e={}){C=e.httpHeadersForPlaylist?e.httpHeadersForPlaylist:null,b=e.httpHeadersForMediaFile?e.httpHeadersForMediaFile:null,!1===e.insertTimeOffsetTag&&(A=!1),e.allowedMediaFiles&&e.allowedMediaFiles.length>0&&p.push(...e.allowedMediaFiles),e.allowedPlaylistSuffix&&e.allowedPlaylistSuffix.length>0&&f.push(...e.allowedPlaylistSuffix)}}self.addEventListener("install",(()=>{self.skipWaiting()})),self.addEventListener("activate",(e=>e.waitUntil(self.clients.claim()))),self.addEventListener("fetch",(function(n){const{request:i,clientId:a}=n;if("GET"!==i.method)return;const{url:c}=i,l=function(e){const t=r.parseURL(e);return t.path.substring(t.path.lastIndexOf(".")+1)}(c);if(f.includes(l))return y&&console.info(`sw onFetch playlist ${c}`),n.respondWith(async function(n,i){v.size>50&&v.clear();const{url:r}=n,s=await clients.get(i);if(m&&s)try{const n=await w.sendMessageToClient(s,{action:t.SW_GET_PLAYLIST,data:{url:r}},200),{data:i}=n;if(i&&i.text){let{text:t}=i;return A&&!t.endsWith(_)&&(t=e.insertTimeOffsetTag(t,g)),new Response(t,{status:200,statusText:"OK",headers:{"Content-Type":"application/vnd.apple.mpegurl"}})}}catch(e){console.error(e)}let o;C&&(y&&console.info(`set additional header for ${r}`),o=new Headers,C(r,o,n.headers));return fetch(new Request(r,{mode:"cors",headers:o})).then((async n=>{if(n.ok&&s)try{const o=await n.clone().text();let a;n.redirected&&(y&&console.warn(`resp redirected to url ${n.url} `),a=n.url);const c=await w.sendMessageToClient(s,{action:t.SW_PLAYLIST,data:{url:r,redirectedUrl:a,ver:"2.2.8",text:o}},200),{data:l}=c;if(y=l&&l.debug,!l.active)return y&&console.warn("window client is not active"),v.delete(i),n;if(v.set(i,s),m=!!l.sharePlaylist,A&&!o.endsWith(_)){const t=e.insertTimeOffsetTag(o,g);return new Response(t,{status:200,statusText:"OK",headers:n.headers})}}catch(e){y&&console.warn(e),v.delete(i)}return n}))}(i,a));if(p.includes(l)){if(y&&console.info(`sw onFetch media ${c}`),E&&y&&console.warn("sw is loading"),v.has(a)){const{headers:e,url:r}=i;let c,l,h=e.get("range")||void 0;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 n=/(\d*)-(\d*)/.exec(t);if(!n||!n[1]&&!n[2])throw new Error("invalid-range-values",{normalizedRangeHeader:t});return{start:""===n[1]?void 0:Number(n[1]),end:""===n[2]?void 0:Number(n[2])}}(h);c=e,l=t}catch(e){return void console.error(e)}if(0===c&&l===c)return;return n.respondWith(function(e,n,i,r,a,c){const l=(o=!1)=>{y&&console.info(`request ${e} from network`),E=!0;let a=s(r);return b&&(y&&console.info(`set additional header for ${e}`),b(e,a,n)),fetch(new Request(e,{headers:a,mode:"cors"})).then((async n=>(E=!1,!o&&n.ok&&i&&w.sendMessageToClient(i,{action:t.SW_MEDIA,data:{url:e,buffer:await n.clone().arrayBuffer(),range:r}},1e3).catch((e=>{y&&console.warn(e)})),n))).catch((e=>(E=!1,console.error(e),new Response(null,{status:502,statusText:"Hls Proxy Error"}))))};let h=!1;a||c?(a||c)&&(h=!0):(r=void 0,0===a&&void 0===c&&(y&&console.warn(`request ${e} with range 0-`),h=!0));return E=!0,w.sendMessageToClient(i,{action:t.SW_GET_MEDIA,data:{url:e,range:r}},9e3).then((async t=>{if(E=!1,t&&t.data&&(t.data.buffer||t.data.incomplete)){const{data:i}=t,{buffer:r,incomplete:u,bufferLeft:d,bufferRight:f,size:p}=i;let _;if(y&&console.info(`hit cache ${e}`),u?p&&(d||f)&&(_=await function(e,t,n,i,r,a,c,l){const h=c+(i?i.byteLength:0),u=function(e,t,n,i=0,r=0){let s="bytes=";return s=t?0===r?`${s}${i}-${n-1-t.byteLength}`:`${s}${i}-${r-t.byteLength}`:0===r?`${s}${i}-`:`${s}${i}-${r}`,s}(0,r,a,h,l);y&&console.warn(`continue download from ${t} range: ${u}`);let d=s(u);b&&(y&&console.info(`set additional header for ${t}`),b(t,d,n));return fetch(t,{headers:d,mode:"cors"}).then((e=>e.arrayBuffer())).then((e=>{let t=o.l.from(e);return o.l.concat([i,t,r].filter((e=>!!e))).buffer})).catch((e=>{console.error(`http partial download error ${e}`)}))}(0,e,n,d,f,p,a||0,c||0)):_=r,h&&_.byteLength!==c-a+1)return console.error("buffer size is not equal to range length "+(c-a+1)),l();const g={status:h?206:200,statusText:h?"Partial Content":"OK",headers:{"Accept-Ranges":"bytes","Content-Length":_.byteLength}};return h&&(g.headers["Content-Range"]=`bytes ${a}-${c}/${_.byteLength}`),new Response(_,g)}return l()})).catch((t=>(E=!1,y&&(console.warn(t),console.warn(`while requesting ${e}`)),l())))}(r,e,v.get(a),h,c,l))}y&&console.warn("windowClient not exist when get media")}})),T.version="2.2.8"})(),i=i.default})()));
|