@vknext/shared 1.6.8 → 1.6.10
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
|
-
const e=self;e.addEventListener("install",(()=>{e.skipWaiting()})),e.addEventListener("activate",(t=>{t.waitUntil(e.clients.claim())}));const t=new Map;e.addEventListener("message",(n=>{const
|
|
1
|
+
const e=self;e.addEventListener("install",(()=>{e.skipWaiting()})),e.addEventListener("activate",(t=>{t.waitUntil(e.clients.claim())}));const t=new Map;e.addEventListener("message",(n=>{const o=n.data;if("ping"===o)return;const s=o,a=s.url||e.registration.scope+Math.random()+"/"+("string"==typeof s?s:s.filename),r=n.ports[0],i=[null,s,r];s.readableStream?i[0]=s.readableStream:s.transferringReadable?r.onmessage=e=>{r.onmessage=null,i[0]=e.data.readableStream}:i[0]=function(e){return new ReadableStream({start(n){e.onmessage=({data:e})=>"end"===e?n.close():"abort"===e?(n.error("Aborted the download"),void(e.pathname&&t.delete(e.pathname))):void n.enqueue(e)},cancel(t){console.log("user aborted",t),e.postMessage({abort:!0})}})}(r),t.set(a,i),r.postMessage({download:a,filename:"string"==typeof s?s:s.filename})})),e.addEventListener("fetch",(e=>{const n=e.request.url;if(n.endsWith("/ping"))return e.respondWith(new Response("pong"));const o=t.get(n);if(!o)return null;const[s,a,r]=o;t.delete(n);const i=new Headers({"Content-Type":"application/octet-stream; charset=utf-8","Content-Security-Policy":"default-src 'none'","X-Content-Security-Policy":"default-src 'none'","X-WebKit-CSP":"default-src 'none'","X-XSS-Protection":"1; mode=block","Cross-Origin-Embedder-Policy":"require-corp"}),d=new Headers(a.headers||{});d.has("Content-Length")&&i.set("Content-Length",d.get("Content-Length")),d.has("Content-Disposition")&&i.set("Content-Disposition",d.get("Content-Disposition")),a.size&&(console.warn("Depricated"),i.set("Content-Length",String(a.size)));let l="string"==typeof a?a:a.filename;l&&(console.warn("Depricated"),l=encodeURIComponent(l).replace(/['()]/g,escape).replace(/\*/g,"%2A"),i.set("Content-Disposition","attachment; filename*=UTF-8''"+l)),e.respondWith(new Response(s,{headers:i})),r.postMessage({debug:"Download started"})}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getHlsInstance as e}from"./utils/getHlsInstance.js";import{sendMessage as r}from"./utils/sendMessage.js";const o=async({url:o,filename:n,onProgress:t,forceHls:a})=>{if(!a)try{const e=await r({url:o,filename:n,type:"convertHlsToMp3",onProgress:t});if(e instanceof ReadableStream)return e;if(e instanceof Blob)return e.stream();if("stream"in e)return e.stream();throw new Error("Invalid response")}catch(e){console.error(e)}const s=await e();let i=null,l=null,d=!1;const f=()=>{i&&(i.stopLoad(),i.destroy())};return new ReadableStream({start(e){i=new s({maxBufferHole:.5,maxBufferLength:600,maxBufferSize:6e7,fragLoadingRetryDelay:500,fragLoadingMaxRetry:20,maxFragLookUpTolerance:.25,enableWorker:!1}),l=new Audio;let r,n=null,a=0,c=0,u=0;const E=r=>{e.error(new Error(r||"HLS Error")),f()};i.on(s.Events.MANIFEST_PARSED,((e,r)=>{const o=r.levels[0]?.details;o&&(a=o.fragments.length)})),i.on(s.Events.BUFFER_CODECS,((e,o)=>{o.audio&&"audio/mp4"!==o.audio.container||(r=o.audio)})),i.on(s.Events.BUFFER_APPENDING,((e,r)=>{n=r.data})),i.on(s.Events.ERROR,((e,r)=>{if(["bufferFullError"].includes(r.details))E(r.details);else{if(r.type===s.ErrorTypes.NETWORK_ERROR){if(r.response&&(403===r.response.code||404===r.response.code))return void E(`HTTP Error ${r.response.code} (Link expired or invalid)`);if(!navigator.onLine){if(!d){d=!0,i?.stopLoad();const e=()=>{window.removeEventListener("online",e),d=!1,i?.startLoad()};window.addEventListener("online",e)}return}return r.fatal?void i?.startLoad():void 0}if(r.type===s.ErrorTypes.MEDIA_ERROR){if("bufferStalledError"===r.details)return void i?.startLoad();if(u<
|
|
1
|
+
import{getHlsInstance as e}from"./utils/getHlsInstance.js";import{sendMessage as r}from"./utils/sendMessage.js";const o=async({url:o,filename:n,onProgress:t,forceHls:a})=>{if(!a)try{const e=await r({url:o,filename:n,type:"convertHlsToMp3",onProgress:t});if(e instanceof ReadableStream)return e;if(e instanceof Blob)return e.stream();if("stream"in e)return e.stream();throw new Error("Invalid response")}catch(e){console.error(e)}const s=await e();let i=null,l=null,d=!1;const f=()=>{i&&(i.stopLoad(),i.destroy())};return new ReadableStream({start(e){i=new s({maxBufferHole:.5,maxBufferLength:600,maxBufferSize:6e7,fragLoadingRetryDelay:500,fragLoadingMaxRetry:20,maxFragLookUpTolerance:.25,enableWorker:!1}),l=new Audio;let r,n=null,a=0,c=0,u=0;const E=r=>{e.error(new Error(r||"HLS Error")),f()};i.on(s.Events.MANIFEST_PARSED,((e,r)=>{const o=r.levels[0]?.details;o&&(a=o.fragments.length)})),i.on(s.Events.BUFFER_CODECS,((e,o)=>{o.audio&&"audio/mp4"!==o.audio.container||(r=o.audio)})),i.on(s.Events.BUFFER_APPENDING,((e,r)=>{n=r.data})),i.on(s.Events.ERROR,((e,r)=>{if(["bufferFullError"].includes(r.details))E(r.details);else{if(r.type===s.ErrorTypes.NETWORK_ERROR){if(r.response&&(403===r.response.code||404===r.response.code))return void E(`HTTP Error ${r.response.code} (Link expired or invalid)`);if(!navigator.onLine){if(!d){d=!0,i?.stopLoad();const e=()=>{window.removeEventListener("online",e),d=!1,i?.startLoad()};window.addEventListener("online",e)}return}return r.fatal?void i?.startLoad():void 0}if(r.type===s.ErrorTypes.MEDIA_ERROR){if("bufferStalledError"===r.details)return void i?.startLoad();if("fragParsingError"===r.details)return void i?.recoverMediaError();if(u<6)return u++,u>1&&i?.swapAudioCodec(),void i?.recoverMediaError()}r.fatal&&E(r.details)}})),i.on(s.Events.FRAG_BUFFERED,(async(o,s)=>{if(u=0,n){const o=r?n.slice(8,n.length):n;e.enqueue(o),c++,n=null}l.currentTime=Math.max(0,s.frag.start+s.frag.duration-.25);try{t&&a>0&&t(c/a)}catch(e){console.error(e)}c>=a&&(f(),e.close())})),i.loadSource(o),i.attachMedia(l)},cancel(){f(),l&&(l.pause(),l.remove())}})};export{o as convertTrackToStream};
|