@irewind/web-ffmpeg 1.1.7 → 1.1.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/dist/index.js +2 -2
- package/dist/worker.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! @irewind/web-ffmpeg 1.1.
|
|
2
|
-
import e from"./worker.js?worker";const t={LOAD:`LOAD`,RUN:`RUN`,ABORT_RUN:`ABORT_RUN`,CWD:`CWD`,CH_DIR:`CH_DIR`,EXISTS:`EXISTS`,IS_FILE:`IS_FILE`,IS_DIR:`IS_DIR`,WRITE_FILE:`WRITE_FILE`,READ_FILE:`READ_FILE`,DELETE_FILE:`DELETE_FILE`,RENAME:`RENAME`,CREATE_DIR:`CREATE_DIR`,LIST_DIR:`LIST_DIR`,DELETE_DIR:`DELETE_DIR`,ERROR:`ERROR`,LOG:`LOG`,PROGRESS:`PROGRESS`},n=`webFFmpeg not loaded`,r=`webFFmpeg is destroyed`;let i=0
|
|
1
|
+
/*! @irewind/web-ffmpeg 1.1.8 | Copyright iRewind */
|
|
2
|
+
import e from"./worker.js?worker";const t={LOAD:`LOAD`,RUN:`RUN`,ABORT_RUN:`ABORT_RUN`,CWD:`CWD`,CH_DIR:`CH_DIR`,EXISTS:`EXISTS`,IS_FILE:`IS_FILE`,IS_DIR:`IS_DIR`,WRITE_FILE:`WRITE_FILE`,READ_FILE:`READ_FILE`,DELETE_FILE:`DELETE_FILE`,RENAME:`RENAME`,CREATE_DIR:`CREATE_DIR`,LIST_DIR:`LIST_DIR`,DELETE_DIR:`DELETE_DIR`,ERROR:`ERROR`,LOG:`LOG`,PROGRESS:`PROGRESS`},n=`webFFmpeg not loaded`,r=`webFFmpeg is destroyed`;let i=0,a=`[webFFmpeg]`;var o=class{#e=null;#t=!1;#n=null;#r=null;#i=[];#a={};#o={};load(){if(this.#e===null)return this.#e=new e,this.#e.addEventListener(`message`,({data:{id:e,type:n,payload:r}})=>{switch(n){case t.LOAD:case t.RUN:case t.ABORT_RUN:case t.CWD:case t.CH_DIR:case t.EXISTS:case t.IS_FILE:case t.IS_DIR:case t.WRITE_FILE:case t.READ_FILE:case t.DELETE_FILE:case t.RENAME:case t.CREATE_DIR:case t.LIST_DIR:case t.DELETE_DIR:this.#a[e]?.(r);break;case t.LOG:this.#t===!0&&console.log(r.message);break;case t.PROGRESS:this.#r?.(r);break;case t.ERROR:this.#o[e]?.(r);break}delete this.#a[e],delete this.#o[e]}),this.#s({type:t.LOAD})}async startSession({log:e=!1,signal:t}){e===!0&&console.log(a,`New Session`),this.#t=e,this.#n=t,this.#i=(await this.listDir(`/`)).map(e=>e.name)}async cleanupSession(e=`webFFmpeg has ended the session`){let t=Error(e);for(let e in this.#o)this.#o[e](t);if(this.#n=null,this.#r=null,this.#a={},this.#o={},e!==r){await this.chdir(`/`);let e=this.#i,t=await this.listDir(`/`);for(let n of t)if(e.includes(n.name)===!1){let e=n.isDir?`deleteDir`:`deleteFile`;await this[e](n.name)}}this.#i=[],this.#t===!0&&console.log(a,`Cleaned up Session`),this.#t=!1}destroy(){this.#e!==null&&(this.cleanupSession(r),this.#e.terminate(),this.#e=null,this.#t===!0&&console.log(a,`Destroyed`))}#s({type:e,payload:t,trans:r=[]}){if(this.#t===!0){let{data:n,...r}=t||{};console.log(a,`${e} ->`,r)}if(this.#e===null)throw Error(n);return new Promise((n,a)=>{let o=++i;this.#a[o]=e=>{n(e)},this.#o[o]=e=>{a(e)},this.#e?.postMessage({id:o,type:e,payload:t},r)})}run(e,r=null){if(this.#r=r,this.#e===null)throw Error(n);return this.#t===!0&&console.log(a,`Calling FFmpeg:`,e),new Promise((n,r)=>{let a=++i,o=()=>{this.#r=null,this.#s({id:++i,type:t.ABORT_RUN}),r(Error(`Message # ${a} was aborted`))};this.#a[a]=e=>{this.#r=null,this.#n?.removeEventListener(`abort`,o),n(e)},this.#o[a]=e=>{this.#r=null,this.#n?.removeEventListener(`abort`,o),r(e)},this.#n?.addEventListener(`abort`,o,{once:!0}),this.#e?.postMessage({id:a,type:t.RUN,payload:{args:e}},[])})}cwd(){return this.#s({type:t.CWD})}chdir(e){return this.#s({type:t.CH_DIR,payload:{path:e}})}exists(e){return this.#s({type:t.EXISTS,payload:{path:e}})}isFile(e){return this.#s({type:t.IS_FILE,payload:{path:e}})}writeFile(e,n){return this.#s({type:t.WRITE_FILE,payload:{path:e,data:n},trans:n instanceof Uint8Array?[n.buffer]:[]})}readFile(e,n=`binary`){return this.#s({type:t.READ_FILE,payload:{path:e,encoding:n}})}deleteFile(e){return this.#s({type:t.DELETE_FILE,payload:{path:e}})}rename(e,n){return this.#s({type:t.RENAME,payload:{oldPath:e,newPath:n}})}isDir(e){return this.#s({type:t.IS_DIR,payload:{path:e}})}createDir(e){return this.#s({type:t.CREATE_DIR,payload:{path:e}})}listDir(e){return this.#s({type:t.LIST_DIR,payload:{path:e}})}deleteDir(e){return this.#s({type:t.DELETE_DIR,payload:{path:e}})}};async function s(){let e=new o;return await e.load(),e}let c=null,l=Promise.resolve();const u={id:null,timeout:15*6e4,start(){this.clear(),this.id=setTimeout(()=>{this.id=null,c.destroy()},this.timeout)},clear(){this.id!==null&&(clearTimeout(this.id),this.id=null)}};function d({signal:e,log:t=!1,showMessage:n=()=>{}},r){return u.clear(),l=l.catch(()=>{}).then(async()=>{u.clear(),e?.throwIfAborted(),n(`Loading audio-video module...`);try{c||=await s()}catch(t){throw e?.throwIfAborted(),console.error(t),Error(`Failed to load audio-video module`,{cause:t})}return e?.throwIfAborted(),await c.startSession({log:t,signal:e}),e?.throwIfAborted(),r(c)}).catch(t=>{throw e?.aborted!==!0&&(u.clear(),c!==null&&(c.destroy(),c=null)),t}).finally(()=>{n(),c!==null&&(c.cleanupSession(),u.start())}),l}export{d as default};
|
package/dist/worker.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! @irewind/web-ffmpeg 1.1.
|
|
1
|
+
/*! @irewind/web-ffmpeg 1.1.8 | Copyright iRewind */
|
|
2
2
|
import e from"./ffmpeg.js";const t={LOAD:`LOAD`,RUN:`RUN`,ABORT_RUN:`ABORT_RUN`,CWD:`CWD`,CH_DIR:`CH_DIR`,EXISTS:`EXISTS`,IS_FILE:`IS_FILE`,IS_DIR:`IS_DIR`,WRITE_FILE:`WRITE_FILE`,READ_FILE:`READ_FILE`,DELETE_FILE:`DELETE_FILE`,RENAME:`RENAME`,CREATE_DIR:`CREATE_DIR`,LIST_DIR:`LIST_DIR`,DELETE_DIR:`DELETE_DIR`,ERROR:`ERROR`,LOG:`LOG`,PROGRESS:`PROGRESS`};let n;async function r(){n=await e(),n.setLogger(e=>self.postMessage({type:t.LOG,payload:e})),n.setProgress(e=>self.postMessage({type:t.PROGRESS,payload:e}))}function i({args:e}){n.setAbortRun(0),n.runFFmpegCmd(...e);let t=n.ret;return n.reset(),t}function a(){n.setAbortRun(1)}function o(){return n.FS.cwd()}function s({path:e}){return n.FS.chdir(e)}function c(e){try{return n.FS.stat(e.path)}catch{return!1}}function l({path:e}){try{let t=n.FS.stat(e);return n.FS.isFile(t.mode)}catch{return!1}}function u({path:e,data:t}){return n.FS.writeFile(e,t)}function d({path:e,encoding:t}){return n.FS.readFile(e,{encoding:t})}function f({path:e}){return n.FS.unlink(e)}function p({oldPath:e,newPath:t}){return n.FS.rename(e,t)}function m({path:e}){try{let t=n.FS.stat(e);return n.FS.isDir(t.mode)}catch{return!1}}function h({path:e}){return n.FS.mkdir(e)}function g({path:e}){let t=n.FS.readdir(e),r=[];for(let i of t){let t=n.FS.stat(`${e}/${i}`),a=n.FS.isDir(t.mode);r.push({name:i,isDir:a})}return r}function _({path:e}){return n.FS.rmdir(e)}self.addEventListener(`message`,async({data:{id:e,type:v,payload:y}})=>{let b;try{if(v!==t.LOAD&&!n)throw Error(`webFFmpeg not loaded`);switch(v){case t.LOAD:b=await r(y);break;case t.RUN:b=i(y);break;case t.ABORT_RUN:b=a(y);break;case t.CWD:b=o(y);break;case t.CH_DIR:b=s(y);break;case t.EXISTS:b=c(y);break;case t.IS_FILE:b=l(y);break;case t.IS_DIR:b=m(y);break;case t.WRITE_FILE:b=u(y);break;case t.READ_FILE:b=d(y);break;case t.DELETE_FILE:b=f(y);break;case t.RENAME:b=p(y);break;case t.CREATE_DIR:b=h(y);break;case t.LIST_DIR:b=g(y);break;case t.DELETE_DIR:b=_(y);break;default:throw Error(`unknown message type`)}}catch(n){self.postMessage({id:e,type:t.ERROR,payload:n.toString()});return}self.postMessage({id:e,type:v,payload:b},b instanceof Uint8Array?[b.buffer]:[])});
|