@cher-ami/audio-manager
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -1,2 +0,2 @@ | ||
import { TDeferredPromise } from "@wbe/deferred-promise"; | ||
import { TDeferredPromise } from "./helpers/deferred-promise"; | ||
import { Howl } from "howler"; | ||
@@ -3,0 +3,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import{StateSignal as i}from"@zouloux/signal";import{deferredPromise as s}from"@wbe/deferred-promise";import{Howl as t}from"howler";import e from"@wbe/debug";import{useMemo as a,useState as n,useEffect as o}from"react";function h(){return h=Object.assign?Object.assign.bind():function(i){for(var s=1;s<arguments.length;s++){var t=arguments[s];for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&(i[e]=t[e])}return i},h.apply(this,arguments)}const d=e("AudioManager"),r=i(!1);class l{constructor(i,t={}){this.url=void 0,this.options=void 0,this.sound=void 0,this.isLoading=void 0,this.isLoaded=void 0,this.isPlaying=void 0,this.isMuted=void 0,this.id=null,this.nameSpace=void 0,this.canplayPromise=void 0,this.endedPromise=void 0,this.raf=void 0,this.handleMuteAll=i=>{i?this.mute():this.unmute()},this.handleEnded=()=>{d(this.nameSpace,"ended"),this.isPlaying=!1,this.endedPromise.resolve(),this.raf&&this.cancelRaf()},this.url=i,this.options=h({},{volume:1,autoplay:!1,loop:!1,preload:!0,html5:!1,delay:0,onUpdate:null},t),this.nameSpace=this.getNameSpace(this.id,this.url),this.isPlaying=!1,this.isLoading=!0,this.isLoaded=!1,this.isMuted=!1,this.canplayPromise=s(),this.endedPromise=s(),this.load(),this.initEvents()}getNameSpace(i,s){return`${i} - ${s.replace(/^.*[\\\/]/,"")} -`}load(){this.sound=new t(h({src:[this.url]},this.options,{onload:()=>{d(this.nameSpace,"canplay handler, audio is ready"),this.isLoaded=!0,this.canplayPromise.resolve(),this.isLoading=!1,this.isLoaded=!0,this.isMuted&&this.mute()}}))}initEvents(){r.add(this.handleMuteAll),this.sound.on("end",this.handleEnded)}async play(){return d(this.nameSpace,"waiting for canplayPromise..."),await this.canplayPromise.promise,this.endedPromise=s(),d(this.nameSpace,"play",this.options),await new Promise(i=>setTimeout(i,this.options.delay)),this.id=this.sound.play(),this.nameSpace=this.getNameSpace(this.id,this.url),this.isPlaying=!0,this.options.onUpdate&&(this.raf=this.rafRender()),this.endedPromise.promise}pause(){this.isPlaying&&this.isLoaded&&(this.sound.pause(),this.raf&&this.cancelRaf())}async stop(){d(this.nameSpace,"stop"),this.sound.stop(this.id),this.isPlaying=!1,this.raf&&this.cancelRaf()}replay(){d(this.nameSpace,"replay"),this.stop(),this.play()}async loop(){this.sound.loop(!0),this.isPlaying=!0}mute(){d(this.nameSpace,"mute"),this.isMuted||(this.sound.mute(!0),this.isMuted=!0)}unmute(){d(this.nameSpace,"unmute"),this.isMuted&&(this.sound.mute(!1),this.isMuted=!1)}async fade(i,s,t=1e3){return d(this.nameSpace,"fade >",i,s,this.options),this.isPlaying||this.play(),this.sound.fade(i,s,t),new Promise(i=>setTimeout(i,t))}async fadeIn(i=1e3){return this.id=this.sound.play(),d(this.nameSpace,`fadeIn 0 -> ${this.options.volume}`),this.isPlaying=!0,this.sound.fade(0,this.options.volume,i),new Promise(s=>setTimeout(()=>{d(this.nameSpace,"fadeIn ended"),s()},i))}async fadeOut(i=1e3){return d(this.nameSpace,`fadeOut ${this.options.volume} -> 0`),this.sound.fade(this.options.volume,0,i),new Promise(s=>setTimeout(()=>{d(this.nameSpace,"fadeOut ended"),this.stop(),s()},i))}destroy(){d(this.nameSpace,"destroy"),this.sound.unload(),r.remove(this.handleMuteAll)}rafRender(){return requestAnimationFrame(i=>{var s,t;null==(s=(t=this.options).onUpdate)||s.call(t,i),this.raf=this.rafRender()})}cancelRaf(){cancelAnimationFrame(this.raf),this.raf=null}}e("AudioManager:hooks");const u={},p=(i,s,t=[])=>{const e=a(()=>[null!=s&&s.id?`__${s.id}__`:null,i.split("/")[i.split("/").length-1].replaceAll(" ","/")].filter(i=>i).join(""),[i,s]),[h]=n(()=>{var t;return null!=(t=null==u?void 0:u[e])?t:new l(i,s)});return o(()=>{u[e]||(u[e]=h)},t),h},m=()=>{const[i,s]=n(r.state);return o(()=>r.add(i=>{s(i)}),[]),[i,i=>{r.dispatch(i)}]};export{l as AudioManager,r as MUTE_AUDIO_SIGNAL,p as useAudio,m as useMuteAllAudio}; | ||
import{StateSignal as i}from"@zouloux/signal";import{Howl as s}from"howler";import t from"@wbe/debug";import{useMemo as e,useState as a,useEffect as n}from"react";function o(){return o=Object.assign?Object.assign.bind():function(i){for(var s=1;s<arguments.length;s++){var t=arguments[s];for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&(i[e]=t[e])}return i},o.apply(this,arguments)}function h(){const i={};return i.promise=new Promise((s,t)=>{i.resolve=s,i.reject=t}),i}const d=t("AudioManager"),r=i(!1);class l{constructor(i,s={}){this.url=void 0,this.options=void 0,this.sound=void 0,this.isLoading=void 0,this.isLoaded=void 0,this.isPlaying=void 0,this.isMuted=void 0,this.id=null,this.nameSpace=void 0,this.canplayPromise=void 0,this.endedPromise=void 0,this.raf=void 0,this.handleMuteAll=i=>{i?this.mute():this.unmute()},this.handleEnded=()=>{d(this.nameSpace,"ended"),this.isPlaying=!1,this.endedPromise.resolve(),this.raf&&this.cancelRaf()},this.url=i,this.options=o({},{volume:1,autoplay:!1,loop:!1,preload:!0,html5:!1,delay:0,onUpdate:null},s),this.nameSpace=this.getNameSpace(this.id,this.url),this.isPlaying=!1,this.isLoading=!0,this.isLoaded=!1,this.isMuted=!1,this.canplayPromise=h(),this.endedPromise=h(),this.load(),this.initEvents()}getNameSpace(i,s){return`${i} - ${s.replace(/^.*[\\\/]/,"")} -`}load(){this.sound=new s(o({src:[this.url]},this.options,{onload:()=>{d(this.nameSpace,"canplay handler, audio is ready"),this.isLoaded=!0,this.canplayPromise.resolve(),this.isLoading=!1,this.isLoaded=!0,this.isMuted&&this.mute()}}))}initEvents(){r.add(this.handleMuteAll),this.sound.on("end",this.handleEnded)}async play(){return d(this.nameSpace,"waiting for canplayPromise..."),await this.canplayPromise.promise,this.endedPromise=h(),d(this.nameSpace,"play",this.options),await new Promise(i=>setTimeout(i,this.options.delay)),this.id=this.sound.play(),this.nameSpace=this.getNameSpace(this.id,this.url),this.isPlaying=!0,this.options.onUpdate&&(this.raf=this.rafRender()),this.endedPromise.promise}pause(){this.isPlaying&&this.isLoaded&&(this.sound.pause(),this.raf&&this.cancelRaf())}async stop(){d(this.nameSpace,"stop"),this.sound.stop(this.id),this.isPlaying=!1,this.raf&&this.cancelRaf()}replay(){d(this.nameSpace,"replay"),this.stop(),this.play()}async loop(){this.sound.loop(!0),this.isPlaying=!0}mute(){d(this.nameSpace,"mute"),this.isMuted||(this.sound.mute(!0),this.isMuted=!0)}unmute(){d(this.nameSpace,"unmute"),this.isMuted&&(this.sound.mute(!1),this.isMuted=!1)}async fade(i,s,t=1e3){return d(this.nameSpace,"fade >",i,s,this.options),this.isPlaying||this.play(),this.sound.fade(i,s,t),new Promise(i=>setTimeout(i,t))}async fadeIn(i=1e3){return this.id=this.sound.play(),d(this.nameSpace,`fadeIn 0 -> ${this.options.volume}`),this.isPlaying=!0,this.sound.fade(0,this.options.volume,i),new Promise(s=>setTimeout(()=>{d(this.nameSpace,"fadeIn ended"),s()},i))}async fadeOut(i=1e3){return d(this.nameSpace,`fadeOut ${this.options.volume} -> 0`),this.sound.fade(this.options.volume,0,i),new Promise(s=>setTimeout(()=>{d(this.nameSpace,"fadeOut ended"),this.stop(),s()},i))}destroy(){d(this.nameSpace,"destroy"),this.sound.unload(),r.remove(this.handleMuteAll)}rafRender(){return requestAnimationFrame(i=>{var s,t;null==(s=(t=this.options).onUpdate)||s.call(t,i),this.raf=this.rafRender()})}cancelRaf(){cancelAnimationFrame(this.raf),this.raf=null}}t("AudioManager:hooks");const u={},p=(i,s,t=[])=>{const o=e(()=>[null!=s&&s.id?`__${s.id}__`:null,i.split("/")[i.split("/").length-1].replaceAll(" ","/")].filter(i=>i).join(""),[i,s]),[h]=a(()=>{var t;return null!=(t=null==u?void 0:u[o])?t:new l(i,s)});return n(()=>{u[o]||(u[o]=h)},t),h},m=()=>{const[i,s]=a(r.state);return n(()=>r.add(i=>{s(i)}),[]),[i,i=>{r.dispatch(i)}]};export{l as AudioManager,r as MUTE_AUDIO_SIGNAL,p as useAudio,m as useMuteAllAudio}; | ||
//# sourceMappingURL=index.modern.js.map |
@@ -1,2 +0,2 @@ | ||
import{StateSignal as e}from"@zouloux/signal";import{deferredPromise as n}from"@wbe/deferred-promise";import{Howl as t}from"howler";import i from"@wbe/debug";import{useMemo as o,useState as s,useEffect as r}from"react";function a(){return a=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},a.apply(this,arguments)}var u=i("AudioManager"),d=e(!1),c=/*#__PURE__*/function(){function e(e,t){var i=this;void 0===t&&(t={}),this.url=void 0,this.options=void 0,this.sound=void 0,this.isLoading=void 0,this.isLoaded=void 0,this.isPlaying=void 0,this.isMuted=void 0,this.id=null,this.nameSpace=void 0,this.canplayPromise=void 0,this.endedPromise=void 0,this.raf=void 0,this.handleMuteAll=function(e){e?i.mute():i.unmute()},this.handleEnded=function(){u(i.nameSpace,"ended"),i.isPlaying=!1,i.endedPromise.resolve(),i.raf&&i.cancelRaf()},this.url=e,this.options=a({},{volume:1,autoplay:!1,loop:!1,preload:!0,html5:!1,delay:0,onUpdate:null},t),this.nameSpace=this.getNameSpace(this.id,this.url),this.isPlaying=!1,this.isLoading=!0,this.isLoaded=!1,this.isMuted=!1,this.canplayPromise=n(),this.endedPromise=n(),this.load(),this.initEvents()}var i=e.prototype;return i.getNameSpace=function(e,n){return e+" - "+n.replace(/^.*[\\\/]/,"")+" -"},i.load=function(){var e=this;this.sound=new t(a({src:[this.url]},this.options,{onload:function(){u(e.nameSpace,"canplay handler, audio is ready"),e.isLoaded=!0,e.canplayPromise.resolve(),e.isLoading=!1,e.isLoaded=!0,e.isMuted&&e.mute()}}))},i.initEvents=function(){d.add(this.handleMuteAll),this.sound.on("end",this.handleEnded)},i.play=function(){try{var e=this;return u(e.nameSpace,"waiting for canplayPromise..."),Promise.resolve(e.canplayPromise.promise).then(function(){return e.endedPromise=n(),u(e.nameSpace,"play",e.options),Promise.resolve(new Promise(function(n){return setTimeout(n,e.options.delay)})).then(function(){return e.id=e.sound.play(),e.nameSpace=e.getNameSpace(e.id,e.url),e.isPlaying=!0,e.options.onUpdate&&(e.raf=e.rafRender()),e.endedPromise.promise})})}catch(e){return Promise.reject(e)}},i.pause=function(){this.isPlaying&&this.isLoaded&&(this.sound.pause(),this.raf&&this.cancelRaf())},i.stop=function(){try{var e=this;return u(e.nameSpace,"stop"),e.sound.stop(e.id),e.isPlaying=!1,e.raf&&e.cancelRaf(),Promise.resolve()}catch(e){return Promise.reject(e)}},i.replay=function(){u(this.nameSpace,"replay"),this.stop(),this.play()},i.loop=function(){try{return this.sound.loop(!0),this.isPlaying=!0,Promise.resolve()}catch(e){return Promise.reject(e)}},i.mute=function(){u(this.nameSpace,"mute"),this.isMuted||(this.sound.mute(!0),this.isMuted=!0)},i.unmute=function(){u(this.nameSpace,"unmute"),this.isMuted&&(this.sound.mute(!1),this.isMuted=!1)},i.fade=function(e,n,t){void 0===t&&(t=1e3);try{var i=this;return u(i.nameSpace,"fade >",e,n,i.options),i.isPlaying||i.play(),i.sound.fade(e,n,t),Promise.resolve(new Promise(function(e){return setTimeout(e,t)}))}catch(e){return Promise.reject(e)}},i.fadeIn=function(e){void 0===e&&(e=1e3);try{var n=this;return n.id=n.sound.play(),u(n.nameSpace,"fadeIn 0 -> "+n.options.volume),n.isPlaying=!0,n.sound.fade(0,n.options.volume,e),Promise.resolve(new Promise(function(t){return setTimeout(function(){u(n.nameSpace,"fadeIn ended"),t()},e)}))}catch(e){return Promise.reject(e)}},i.fadeOut=function(e){void 0===e&&(e=1e3);try{var n=this;return u(n.nameSpace,"fadeOut "+n.options.volume+" -> 0"),n.sound.fade(n.options.volume,0,e),Promise.resolve(new Promise(function(t){return setTimeout(function(){u(n.nameSpace,"fadeOut ended"),n.stop(),t()},e)}))}catch(e){return Promise.reject(e)}},i.destroy=function(){u(this.nameSpace,"destroy"),this.sound.unload(),d.remove(this.handleMuteAll)},i.rafRender=function(){var e=this;return requestAnimationFrame(function(n){null==e.options.onUpdate||e.options.onUpdate(n),e.raf=e.rafRender()})},i.cancelRaf=function(){cancelAnimationFrame(this.raf),this.raf=null},e}();i("AudioManager:hooks");var l={},h=function(e,n,t){void 0===t&&(t=[]);var i=o(function(){return[null!=n&&n.id?"__"+n.id+"__":null,e.split("/")[e.split("/").length-1].replaceAll(" ","/")].filter(function(e){return e}).join("")},[e,n]),a=s(function(){var t;return null!=(t=null==l?void 0:l[i])?t:new c(e,n)})[0];return r(function(){l[i]||(l[i]=a)},t),a},m=function(){var e=s(d.state),n=e[0],t=e[1];return r(function(){return d.add(function(e){t(e)})},[]),[n,function(e){d.dispatch(e)}]};export{c as AudioManager,d as MUTE_AUDIO_SIGNAL,h as useAudio,m as useMuteAllAudio}; | ||
import{StateSignal as e}from"@zouloux/signal";import{Howl as n}from"howler";import t from"@wbe/debug";import{useMemo as i,useState as o,useEffect as s}from"react";function r(){return r=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},r.apply(this,arguments)}function a(){var e={};return e.promise=new Promise(function(n,t){e.resolve=n,e.reject=t}),e}var u=t("AudioManager"),d=e(!1),c=/*#__PURE__*/function(){function e(e,n){var t=this;void 0===n&&(n={}),this.url=void 0,this.options=void 0,this.sound=void 0,this.isLoading=void 0,this.isLoaded=void 0,this.isPlaying=void 0,this.isMuted=void 0,this.id=null,this.nameSpace=void 0,this.canplayPromise=void 0,this.endedPromise=void 0,this.raf=void 0,this.handleMuteAll=function(e){e?t.mute():t.unmute()},this.handleEnded=function(){u(t.nameSpace,"ended"),t.isPlaying=!1,t.endedPromise.resolve(),t.raf&&t.cancelRaf()},this.url=e,this.options=r({},{volume:1,autoplay:!1,loop:!1,preload:!0,html5:!1,delay:0,onUpdate:null},n),this.nameSpace=this.getNameSpace(this.id,this.url),this.isPlaying=!1,this.isLoading=!0,this.isLoaded=!1,this.isMuted=!1,this.canplayPromise=a(),this.endedPromise=a(),this.load(),this.initEvents()}var t=e.prototype;return t.getNameSpace=function(e,n){return e+" - "+n.replace(/^.*[\\\/]/,"")+" -"},t.load=function(){var e=this;this.sound=new n(r({src:[this.url]},this.options,{onload:function(){u(e.nameSpace,"canplay handler, audio is ready"),e.isLoaded=!0,e.canplayPromise.resolve(),e.isLoading=!1,e.isLoaded=!0,e.isMuted&&e.mute()}}))},t.initEvents=function(){d.add(this.handleMuteAll),this.sound.on("end",this.handleEnded)},t.play=function(){try{var e=this;return u(e.nameSpace,"waiting for canplayPromise..."),Promise.resolve(e.canplayPromise.promise).then(function(){return e.endedPromise=a(),u(e.nameSpace,"play",e.options),Promise.resolve(new Promise(function(n){return setTimeout(n,e.options.delay)})).then(function(){return e.id=e.sound.play(),e.nameSpace=e.getNameSpace(e.id,e.url),e.isPlaying=!0,e.options.onUpdate&&(e.raf=e.rafRender()),e.endedPromise.promise})})}catch(e){return Promise.reject(e)}},t.pause=function(){this.isPlaying&&this.isLoaded&&(this.sound.pause(),this.raf&&this.cancelRaf())},t.stop=function(){try{var e=this;return u(e.nameSpace,"stop"),e.sound.stop(e.id),e.isPlaying=!1,e.raf&&e.cancelRaf(),Promise.resolve()}catch(e){return Promise.reject(e)}},t.replay=function(){u(this.nameSpace,"replay"),this.stop(),this.play()},t.loop=function(){try{return this.sound.loop(!0),this.isPlaying=!0,Promise.resolve()}catch(e){return Promise.reject(e)}},t.mute=function(){u(this.nameSpace,"mute"),this.isMuted||(this.sound.mute(!0),this.isMuted=!0)},t.unmute=function(){u(this.nameSpace,"unmute"),this.isMuted&&(this.sound.mute(!1),this.isMuted=!1)},t.fade=function(e,n,t){void 0===t&&(t=1e3);try{var i=this;return u(i.nameSpace,"fade >",e,n,i.options),i.isPlaying||i.play(),i.sound.fade(e,n,t),Promise.resolve(new Promise(function(e){return setTimeout(e,t)}))}catch(e){return Promise.reject(e)}},t.fadeIn=function(e){void 0===e&&(e=1e3);try{var n=this;return n.id=n.sound.play(),u(n.nameSpace,"fadeIn 0 -> "+n.options.volume),n.isPlaying=!0,n.sound.fade(0,n.options.volume,e),Promise.resolve(new Promise(function(t){return setTimeout(function(){u(n.nameSpace,"fadeIn ended"),t()},e)}))}catch(e){return Promise.reject(e)}},t.fadeOut=function(e){void 0===e&&(e=1e3);try{var n=this;return u(n.nameSpace,"fadeOut "+n.options.volume+" -> 0"),n.sound.fade(n.options.volume,0,e),Promise.resolve(new Promise(function(t){return setTimeout(function(){u(n.nameSpace,"fadeOut ended"),n.stop(),t()},e)}))}catch(e){return Promise.reject(e)}},t.destroy=function(){u(this.nameSpace,"destroy"),this.sound.unload(),d.remove(this.handleMuteAll)},t.rafRender=function(){var e=this;return requestAnimationFrame(function(n){null==e.options.onUpdate||e.options.onUpdate(n),e.raf=e.rafRender()})},t.cancelRaf=function(){cancelAnimationFrame(this.raf),this.raf=null},e}();t("AudioManager:hooks");var l={},h=function(e,n,t){void 0===t&&(t=[]);var r=i(function(){return[null!=n&&n.id?"__"+n.id+"__":null,e.split("/")[e.split("/").length-1].replaceAll(" ","/")].filter(function(e){return e}).join("")},[e,n]),a=o(function(){var t;return null!=(t=null==l?void 0:l[r])?t:new c(e,n)})[0];return s(function(){l[r]||(l[r]=a)},t),a},m=function(){var e=o(d.state),n=e[0],t=e[1];return s(function(){return d.add(function(e){t(e)})},[]),[n,function(e){d.dispatch(e)}]};export{c as AudioManager,d as MUTE_AUDIO_SIGNAL,h as useAudio,m as useMuteAllAudio}; | ||
//# sourceMappingURL=index.module.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@zouloux/signal"),require("@wbe/deferred-promise"),require("howler"),require("@wbe/debug"),require("react")):"function"==typeof define&&define.amd?define(["exports","@zouloux/signal","@wbe/deferred-promise","howler","@wbe/debug","react"],t):t((e||self).audioManager={},e.signal,e.deferredPromise,e.howler,e.debug,e.react)}(this,function(e,t,i,n,o,r){function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=/*#__PURE__*/s(o);function u(){return u=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=i[n])}return e},u.apply(this,arguments)}var d=a.default("AudioManager"),l=t.StateSignal(!1),c=/*#__PURE__*/function(){function e(e,t){var n=this;void 0===t&&(t={}),this.url=void 0,this.options=void 0,this.sound=void 0,this.isLoading=void 0,this.isLoaded=void 0,this.isPlaying=void 0,this.isMuted=void 0,this.id=null,this.nameSpace=void 0,this.canplayPromise=void 0,this.endedPromise=void 0,this.raf=void 0,this.handleMuteAll=function(e){e?n.mute():n.unmute()},this.handleEnded=function(){d(n.nameSpace,"ended"),n.isPlaying=!1,n.endedPromise.resolve(),n.raf&&n.cancelRaf()},this.url=e,this.options=u({},{volume:1,autoplay:!1,loop:!1,preload:!0,html5:!1,delay:0,onUpdate:null},t),this.nameSpace=this.getNameSpace(this.id,this.url),this.isPlaying=!1,this.isLoading=!0,this.isLoaded=!1,this.isMuted=!1,this.canplayPromise=i.deferredPromise(),this.endedPromise=i.deferredPromise(),this.load(),this.initEvents()}var t=e.prototype;return t.getNameSpace=function(e,t){return e+" - "+t.replace(/^.*[\\\/]/,"")+" -"},t.load=function(){var e=this;this.sound=new n.Howl(u({src:[this.url]},this.options,{onload:function(){d(e.nameSpace,"canplay handler, audio is ready"),e.isLoaded=!0,e.canplayPromise.resolve(),e.isLoading=!1,e.isLoaded=!0,e.isMuted&&e.mute()}}))},t.initEvents=function(){l.add(this.handleMuteAll),this.sound.on("end",this.handleEnded)},t.play=function(){try{var e=this;return d(e.nameSpace,"waiting for canplayPromise..."),Promise.resolve(e.canplayPromise.promise).then(function(){return e.endedPromise=i.deferredPromise(),d(e.nameSpace,"play",e.options),Promise.resolve(new Promise(function(t){return setTimeout(t,e.options.delay)})).then(function(){return e.id=e.sound.play(),e.nameSpace=e.getNameSpace(e.id,e.url),e.isPlaying=!0,e.options.onUpdate&&(e.raf=e.rafRender()),e.endedPromise.promise})})}catch(e){return Promise.reject(e)}},t.pause=function(){this.isPlaying&&this.isLoaded&&(this.sound.pause(),this.raf&&this.cancelRaf())},t.stop=function(){try{var e=this;return d(e.nameSpace,"stop"),e.sound.stop(e.id),e.isPlaying=!1,e.raf&&e.cancelRaf(),Promise.resolve()}catch(e){return Promise.reject(e)}},t.replay=function(){d(this.nameSpace,"replay"),this.stop(),this.play()},t.loop=function(){try{return this.sound.loop(!0),this.isPlaying=!0,Promise.resolve()}catch(e){return Promise.reject(e)}},t.mute=function(){d(this.nameSpace,"mute"),this.isMuted||(this.sound.mute(!0),this.isMuted=!0)},t.unmute=function(){d(this.nameSpace,"unmute"),this.isMuted&&(this.sound.mute(!1),this.isMuted=!1)},t.fade=function(e,t,i){void 0===i&&(i=1e3);try{var n=this;return d(n.nameSpace,"fade >",e,t,n.options),n.isPlaying||n.play(),n.sound.fade(e,t,i),Promise.resolve(new Promise(function(e){return setTimeout(e,i)}))}catch(e){return Promise.reject(e)}},t.fadeIn=function(e){void 0===e&&(e=1e3);try{var t=this;return t.id=t.sound.play(),d(t.nameSpace,"fadeIn 0 -> "+t.options.volume),t.isPlaying=!0,t.sound.fade(0,t.options.volume,e),Promise.resolve(new Promise(function(i){return setTimeout(function(){d(t.nameSpace,"fadeIn ended"),i()},e)}))}catch(e){return Promise.reject(e)}},t.fadeOut=function(e){void 0===e&&(e=1e3);try{var t=this;return d(t.nameSpace,"fadeOut "+t.options.volume+" -> 0"),t.sound.fade(t.options.volume,0,e),Promise.resolve(new Promise(function(i){return setTimeout(function(){d(t.nameSpace,"fadeOut ended"),t.stop(),i()},e)}))}catch(e){return Promise.reject(e)}},t.destroy=function(){d(this.nameSpace,"destroy"),this.sound.unload(),l.remove(this.handleMuteAll)},t.rafRender=function(){var e=this;return requestAnimationFrame(function(t){null==e.options.onUpdate||e.options.onUpdate(t),e.raf=e.rafRender()})},t.cancelRaf=function(){cancelAnimationFrame(this.raf),this.raf=null},e}();a.default("AudioManager:hooks");var f={};e.AudioManager=c,e.MUTE_AUDIO_SIGNAL=l,e.useAudio=function(e,t,i){void 0===i&&(i=[]);var n=r.useMemo(function(){return[null!=t&&t.id?"__"+t.id+"__":null,e.split("/")[e.split("/").length-1].replaceAll(" ","/")].filter(function(e){return e}).join("")},[e,t]),o=r.useState(function(){var i;return null!=(i=null==f?void 0:f[n])?i:new c(e,t)})[0];return r.useEffect(function(){f[n]||(f[n]=o)},i),o},e.useMuteAllAudio=function(){var e=r.useState(l.state),t=e[0],i=e[1];return r.useEffect(function(){return l.add(function(e){i(e)})},[]),[t,function(e){l.dispatch(e)}]}}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@zouloux/signal"),require("howler"),require("@wbe/debug"),require("react")):"function"==typeof define&&define.amd?define(["exports","@zouloux/signal","howler","@wbe/debug","react"],n):n((e||self).audioManager={},e.signal,e.howler,e.debug,e.react)}(this,function(e,n,t,i,o){function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=/*#__PURE__*/s(i);function r(){return r=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},r.apply(this,arguments)}function u(){var e={};return e.promise=new Promise(function(n,t){e.resolve=n,e.reject=t}),e}var d=a.default("AudioManager"),l=n.StateSignal(!1),c=/*#__PURE__*/function(){function e(e,n){var t=this;void 0===n&&(n={}),this.url=void 0,this.options=void 0,this.sound=void 0,this.isLoading=void 0,this.isLoaded=void 0,this.isPlaying=void 0,this.isMuted=void 0,this.id=null,this.nameSpace=void 0,this.canplayPromise=void 0,this.endedPromise=void 0,this.raf=void 0,this.handleMuteAll=function(e){e?t.mute():t.unmute()},this.handleEnded=function(){d(t.nameSpace,"ended"),t.isPlaying=!1,t.endedPromise.resolve(),t.raf&&t.cancelRaf()},this.url=e,this.options=r({},{volume:1,autoplay:!1,loop:!1,preload:!0,html5:!1,delay:0,onUpdate:null},n),this.nameSpace=this.getNameSpace(this.id,this.url),this.isPlaying=!1,this.isLoading=!0,this.isLoaded=!1,this.isMuted=!1,this.canplayPromise=u(),this.endedPromise=u(),this.load(),this.initEvents()}var n=e.prototype;return n.getNameSpace=function(e,n){return e+" - "+n.replace(/^.*[\\\/]/,"")+" -"},n.load=function(){var e=this;this.sound=new t.Howl(r({src:[this.url]},this.options,{onload:function(){d(e.nameSpace,"canplay handler, audio is ready"),e.isLoaded=!0,e.canplayPromise.resolve(),e.isLoading=!1,e.isLoaded=!0,e.isMuted&&e.mute()}}))},n.initEvents=function(){l.add(this.handleMuteAll),this.sound.on("end",this.handleEnded)},n.play=function(){try{var e=this;return d(e.nameSpace,"waiting for canplayPromise..."),Promise.resolve(e.canplayPromise.promise).then(function(){return e.endedPromise=u(),d(e.nameSpace,"play",e.options),Promise.resolve(new Promise(function(n){return setTimeout(n,e.options.delay)})).then(function(){return e.id=e.sound.play(),e.nameSpace=e.getNameSpace(e.id,e.url),e.isPlaying=!0,e.options.onUpdate&&(e.raf=e.rafRender()),e.endedPromise.promise})})}catch(e){return Promise.reject(e)}},n.pause=function(){this.isPlaying&&this.isLoaded&&(this.sound.pause(),this.raf&&this.cancelRaf())},n.stop=function(){try{var e=this;return d(e.nameSpace,"stop"),e.sound.stop(e.id),e.isPlaying=!1,e.raf&&e.cancelRaf(),Promise.resolve()}catch(e){return Promise.reject(e)}},n.replay=function(){d(this.nameSpace,"replay"),this.stop(),this.play()},n.loop=function(){try{return this.sound.loop(!0),this.isPlaying=!0,Promise.resolve()}catch(e){return Promise.reject(e)}},n.mute=function(){d(this.nameSpace,"mute"),this.isMuted||(this.sound.mute(!0),this.isMuted=!0)},n.unmute=function(){d(this.nameSpace,"unmute"),this.isMuted&&(this.sound.mute(!1),this.isMuted=!1)},n.fade=function(e,n,t){void 0===t&&(t=1e3);try{var i=this;return d(i.nameSpace,"fade >",e,n,i.options),i.isPlaying||i.play(),i.sound.fade(e,n,t),Promise.resolve(new Promise(function(e){return setTimeout(e,t)}))}catch(e){return Promise.reject(e)}},n.fadeIn=function(e){void 0===e&&(e=1e3);try{var n=this;return n.id=n.sound.play(),d(n.nameSpace,"fadeIn 0 -> "+n.options.volume),n.isPlaying=!0,n.sound.fade(0,n.options.volume,e),Promise.resolve(new Promise(function(t){return setTimeout(function(){d(n.nameSpace,"fadeIn ended"),t()},e)}))}catch(e){return Promise.reject(e)}},n.fadeOut=function(e){void 0===e&&(e=1e3);try{var n=this;return d(n.nameSpace,"fadeOut "+n.options.volume+" -> 0"),n.sound.fade(n.options.volume,0,e),Promise.resolve(new Promise(function(t){return setTimeout(function(){d(n.nameSpace,"fadeOut ended"),n.stop(),t()},e)}))}catch(e){return Promise.reject(e)}},n.destroy=function(){d(this.nameSpace,"destroy"),this.sound.unload(),l.remove(this.handleMuteAll)},n.rafRender=function(){var e=this;return requestAnimationFrame(function(n){null==e.options.onUpdate||e.options.onUpdate(n),e.raf=e.rafRender()})},n.cancelRaf=function(){cancelAnimationFrame(this.raf),this.raf=null},e}();a.default("AudioManager:hooks");var f={};e.AudioManager=c,e.MUTE_AUDIO_SIGNAL=l,e.useAudio=function(e,n,t){void 0===t&&(t=[]);var i=o.useMemo(function(){return[null!=n&&n.id?"__"+n.id+"__":null,e.split("/")[e.split("/").length-1].replaceAll(" ","/")].filter(function(e){return e}).join("")},[e,n]),s=o.useState(function(){var t;return null!=(t=null==f?void 0:f[i])?t:new c(e,n)})[0];return o.useEffect(function(){f[i]||(f[i]=s)},t),s},e.useMuteAllAudio=function(){var e=o.useState(l.state),n=e[0],t=e[1];return o.useEffect(function(){return l.add(function(e){t(e)})},[]),[n,function(e){l.dispatch(e)}]}}); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "@cher-ami/audio-manager", | ||
"description": "A simple web audio manager", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"author": "cher-ami", | ||
@@ -41,3 +41,2 @@ "license": "MIT", | ||
"@wbe/debug": "^1.0.0", | ||
"@wbe/deferred-promise": "^2.4.0", | ||
"@zouloux/signal": "^0.2.4", | ||
@@ -44,0 +43,0 @@ "howler": "^2.2.3" |
@@ -9,3 +9,2 @@ # Audio manager | ||
- [@zouloux/signal](https://www.npmjs.com/package/@zouloux/signal) | ||
- [@wbe/deferred-promise](https://www.npmjs.com/package/@wbe/) | ||
- [@wbe/debug](https://www.npmjs.com/package/@wbe/debug) | ||
@@ -12,0 +11,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
81236
5
16
156
243
- Removed@wbe/deferred-promise@^2.4.0
- Removed@wbe/deferred-promise@2.4.0(transitive)