@vknext/shared 1.6.31 → 1.6.32
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/dist/vkcom/audio/convertTrackToStream.js +1 -1
- package/dist/vkcom/audio/getTrackDetails.js +1 -1
- package/dist/vkcom/audio/utils/attachHlsErrorHandlers.d.ts +8 -0
- package/dist/vkcom/audio/utils/attachHlsErrorHandlers.js +1 -0
- package/dist/vkcom/audio/utils/extractAudioFromMp4.d.ts +1 -0
- package/dist/vkcom/audio/utils/extractAudioFromMp4.js +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{attachHlsErrorHandlers as e}from"./utils/attachHlsErrorHandlers.js";import{extractAudioFromMp4 as r}from"./utils/extractAudioFromMp4.js";import{getHlsInstance as o}from"./utils/getHlsInstance.js";import{sendMessage as t}from"./utils/sendMessage.js";const a=async({url:a,filename:n,onProgress:s,forceHls:l})=>{if(!l)try{const e=await t({url:a,filename:n,type:"convertHlsToMp3",onProgress:s});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 i=await o();let c=null,u=null;const f=()=>{c&&(c.stopLoad(),c.destroy())};return new ReadableStream({start(o){c=new i({maxBufferHole:.5,maxBufferLength:600,maxBufferSize:6e7,fragLoadingRetryDelay:500,fragLoadingMaxRetry:20,maxFragLookUpTolerance:.25,enableWorker:!1}),u=new Audio;let t,n=null,l=0,m=0;c.on(i.Events.MANIFEST_PARSED,((e,r)=>{const o=r.levels[0]?.details;o&&(l=o.fragments.length)})),c.on(i.Events.BUFFER_CODECS,((e,r)=>{r.audio&&"audio/mp4"!==r.audio.container||(t=r.audio)})),c.on(i.Events.BUFFER_APPENDING,((e,r)=>{n=r.data})),c.on(i.Events.FRAG_BUFFERED,(async(e,a)=>{if(n){const e=t?r(n):n;o.enqueue(e),m++,n=null}u.currentTime=Math.max(0,a.frag.start+a.frag.duration-.25);try{s&&l>0&&s(m/l)}catch(e){console.error(e)}m>=l&&(f(),o.close())})),e({Hls:i,hlsInstance:c,onError:e=>{o.error(new Error(e||"HLS Error")),f()}}),c.loadSource(a),c.attachMedia(u)},cancel(){f(),u&&(u.pause(),u.remove())}})};export{a as convertTrackToStream};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createPromise as
|
|
1
|
+
import{createPromise as t}from"../../utils/createPromise.js";import"../../utils/parseSvg.js";import{attachHlsErrorHandlers as e}from"./utils/attachHlsErrorHandlers.js";import{getHlsInstance as r}from"./utils/getHlsInstance.js";const o=async({url:o})=>{const{promise:a,resolve:n,reject:s}=t(),i=await r(),l=new i({maxBufferHole:2,maxBufferLength:10,maxBufferSize:5e6,fragLoadingRetryDelay:500,fragLoadingMaxRetry:3,maxFragLookUpTolerance:.2,startPosition:0,enableWorker:!1}),u=new Audio;let d;return l.on(i.Events.MANIFEST_PARSED,((t,e)=>{const r=e.levels[0]?.details;r&&(d=r.totalduration)})),l.on(i.Events.FRAG_LOADED,((t,{frag:e,payload:r})=>{if("initSegment"===e.sn)return;const o=e.duration;if(o<=0)return;if(!d){const t=l.levels[e.level];t&&t.details&&(d=t.details.totalduration)}const a=d||o;((t,e,r)=>{const o=t/e*r,a=Math.round(8*o/r/1e3);n({bitrate:a,size:Math.round(o),duration:r}),l.stopLoad(),l.destroy()})((t=>{const e=new DataView(t);let r=0;for(;r+8<=t.byteLength;){const o=e.getUint32(r),a=e.getUint32(r+4);if(o<8)break;if(1835295092===a)return Math.min(o,t.byteLength-r)-8;r+=o}return t.byteLength})(r),o,a)})),e({Hls:i,hlsInstance:l,onError:t=>{s(t),l.stopLoad(),l.destroy()}}),l.loadSource(o),l.attachMedia(u),await a};export{o as getTrackDetails};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type HlsJs from "hls.js";
|
|
2
|
+
interface AttachHlsErrorHandlersParams {
|
|
3
|
+
Hls: typeof HlsJs;
|
|
4
|
+
hlsInstance: HlsJs;
|
|
5
|
+
onError: (errorDetail?: string) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare const attachHlsErrorHandlers: ({ Hls, hlsInstance, onError }: AttachHlsErrorHandlersParams) => void;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const r=({Hls:r,hlsInstance:e,onError:o})=>{let i=!1,n=0;e.on(r.Events.FRAG_BUFFERED,(()=>{n=0})),e.on(r.Events.ERROR,((t,s)=>{if(["bufferFullError"].includes(s.details))o(s.details);else{if(s.type===r.ErrorTypes.NETWORK_ERROR){if(s.response&&(403===s.response.code||404===s.response.code))return void o(`HTTP Error ${s.response.code} (Link expired or invalid)`);if(!navigator.onLine){if(!i){i=!0,e?.stopLoad();const r=()=>{window.removeEventListener("online",r),i=!1,e?.startLoad()};window.addEventListener("online",r)}return}return s.fatal?void e?.startLoad():void 0}if(s.type===r.ErrorTypes.MEDIA_ERROR){if("bufferStalledError"===s.details)return void e?.startLoad();if("fragParsingError"===s.details)return void e?.recoverMediaError();if(n<6)return n++,n>1&&e?.swapAudioCodec(),void e?.recoverMediaError()}s.fatal&&o(s.details)}}))};export{r as attachHlsErrorHandlers};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const extractAudioFromMp4: (buffer: Uint8Array) => Uint8Array;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t=t=>{const e=new DataView(t.buffer,t.byteOffset,t.byteLength);let n=0;for(;n+8<=t.length;){const r=e.getUint32(n),i=e.getUint32(n+4);if(r<8)break;if(1835295092===i){const e=Math.min(n+r,t.length);return t.slice(n+8,e)}n+=r}return new Uint8Array(0)};export{t as extractAudioFromMp4};
|