@vknext/shared 1.5.2 → 1.5.3
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
class e{sw=null;scope;swUrl;messages=[];keepAliveInterval;constructor(e){this.swUrl=e.swUrl,this.init()}init(){window.onmessage=e=>this.messages.push(e),window.opener&&window.opener.postMessage("VKNext/StreamSaver::loadedPopup","*"),navigator.serviceWorker&&this.registerWorker().then((()=>{window.onmessage=e=>this.onMessage(e),this.messages.forEach((e=>this.onMessage(e))),this.messages=[]})),this.keepAlive()}keepAlive(){if(this.keepAliveInterval)return;const e=location.href.substring(0,location.href.lastIndexOf("/"))+"/ping";this.keepAliveInterval=window.setInterval((()=>{this.sw?this.sw.postMessage("ping"):fetch(e).then((e=>(!e.ok&&this.keepAliveInterval&&clearInterval(this.keepAliveInterval),e.text())))}),1e4)}registerWorker(){return navigator.serviceWorker.getRegistration("./").then((e=>e
|
|
1
|
+
class e{sw=null;scope;swUrl;messages=[];keepAliveInterval;constructor(e){this.swUrl=e.swUrl,this.init()}init(){window.onmessage=e=>this.messages.push(e),window.opener&&window.opener.postMessage("VKNext/StreamSaver::loadedPopup","*"),navigator.serviceWorker&&this.registerWorker().then((()=>{window.onmessage=e=>this.onMessage(e),this.messages.forEach((e=>this.onMessage(e))),this.messages=[]})),this.keepAlive()}keepAlive(){if(this.keepAliveInterval)return;const e=location.href.substring(0,location.href.lastIndexOf("/"))+"/ping";this.keepAliveInterval=window.setInterval((()=>{this.sw?this.sw.postMessage("ping"):fetch(e).then((e=>(!e.ok&&this.keepAliveInterval&&clearInterval(this.keepAliveInterval),e.text())))}),1e4)}registerWorker(){return navigator.serviceWorker.getRegistration("./").then((e=>e&&e?.active?.scriptURL===this.swUrl?e:navigator.serviceWorker.register(this.swUrl))).then((e=>{const t=e.installing||e.waiting;return this.scope=e.scope,(this.sw=e.active)?Promise.resolve():new Promise((a=>{if(!t)return void a();const r=()=>{"activated"===t.state&&(t.removeEventListener("statechange",r),this.sw=e.active,a())};t.addEventListener("statechange",r)}))}))}onMessage(e){let{data:t,ports:a,origin:r}=e;if(!a||!a.length)throw new TypeError("[VK Next/StreamSaver] You didn't send a messageChannel");if("object"!=typeof t)throw new TypeError("[VK Next/StreamSaver] You didn't send a object");const s=t;s.origin=r,s.referrer=s.referrer||document.referrer||r,s.headers?new Headers(s.headers):console.warn("[VK Next/StreamSaver] pass `data.headers`..."),"string"==typeof s.filename&&(console.warn("[VK Next/StreamSaver] You shouldn't send `data.filename` anymore..."),s.filename=s.filename.replace(/\//g,":")),s.size&&console.warn("[VK Next/StreamSaver] You shouldn't send `data.size` anymore..."),s.readableStream&&console.warn("[VK Next/StreamSaver] You should send the readableStream in the messageChannel..."),s.pathname||(console.warn("[VK Next/StreamSaver] Please send `data.pathname`"),s.pathname=Math.random().toString().slice(-6)+"/"+s.filename),s.pathname=s.pathname.replace(/^\/+/g,"");let n=r.replace(/(^\w+:|^)\/\//,"");if(s.url=new URL(`${this.scope+n}/${s.pathname}`).toString(),!s.url.startsWith(`${this.scope+n}/`))throw new TypeError("[StreamSaver] bad `data.pathname`");const i=s.readableStream?[a[0],s.readableStream]:[a[0]];s.readableStream||s.transferringReadable||this.keepAlive(),this.sw&&this.sw.postMessage(s,i)}}export{e as StreamSaverMitm};
|