@eva/plugin-sound 1.2.0-alpha.2 → 1.2.0-alpha.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.
@@ -479,19 +479,33 @@ this.EVA.plugin.sound = function (exports, eva_js) {
479
479
  reject(new Error('No audio support'));
480
480
  }
481
481
 
482
- _this.ctx.decodeAudioData(arraybuffer).then(function (decodedData) {
482
+ var success = function success(decodedData) {
483
+ if (_this.decodeAudioPromiseMap[name]) {
484
+ delete _this.decodeAudioPromiseMap[name];
485
+ }
486
+
483
487
  if (decodedData) {
484
488
  resolve(decodedData);
485
489
  } else {
486
490
  reject(new Error("Error decoding audio " + name));
487
491
  }
488
- }).catch(function (error) {
489
- reject(new Error(error + ". arrayBuffer byteLength: " + (arraybuffer ? arraybuffer.byteLength : 0)));
490
- }).finally(function () {
492
+ };
493
+
494
+ var error = function error(err) {
491
495
  if (_this.decodeAudioPromiseMap[name]) {
492
496
  delete _this.decodeAudioPromiseMap[name];
493
497
  }
494
- });
498
+
499
+ reject(new Error(err + ". arrayBuffer byteLength: " + (arraybuffer ? arraybuffer.byteLength : 0)));
500
+ };
501
+
502
+ var promise = _this.ctx.decodeAudioData(arraybuffer, success, error);
503
+
504
+ if (promise instanceof Promise) {
505
+ promise.catch(function (err) {
506
+ reject(new Error("catch " + err + ", arrayBuffer byteLength: " + (arraybuffer ? arraybuffer.byteLength : 0)));
507
+ });
508
+ }
495
509
  });
496
510
  this.decodeAudioPromiseMap[name] = promise;
497
511
  return promise;
@@ -1 +1 @@
1
- function _extends(){return(_extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var o=arguments[e];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(t[n]=o[n])}return t}).apply(this,arguments)}this.EVA=this.EVA||{},this.EVA.plugin=this.EVA.plugin||{},this.EVA.plugin.sound=function(t,e){"use strict";var o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])})(t,e)};function n(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function i(t,e,o,n){return new(o||(o=Promise))((function(i,r){function s(t){try{a(n.next(t))}catch(t){r(t)}}function u(t){try{a(n.throw(t))}catch(t){r(t)}}function a(t){var e;t.done?i(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(s,u)}a((n=n.apply(t,e||[])).next())}))}function r(t,e){var o,n,i,r,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return r={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function u(r){return function(u){return function(r){if(o)throw new TypeError("Generator is already executing.");for(;s;)try{if(o=1,n&&(i=2&r[0]?n.return:r[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,r[1])).done)return i;switch(n=0,i&&(r=[2&r[0],i.value]),r[0]){case 0:case 1:i=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,n=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==r[0]&&2!==r[0])){s=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3])){s.label=r[1];break}if(6===r[0]&&s.label<i[1]){s.label=i[1],i=r;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(r);break}i[2]&&s.ops.pop(),s.trys.pop();continue}r=e.call(t,s)}catch(t){r=[6,t],n=0}finally{o=i=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,u])}}}var s=function(t){function o(e){var o=t.call(this)||this;return o.autoPauseAndStart=!0,o.components=[],o.pausedComponents=[],o.audioBufferCache={},o.decodeAudioPromiseMap={},_extends(o,e),o}return n(o,t),Object.defineProperty(o.prototype,"muted",{get:function(){return!!this.gainNode&&0===this.gainNode.gain.value},set:function(t){this.gainNode&&this.gainNode.gain.setValueAtTime(t?0:1,0)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"volume",{get:function(){return this.gainNode?this.gainNode.gain.value:1},set:function(t){!this.gainNode||"number"!=typeof t||t<0||t>1||this.gainNode.gain.setValueAtTime(t,0)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"audioLocked",{get:function(){return!this.ctx||"running"!==this.ctx.state},enumerable:!1,configurable:!0}),o.prototype.resumeAll=function(){var t=this,e=function(){t.pausedComponents.forEach((function(t){t.play()})),t.pausedComponents=[]};this.ctx.resume().then(e,e)},o.prototype.pauseAll=function(){var t=this;this.components.forEach((function(e){e.playing&&(t.pausedComponents.push(e),e.pause())})),this.ctx.suspend().then()},o.prototype.stopAll=function(){this.components.forEach((function(t){t.playing&&t.stop()})),this.pausedComponents=[],this.ctx.suspend().then()},o.prototype.init=function(){this.setupAudioContext()},o.prototype.update=function(){var t,e,o=this.componentObserver.clear();try{for(var n=function(t){var e="function"==typeof Symbol&&Symbol.iterator,o=e&&t[e],n=0;if(o)return o.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(o),i=n.next();!i.done;i=n.next()){var r=i.value;this.componentChanged(r)}}catch(e){t={error:e}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(t)throw t.error}}},o.prototype.onResume=function(){this.autoPauseAndStart&&this.resumeAll()},o.prototype.onPause=function(){this.autoPauseAndStart&&this.pauseAll()},o.prototype.onDestroy=function(){this.components.forEach((function(t){t.onDestroy()})),this.components=[],this.ctx&&(this.gainNode.disconnect(),this.gainNode=null,this.ctx.close(),this.ctx=null)},o.prototype.componentChanged=function(t){return i(this,void 0,void 0,(function(){return r(this,(function(o){return"Sound"!==t.componentName||t.type===e.OBSERVER_TYPE.ADD&&this.add(t),[2]}))}))},o.prototype.setupAudioContext=function(){try{var t=window.AudioContext||window.webkitAudioContext;this.ctx=new t}catch(t){console.error(t),this.onError&&this.onError(t)}this.ctx&&(this.gainNode=void 0===this.ctx.createGain?this.ctx.createGainNode():this.ctx.createGain(),this.gainNode.gain.setValueAtTime(this.muted?0:this.volume,this.ctx.currentTime),this.gainNode.connect(this.ctx.destination),this.unlockAudio())},o.prototype.unlockAudio=function(){var t=this;if(this.ctx&&this.audioLocked){var e=function e(){if(t.ctx){var o=function(){document.body.removeEventListener("touchstart",e),document.body.removeEventListener("touchend",e),document.body.removeEventListener("click",e)};t.ctx.resume().then(o,o)}};document.body.addEventListener("touchstart",e),document.body.addEventListener("touchend",e),document.body.addEventListener("click",e)}},o.prototype.add=function(t){var o;return i(this,void 0,void 0,(function(){var n,i,s,u,a,c;return r(this,(function(r){switch(r.label){case 0:n=t.component,this.components.push(n),r.label=1;case 1:return r.trys.push([1,5,,6]),i=n.config,n.state="loading",[4,e.resource.getResource(i.resource)];case 2:return s=r.sent(),this.audioBufferCache[s.name]||!(null===(o=null==s?void 0:s.data)||void 0===o?void 0:o.audio)?[3,4]:(u=this.audioBufferCache,a=s.name,[4,this.decodeAudioData(s.data.audio,s.name)]);case 3:u[a]=r.sent(),r.label=4;case 4:return this.audioBufferCache[s.name]&&(n.systemContext=this.ctx,n.systemDestination=this.gainNode,n.onload(this.audioBufferCache[s.name])),[3,6];case 5:return c=r.sent(),this.onError&&this.onError(c),[3,6];case 6:return[2]}}))}))},o.prototype.decodeAudioData=function(t,e){var o=this;if(this.decodeAudioPromiseMap[e])return this.decodeAudioPromiseMap[e];var n=new Promise((function(n,i){o.ctx||i(new Error("No audio support")),o.ctx.decodeAudioData(t).then((function(t){t?n(t):i(new Error("Error decoding audio "+e))})).catch((function(e){i(new Error(e+". arrayBuffer byteLength: "+(t?t.byteLength:0)))})).finally((function(){o.decodeAudioPromiseMap[e]&&delete o.decodeAudioPromiseMap[e]}))}));return this.decodeAudioPromiseMap[e]=n,n},o.systemName="SoundSystem",o=function(t,e,o,n){var i,r=arguments.length,s=r<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,o,n);else for(var u=t.length-1;u>=0;u--)(i=t[u])&&(s=(r<3?i(s):r>3?i(e,o,s):i(e,o))||s);return r>3&&s&&Object.defineProperty(e,o,s),s}([e.decorators.componentObserver({Sound:[]})],o)}(e.System),u=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.state="unloaded",e.config={resource:"",autoplay:!1,muted:!1,volume:1,loop:!1,seek:0},e.playTime=0,e.startTime=0,e.duration=0,e.actionQueue=[],e}return n(e,t),Object.defineProperty(e.prototype,"muted",{get:function(){return!!this.gainNode&&0===this.gainNode.gain.value},set:function(t){this.gainNode&&this.gainNode.gain.setValueAtTime(t?0:this.config.volume,0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"volume",{get:function(){return this.gainNode?this.gainNode.gain.value:1},set:function(t){"number"!=typeof t||t<0||t>1||(this.config.volume=t,this.gainNode&&this.gainNode.gain.setValueAtTime(t,0))},enumerable:!1,configurable:!0}),e.prototype.init=function(t){t&&(_extends(this.config,t),this.config.autoplay&&this.actionQueue.push(this.play.bind(this)))},e.prototype.play=function(){var t=this;if("loaded"!==this.state&&this.actionQueue.push(this.play.bind(this)),this.destroySource(),this.createSource(),this.sourceNode){var e=this.systemContext.currentTime,o=this.config.seek,n=this.config.duration;this.sourceNode.start(0,o,n),this.startTime=e,this.playTime=e-o,this.paused=!1,this.playing=!0,this.resetConfig(),this.endedListener=function(){t.sourceNode&&(t.config.onEnd&&t.config.onEnd(),t.playing&&t.destroySource())},this.sourceNode.addEventListener("ended",this.endedListener)}},e.prototype.pause=function(){"loaded"!==this.state&&this.actionQueue.push(this.pause.bind(this)),!this.paused&&this.playing&&(this.paused=!0,this.playing=!1,this.config.seek=this.getCurrentTime(),this.destroySource())},e.prototype.stop=function(){"loaded"!==this.state&&this.actionQueue.push(this.stop.bind(this)),(this.paused||this.playing)&&(this.playing=!1,this.paused=!1,this.destroySource(),this.resetConfig())},e.prototype.onload=function(t){this.state="loaded",this.buffer=t,this.duration=this.buffer.duration,this.actionQueue.forEach((function(t){return t()})),this.actionQueue.length=0},e.prototype.onDestroy=function(){this.actionQueue.length=0,this.destroySource()},e.prototype.resetConfig=function(){this.config.seek=0},e.prototype.getCurrentTime=function(){return this.config.loop&&this.duration>0?(this.systemContext.currentTime-this.playTime)%this.duration:this.systemContext.currentTime-this.playTime},e.prototype.createSource=function(){this.systemContext&&"loaded"===this.state&&(this.sourceNode=this.systemContext.createBufferSource(),this.sourceNode.buffer=this.buffer,this.sourceNode.loop=this.config.loop,this.gainNode||(this.gainNode=this.systemContext.createGain(),this.gainNode.connect(this.systemDestination),_extends(this,this.config)),this.sourceNode.connect(this.gainNode))},e.prototype.destroySource=function(){this.sourceNode&&(this.sourceNode.removeEventListener("ended",this.endedListener),this.sourceNode.stop(),this.sourceNode.disconnect(),this.sourceNode=null,this.startTime=0,this.playTime=0,this.playing=!1)},e.componentName="Sound",e}(e.Component);return t.Sound=u,t.SoundSystem=s,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA);
1
+ function _extends(){return(_extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var o=arguments[e];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(t[n]=o[n])}return t}).apply(this,arguments)}this.EVA=this.EVA||{},this.EVA.plugin=this.EVA.plugin||{},this.EVA.plugin.sound=function(t,e){"use strict";var o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])})(t,e)};function n(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function i(t,e,o,n){return new(o||(o=Promise))((function(i,r){function s(t){try{a(n.next(t))}catch(t){r(t)}}function u(t){try{a(n.throw(t))}catch(t){r(t)}}function a(t){var e;t.done?i(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(s,u)}a((n=n.apply(t,e||[])).next())}))}function r(t,e){var o,n,i,r,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return r={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function u(r){return function(u){return function(r){if(o)throw new TypeError("Generator is already executing.");for(;s;)try{if(o=1,n&&(i=2&r[0]?n.return:r[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,r[1])).done)return i;switch(n=0,i&&(r=[2&r[0],i.value]),r[0]){case 0:case 1:i=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,n=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==r[0]&&2!==r[0])){s=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3])){s.label=r[1];break}if(6===r[0]&&s.label<i[1]){s.label=i[1],i=r;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(r);break}i[2]&&s.ops.pop(),s.trys.pop();continue}r=e.call(t,s)}catch(t){r=[6,t],n=0}finally{o=i=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,u])}}}var s=function(t){function o(e){var o=t.call(this)||this;return o.autoPauseAndStart=!0,o.components=[],o.pausedComponents=[],o.audioBufferCache={},o.decodeAudioPromiseMap={},_extends(o,e),o}return n(o,t),Object.defineProperty(o.prototype,"muted",{get:function(){return!!this.gainNode&&0===this.gainNode.gain.value},set:function(t){this.gainNode&&this.gainNode.gain.setValueAtTime(t?0:1,0)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"volume",{get:function(){return this.gainNode?this.gainNode.gain.value:1},set:function(t){!this.gainNode||"number"!=typeof t||t<0||t>1||this.gainNode.gain.setValueAtTime(t,0)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"audioLocked",{get:function(){return!this.ctx||"running"!==this.ctx.state},enumerable:!1,configurable:!0}),o.prototype.resumeAll=function(){var t=this,e=function(){t.pausedComponents.forEach((function(t){t.play()})),t.pausedComponents=[]};this.ctx.resume().then(e,e)},o.prototype.pauseAll=function(){var t=this;this.components.forEach((function(e){e.playing&&(t.pausedComponents.push(e),e.pause())})),this.ctx.suspend().then()},o.prototype.stopAll=function(){this.components.forEach((function(t){t.playing&&t.stop()})),this.pausedComponents=[],this.ctx.suspend().then()},o.prototype.init=function(){this.setupAudioContext()},o.prototype.update=function(){var t,e,o=this.componentObserver.clear();try{for(var n=function(t){var e="function"==typeof Symbol&&Symbol.iterator,o=e&&t[e],n=0;if(o)return o.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(o),i=n.next();!i.done;i=n.next()){var r=i.value;this.componentChanged(r)}}catch(e){t={error:e}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(t)throw t.error}}},o.prototype.onResume=function(){this.autoPauseAndStart&&this.resumeAll()},o.prototype.onPause=function(){this.autoPauseAndStart&&this.pauseAll()},o.prototype.onDestroy=function(){this.components.forEach((function(t){t.onDestroy()})),this.components=[],this.ctx&&(this.gainNode.disconnect(),this.gainNode=null,this.ctx.close(),this.ctx=null)},o.prototype.componentChanged=function(t){return i(this,void 0,void 0,(function(){return r(this,(function(o){return"Sound"!==t.componentName||t.type===e.OBSERVER_TYPE.ADD&&this.add(t),[2]}))}))},o.prototype.setupAudioContext=function(){try{var t=window.AudioContext||window.webkitAudioContext;this.ctx=new t}catch(t){console.error(t),this.onError&&this.onError(t)}this.ctx&&(this.gainNode=void 0===this.ctx.createGain?this.ctx.createGainNode():this.ctx.createGain(),this.gainNode.gain.setValueAtTime(this.muted?0:this.volume,this.ctx.currentTime),this.gainNode.connect(this.ctx.destination),this.unlockAudio())},o.prototype.unlockAudio=function(){var t=this;if(this.ctx&&this.audioLocked){var e=function e(){if(t.ctx){var o=function(){document.body.removeEventListener("touchstart",e),document.body.removeEventListener("touchend",e),document.body.removeEventListener("click",e)};t.ctx.resume().then(o,o)}};document.body.addEventListener("touchstart",e),document.body.addEventListener("touchend",e),document.body.addEventListener("click",e)}},o.prototype.add=function(t){var o;return i(this,void 0,void 0,(function(){var n,i,s,u,a,c;return r(this,(function(r){switch(r.label){case 0:n=t.component,this.components.push(n),r.label=1;case 1:return r.trys.push([1,5,,6]),i=n.config,n.state="loading",[4,e.resource.getResource(i.resource)];case 2:return s=r.sent(),this.audioBufferCache[s.name]||!(null===(o=null==s?void 0:s.data)||void 0===o?void 0:o.audio)?[3,4]:(u=this.audioBufferCache,a=s.name,[4,this.decodeAudioData(s.data.audio,s.name)]);case 3:u[a]=r.sent(),r.label=4;case 4:return this.audioBufferCache[s.name]&&(n.systemContext=this.ctx,n.systemDestination=this.gainNode,n.onload(this.audioBufferCache[s.name])),[3,6];case 5:return c=r.sent(),this.onError&&this.onError(c),[3,6];case 6:return[2]}}))}))},o.prototype.decodeAudioData=function(t,e){var o=this;if(this.decodeAudioPromiseMap[e])return this.decodeAudioPromiseMap[e];var n=new Promise((function(n,i){o.ctx||i(new Error("No audio support"));var r=o.ctx.decodeAudioData(t,(function(t){o.decodeAudioPromiseMap[e]&&delete o.decodeAudioPromiseMap[e],t?n(t):i(new Error("Error decoding audio "+e))}),(function(n){o.decodeAudioPromiseMap[e]&&delete o.decodeAudioPromiseMap[e],i(new Error(n+". arrayBuffer byteLength: "+(t?t.byteLength:0)))}));r instanceof Promise&&r.catch((function(e){i(new Error("catch "+e+", arrayBuffer byteLength: "+(t?t.byteLength:0)))}))}));return this.decodeAudioPromiseMap[e]=n,n},o.systemName="SoundSystem",o=function(t,e,o,n){var i,r=arguments.length,s=r<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,o,n);else for(var u=t.length-1;u>=0;u--)(i=t[u])&&(s=(r<3?i(s):r>3?i(e,o,s):i(e,o))||s);return r>3&&s&&Object.defineProperty(e,o,s),s}([e.decorators.componentObserver({Sound:[]})],o)}(e.System),u=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.state="unloaded",e.config={resource:"",autoplay:!1,muted:!1,volume:1,loop:!1,seek:0},e.playTime=0,e.startTime=0,e.duration=0,e.actionQueue=[],e}return n(e,t),Object.defineProperty(e.prototype,"muted",{get:function(){return!!this.gainNode&&0===this.gainNode.gain.value},set:function(t){this.gainNode&&this.gainNode.gain.setValueAtTime(t?0:this.config.volume,0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"volume",{get:function(){return this.gainNode?this.gainNode.gain.value:1},set:function(t){"number"!=typeof t||t<0||t>1||(this.config.volume=t,this.gainNode&&this.gainNode.gain.setValueAtTime(t,0))},enumerable:!1,configurable:!0}),e.prototype.init=function(t){t&&(_extends(this.config,t),this.config.autoplay&&this.actionQueue.push(this.play.bind(this)))},e.prototype.play=function(){var t=this;if("loaded"!==this.state&&this.actionQueue.push(this.play.bind(this)),this.destroySource(),this.createSource(),this.sourceNode){var e=this.systemContext.currentTime,o=this.config.seek,n=this.config.duration;this.sourceNode.start(0,o,n),this.startTime=e,this.playTime=e-o,this.paused=!1,this.playing=!0,this.resetConfig(),this.endedListener=function(){t.sourceNode&&(t.config.onEnd&&t.config.onEnd(),t.playing&&t.destroySource())},this.sourceNode.addEventListener("ended",this.endedListener)}},e.prototype.pause=function(){"loaded"!==this.state&&this.actionQueue.push(this.pause.bind(this)),!this.paused&&this.playing&&(this.paused=!0,this.playing=!1,this.config.seek=this.getCurrentTime(),this.destroySource())},e.prototype.stop=function(){"loaded"!==this.state&&this.actionQueue.push(this.stop.bind(this)),(this.paused||this.playing)&&(this.playing=!1,this.paused=!1,this.destroySource(),this.resetConfig())},e.prototype.onload=function(t){this.state="loaded",this.buffer=t,this.duration=this.buffer.duration,this.actionQueue.forEach((function(t){return t()})),this.actionQueue.length=0},e.prototype.onDestroy=function(){this.actionQueue.length=0,this.destroySource()},e.prototype.resetConfig=function(){this.config.seek=0},e.prototype.getCurrentTime=function(){return this.config.loop&&this.duration>0?(this.systemContext.currentTime-this.playTime)%this.duration:this.systemContext.currentTime-this.playTime},e.prototype.createSource=function(){this.systemContext&&"loaded"===this.state&&(this.sourceNode=this.systemContext.createBufferSource(),this.sourceNode.buffer=this.buffer,this.sourceNode.loop=this.config.loop,this.gainNode||(this.gainNode=this.systemContext.createGain(),this.gainNode.connect(this.systemDestination),_extends(this,this.config)),this.sourceNode.connect(this.gainNode))},e.prototype.destroySource=function(){this.sourceNode&&(this.sourceNode.removeEventListener("ended",this.endedListener),this.sourceNode.stop(),this.sourceNode.disconnect(),this.sourceNode=null,this.startTime=0,this.playTime=0,this.playing=!1)},e.componentName="Sound",e}(e.Component);return t.Sound=u,t.SoundSystem=s,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA);
@@ -311,20 +311,29 @@ var SoundSystem = (function (_super) {
311
311
  if (!_this.ctx) {
312
312
  reject(new Error('No audio support'));
313
313
  }
314
- _this.ctx.decodeAudioData(arraybuffer).then(function (decodedData) {
314
+ var success = function (decodedData) {
315
+ if (_this.decodeAudioPromiseMap[name]) {
316
+ delete _this.decodeAudioPromiseMap[name];
317
+ }
315
318
  if (decodedData) {
316
319
  resolve(decodedData);
317
320
  }
318
321
  else {
319
322
  reject(new Error("Error decoding audio " + name));
320
323
  }
321
- }).catch(function (error) {
322
- reject(new Error(error + ". arrayBuffer byteLength: " + (arraybuffer ? arraybuffer.byteLength : 0)));
323
- }).finally(function () {
324
+ };
325
+ var error = function (err) {
324
326
  if (_this.decodeAudioPromiseMap[name]) {
325
327
  delete _this.decodeAudioPromiseMap[name];
326
328
  }
327
- });
329
+ reject(new Error(err + ". arrayBuffer byteLength: " + (arraybuffer ? arraybuffer.byteLength : 0)));
330
+ };
331
+ var promise = _this.ctx.decodeAudioData(arraybuffer, success, error);
332
+ if (promise instanceof Promise) {
333
+ promise.catch(function (err) {
334
+ reject(new Error("catch " + err + ", arrayBuffer byteLength: " + (arraybuffer ? arraybuffer.byteLength : 0)));
335
+ });
336
+ }
328
337
  });
329
338
  this.decodeAudioPromiseMap[name] = promise;
330
339
  return promise;
@@ -12,4 +12,4 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
12
12
 
13
13
  See the Apache Version 2.0 License for specific language governing permissions
14
14
  and limitations under the License.
15
- ***************************************************************************** */function o(t,o){function n(){this.constructor=t}e(t,o),t.prototype=null===o?Object.create(o):(n.prototype=o.prototype,new n)}function n(t,e,o,n){return new(o||(o=Promise))((function(i,s){function r(t){try{a(n.next(t))}catch(t){s(t)}}function u(t){try{a(n.throw(t))}catch(t){s(t)}}function a(t){t.done?i(t.value):new o((function(e){e(t.value)})).then(r,u)}a((n=n.apply(t,e||[])).next())}))}function i(t,e){var o,n,i,s,r={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function u(s){return function(u){return function(s){if(o)throw new TypeError("Generator is already executing.");for(;r;)try{if(o=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return r.label++,{value:s[1],done:!1};case 5:r.label++,n=s[1],s=[0];continue;case 7:s=r.ops.pop(),r.trys.pop();continue;default:if(!(i=r.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){r=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){r.label=s[1];break}if(6===s[0]&&r.label<i[1]){r.label=i[1],i=s;break}if(i&&r.label<i[2]){r.label=i[2],r.ops.push(s);break}i[2]&&r.ops.pop(),r.trys.pop();continue}s=e.call(t,r)}catch(t){s=[6,t],n=0}finally{o=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}var s=function(e){function s(t){var o=e.call(this)||this;return o.autoPauseAndStart=!0,o.components=[],o.pausedComponents=[],o.audioBufferCache={},o.decodeAudioPromiseMap={},Object.assign(o,t),o}return o(s,e),Object.defineProperty(s.prototype,"muted",{get:function(){return!!this.gainNode&&0===this.gainNode.gain.value},set:function(t){this.gainNode&&this.gainNode.gain.setValueAtTime(t?0:1,0)},enumerable:!1,configurable:!0}),Object.defineProperty(s.prototype,"volume",{get:function(){return this.gainNode?this.gainNode.gain.value:1},set:function(t){!this.gainNode||"number"!=typeof t||t<0||t>1||this.gainNode.gain.setValueAtTime(t,0)},enumerable:!1,configurable:!0}),Object.defineProperty(s.prototype,"audioLocked",{get:function(){return!this.ctx||"running"!==this.ctx.state},enumerable:!1,configurable:!0}),s.prototype.resumeAll=function(){var t=this,e=function(){t.pausedComponents.forEach((function(t){t.play()})),t.pausedComponents=[]};this.ctx.resume().then(e,e)},s.prototype.pauseAll=function(){var t=this;this.components.forEach((function(e){e.playing&&(t.pausedComponents.push(e),e.pause())})),this.ctx.suspend().then()},s.prototype.stopAll=function(){this.components.forEach((function(t){t.playing&&t.stop()})),this.pausedComponents=[],this.ctx.suspend().then()},s.prototype.init=function(){this.setupAudioContext()},s.prototype.update=function(){var t,e,o=this.componentObserver.clear();try{for(var n=function(t){var e="function"==typeof Symbol&&t[Symbol.iterator],o=0;return e?e.call(t):{next:function(){return t&&o>=t.length&&(t=void 0),{value:t&&t[o++],done:!t}}}}(o),i=n.next();!i.done;i=n.next()){var s=i.value;this.componentChanged(s)}}catch(e){t={error:e}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(t)throw t.error}}},s.prototype.onResume=function(){this.autoPauseAndStart&&this.resumeAll()},s.prototype.onPause=function(){this.autoPauseAndStart&&this.pauseAll()},s.prototype.onDestroy=function(){this.components.forEach((function(t){t.onDestroy()})),this.components=[],this.ctx&&(this.gainNode.disconnect(),this.gainNode=null,this.ctx.close(),this.ctx=null)},s.prototype.componentChanged=function(e){return n(this,void 0,void 0,(function(){return i(this,(function(o){return"Sound"!==e.componentName||e.type===t.OBSERVER_TYPE.ADD&&this.add(e),[2]}))}))},s.prototype.setupAudioContext=function(){try{var t=window.AudioContext||window.webkitAudioContext;this.ctx=new t}catch(t){console.error(t),this.onError&&this.onError(t)}this.ctx&&(this.gainNode=void 0===this.ctx.createGain?this.ctx.createGainNode():this.ctx.createGain(),this.gainNode.gain.setValueAtTime(this.muted?0:this.volume,this.ctx.currentTime),this.gainNode.connect(this.ctx.destination),this.unlockAudio())},s.prototype.unlockAudio=function(){var t=this;if(this.ctx&&this.audioLocked){var e=function(){if(t.ctx){var o=function(){document.body.removeEventListener("touchstart",e),document.body.removeEventListener("touchend",e),document.body.removeEventListener("click",e)};t.ctx.resume().then(o,o)}};document.body.addEventListener("touchstart",e),document.body.addEventListener("touchend",e),document.body.addEventListener("click",e)}},s.prototype.add=function(e){var o;return n(this,void 0,void 0,(function(){var n,s,r,u,a,c;return i(this,(function(i){switch(i.label){case 0:n=e.component,this.components.push(n),i.label=1;case 1:return i.trys.push([1,5,,6]),s=n.config,n.state="loading",[4,t.resource.getResource(s.resource)];case 2:return r=i.sent(),this.audioBufferCache[r.name]||!(null===(o=null==r?void 0:r.data)||void 0===o?void 0:o.audio)?[3,4]:(u=this.audioBufferCache,a=r.name,[4,this.decodeAudioData(r.data.audio,r.name)]);case 3:u[a]=i.sent(),i.label=4;case 4:return this.audioBufferCache[r.name]&&(n.systemContext=this.ctx,n.systemDestination=this.gainNode,n.onload(this.audioBufferCache[r.name])),[3,6];case 5:return c=i.sent(),this.onError&&this.onError(c),[3,6];case 6:return[2]}}))}))},s.prototype.decodeAudioData=function(t,e){var o=this;if(this.decodeAudioPromiseMap[e])return this.decodeAudioPromiseMap[e];var n=new Promise((function(n,i){o.ctx||i(new Error("No audio support")),o.ctx.decodeAudioData(t).then((function(t){t?n(t):i(new Error("Error decoding audio "+e))})).catch((function(e){i(new Error(e+". arrayBuffer byteLength: "+(t?t.byteLength:0)))})).finally((function(){o.decodeAudioPromiseMap[e]&&delete o.decodeAudioPromiseMap[e]}))}));return this.decodeAudioPromiseMap[e]=n,n},s.systemName="SoundSystem",s=function(t,e,o,n){var i,s=arguments.length,r=s<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,o,n);else for(var u=t.length-1;u>=0;u--)(i=t[u])&&(r=(s<3?i(r):s>3?i(e,o,r):i(e,o))||r);return s>3&&r&&Object.defineProperty(e,o,r),r}([t.decorators.componentObserver({Sound:[]})],s)}(t.System),r=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.state="unloaded",e.config={resource:"",autoplay:!1,muted:!1,volume:1,loop:!1,seek:0},e.playTime=0,e.startTime=0,e.duration=0,e.actionQueue=[],e}return o(e,t),Object.defineProperty(e.prototype,"muted",{get:function(){return!!this.gainNode&&0===this.gainNode.gain.value},set:function(t){this.gainNode&&this.gainNode.gain.setValueAtTime(t?0:this.config.volume,0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"volume",{get:function(){return this.gainNode?this.gainNode.gain.value:1},set:function(t){"number"!=typeof t||t<0||t>1||(this.config.volume=t,this.gainNode&&this.gainNode.gain.setValueAtTime(t,0))},enumerable:!1,configurable:!0}),e.prototype.init=function(t){t&&(Object.assign(this.config,t),this.config.autoplay&&this.actionQueue.push(this.play.bind(this)))},e.prototype.play=function(){var t=this;if("loaded"!==this.state&&this.actionQueue.push(this.play.bind(this)),this.destroySource(),this.createSource(),this.sourceNode){var e=this.systemContext.currentTime,o=this.config.seek,n=this.config.duration;this.sourceNode.start(0,o,n),this.startTime=e,this.playTime=e-o,this.paused=!1,this.playing=!0,this.resetConfig(),this.endedListener=function(){t.sourceNode&&(t.config.onEnd&&t.config.onEnd(),t.playing&&t.destroySource())},this.sourceNode.addEventListener("ended",this.endedListener)}},e.prototype.pause=function(){"loaded"!==this.state&&this.actionQueue.push(this.pause.bind(this)),!this.paused&&this.playing&&(this.paused=!0,this.playing=!1,this.config.seek=this.getCurrentTime(),this.destroySource())},e.prototype.stop=function(){"loaded"!==this.state&&this.actionQueue.push(this.stop.bind(this)),(this.paused||this.playing)&&(this.playing=!1,this.paused=!1,this.destroySource(),this.resetConfig())},e.prototype.onload=function(t){this.state="loaded",this.buffer=t,this.duration=this.buffer.duration,this.actionQueue.forEach((function(t){return t()})),this.actionQueue.length=0},e.prototype.onDestroy=function(){this.actionQueue.length=0,this.destroySource()},e.prototype.resetConfig=function(){this.config.seek=0},e.prototype.getCurrentTime=function(){return this.config.loop&&this.duration>0?(this.systemContext.currentTime-this.playTime)%this.duration:this.systemContext.currentTime-this.playTime},e.prototype.createSource=function(){this.systemContext&&"loaded"===this.state&&(this.sourceNode=this.systemContext.createBufferSource(),this.sourceNode.buffer=this.buffer,this.sourceNode.loop=this.config.loop,this.gainNode||(this.gainNode=this.systemContext.createGain(),this.gainNode.connect(this.systemDestination),Object.assign(this,this.config)),this.sourceNode.connect(this.gainNode))},e.prototype.destroySource=function(){this.sourceNode&&(this.sourceNode.removeEventListener("ended",this.endedListener),this.sourceNode.stop(),this.sourceNode.disconnect(),this.sourceNode=null,this.startTime=0,this.playTime=0,this.playing=!1)},e.componentName="Sound",e}(t.Component);exports.Sound=r,exports.SoundSystem=s;
15
+ ***************************************************************************** */function o(t,o){function n(){this.constructor=t}e(t,o),t.prototype=null===o?Object.create(o):(n.prototype=o.prototype,new n)}function n(t,e,o,n){return new(o||(o=Promise))((function(i,r){function s(t){try{a(n.next(t))}catch(t){r(t)}}function u(t){try{a(n.throw(t))}catch(t){r(t)}}function a(t){t.done?i(t.value):new o((function(e){e(t.value)})).then(s,u)}a((n=n.apply(t,e||[])).next())}))}function i(t,e){var o,n,i,r,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return r={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function u(r){return function(u){return function(r){if(o)throw new TypeError("Generator is already executing.");for(;s;)try{if(o=1,n&&(i=2&r[0]?n.return:r[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,r[1])).done)return i;switch(n=0,i&&(r=[2&r[0],i.value]),r[0]){case 0:case 1:i=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,n=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==r[0]&&2!==r[0])){s=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3])){s.label=r[1];break}if(6===r[0]&&s.label<i[1]){s.label=i[1],i=r;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(r);break}i[2]&&s.ops.pop(),s.trys.pop();continue}r=e.call(t,s)}catch(t){r=[6,t],n=0}finally{o=i=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,u])}}}var r=function(e){function r(t){var o=e.call(this)||this;return o.autoPauseAndStart=!0,o.components=[],o.pausedComponents=[],o.audioBufferCache={},o.decodeAudioPromiseMap={},Object.assign(o,t),o}return o(r,e),Object.defineProperty(r.prototype,"muted",{get:function(){return!!this.gainNode&&0===this.gainNode.gain.value},set:function(t){this.gainNode&&this.gainNode.gain.setValueAtTime(t?0:1,0)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"volume",{get:function(){return this.gainNode?this.gainNode.gain.value:1},set:function(t){!this.gainNode||"number"!=typeof t||t<0||t>1||this.gainNode.gain.setValueAtTime(t,0)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"audioLocked",{get:function(){return!this.ctx||"running"!==this.ctx.state},enumerable:!1,configurable:!0}),r.prototype.resumeAll=function(){var t=this,e=function(){t.pausedComponents.forEach((function(t){t.play()})),t.pausedComponents=[]};this.ctx.resume().then(e,e)},r.prototype.pauseAll=function(){var t=this;this.components.forEach((function(e){e.playing&&(t.pausedComponents.push(e),e.pause())})),this.ctx.suspend().then()},r.prototype.stopAll=function(){this.components.forEach((function(t){t.playing&&t.stop()})),this.pausedComponents=[],this.ctx.suspend().then()},r.prototype.init=function(){this.setupAudioContext()},r.prototype.update=function(){var t,e,o=this.componentObserver.clear();try{for(var n=function(t){var e="function"==typeof Symbol&&t[Symbol.iterator],o=0;return e?e.call(t):{next:function(){return t&&o>=t.length&&(t=void 0),{value:t&&t[o++],done:!t}}}}(o),i=n.next();!i.done;i=n.next()){var r=i.value;this.componentChanged(r)}}catch(e){t={error:e}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(t)throw t.error}}},r.prototype.onResume=function(){this.autoPauseAndStart&&this.resumeAll()},r.prototype.onPause=function(){this.autoPauseAndStart&&this.pauseAll()},r.prototype.onDestroy=function(){this.components.forEach((function(t){t.onDestroy()})),this.components=[],this.ctx&&(this.gainNode.disconnect(),this.gainNode=null,this.ctx.close(),this.ctx=null)},r.prototype.componentChanged=function(e){return n(this,void 0,void 0,(function(){return i(this,(function(o){return"Sound"!==e.componentName||e.type===t.OBSERVER_TYPE.ADD&&this.add(e),[2]}))}))},r.prototype.setupAudioContext=function(){try{var t=window.AudioContext||window.webkitAudioContext;this.ctx=new t}catch(t){console.error(t),this.onError&&this.onError(t)}this.ctx&&(this.gainNode=void 0===this.ctx.createGain?this.ctx.createGainNode():this.ctx.createGain(),this.gainNode.gain.setValueAtTime(this.muted?0:this.volume,this.ctx.currentTime),this.gainNode.connect(this.ctx.destination),this.unlockAudio())},r.prototype.unlockAudio=function(){var t=this;if(this.ctx&&this.audioLocked){var e=function(){if(t.ctx){var o=function(){document.body.removeEventListener("touchstart",e),document.body.removeEventListener("touchend",e),document.body.removeEventListener("click",e)};t.ctx.resume().then(o,o)}};document.body.addEventListener("touchstart",e),document.body.addEventListener("touchend",e),document.body.addEventListener("click",e)}},r.prototype.add=function(e){var o;return n(this,void 0,void 0,(function(){var n,r,s,u,a,c;return i(this,(function(i){switch(i.label){case 0:n=e.component,this.components.push(n),i.label=1;case 1:return i.trys.push([1,5,,6]),r=n.config,n.state="loading",[4,t.resource.getResource(r.resource)];case 2:return s=i.sent(),this.audioBufferCache[s.name]||!(null===(o=null==s?void 0:s.data)||void 0===o?void 0:o.audio)?[3,4]:(u=this.audioBufferCache,a=s.name,[4,this.decodeAudioData(s.data.audio,s.name)]);case 3:u[a]=i.sent(),i.label=4;case 4:return this.audioBufferCache[s.name]&&(n.systemContext=this.ctx,n.systemDestination=this.gainNode,n.onload(this.audioBufferCache[s.name])),[3,6];case 5:return c=i.sent(),this.onError&&this.onError(c),[3,6];case 6:return[2]}}))}))},r.prototype.decodeAudioData=function(t,e){var o=this;if(this.decodeAudioPromiseMap[e])return this.decodeAudioPromiseMap[e];var n=new Promise((function(n,i){o.ctx||i(new Error("No audio support"));var r=o.ctx.decodeAudioData(t,(function(t){o.decodeAudioPromiseMap[e]&&delete o.decodeAudioPromiseMap[e],t?n(t):i(new Error("Error decoding audio "+e))}),(function(n){o.decodeAudioPromiseMap[e]&&delete o.decodeAudioPromiseMap[e],i(new Error(n+". arrayBuffer byteLength: "+(t?t.byteLength:0)))}));r instanceof Promise&&r.catch((function(e){i(new Error("catch "+e+", arrayBuffer byteLength: "+(t?t.byteLength:0)))}))}));return this.decodeAudioPromiseMap[e]=n,n},r.systemName="SoundSystem",r=function(t,e,o,n){var i,r=arguments.length,s=r<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,o,n);else for(var u=t.length-1;u>=0;u--)(i=t[u])&&(s=(r<3?i(s):r>3?i(e,o,s):i(e,o))||s);return r>3&&s&&Object.defineProperty(e,o,s),s}([t.decorators.componentObserver({Sound:[]})],r)}(t.System),s=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.state="unloaded",e.config={resource:"",autoplay:!1,muted:!1,volume:1,loop:!1,seek:0},e.playTime=0,e.startTime=0,e.duration=0,e.actionQueue=[],e}return o(e,t),Object.defineProperty(e.prototype,"muted",{get:function(){return!!this.gainNode&&0===this.gainNode.gain.value},set:function(t){this.gainNode&&this.gainNode.gain.setValueAtTime(t?0:this.config.volume,0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"volume",{get:function(){return this.gainNode?this.gainNode.gain.value:1},set:function(t){"number"!=typeof t||t<0||t>1||(this.config.volume=t,this.gainNode&&this.gainNode.gain.setValueAtTime(t,0))},enumerable:!1,configurable:!0}),e.prototype.init=function(t){t&&(Object.assign(this.config,t),this.config.autoplay&&this.actionQueue.push(this.play.bind(this)))},e.prototype.play=function(){var t=this;if("loaded"!==this.state&&this.actionQueue.push(this.play.bind(this)),this.destroySource(),this.createSource(),this.sourceNode){var e=this.systemContext.currentTime,o=this.config.seek,n=this.config.duration;this.sourceNode.start(0,o,n),this.startTime=e,this.playTime=e-o,this.paused=!1,this.playing=!0,this.resetConfig(),this.endedListener=function(){t.sourceNode&&(t.config.onEnd&&t.config.onEnd(),t.playing&&t.destroySource())},this.sourceNode.addEventListener("ended",this.endedListener)}},e.prototype.pause=function(){"loaded"!==this.state&&this.actionQueue.push(this.pause.bind(this)),!this.paused&&this.playing&&(this.paused=!0,this.playing=!1,this.config.seek=this.getCurrentTime(),this.destroySource())},e.prototype.stop=function(){"loaded"!==this.state&&this.actionQueue.push(this.stop.bind(this)),(this.paused||this.playing)&&(this.playing=!1,this.paused=!1,this.destroySource(),this.resetConfig())},e.prototype.onload=function(t){this.state="loaded",this.buffer=t,this.duration=this.buffer.duration,this.actionQueue.forEach((function(t){return t()})),this.actionQueue.length=0},e.prototype.onDestroy=function(){this.actionQueue.length=0,this.destroySource()},e.prototype.resetConfig=function(){this.config.seek=0},e.prototype.getCurrentTime=function(){return this.config.loop&&this.duration>0?(this.systemContext.currentTime-this.playTime)%this.duration:this.systemContext.currentTime-this.playTime},e.prototype.createSource=function(){this.systemContext&&"loaded"===this.state&&(this.sourceNode=this.systemContext.createBufferSource(),this.sourceNode.buffer=this.buffer,this.sourceNode.loop=this.config.loop,this.gainNode||(this.gainNode=this.systemContext.createGain(),this.gainNode.connect(this.systemDestination),Object.assign(this,this.config)),this.sourceNode.connect(this.gainNode))},e.prototype.destroySource=function(){this.sourceNode&&(this.sourceNode.removeEventListener("ended",this.endedListener),this.sourceNode.stop(),this.sourceNode.disconnect(),this.sourceNode=null,this.startTime=0,this.playTime=0,this.playing=!1)},e.componentName="Sound",e}(t.Component);exports.Sound=s,exports.SoundSystem=r;
@@ -307,20 +307,29 @@ var SoundSystem = (function (_super) {
307
307
  if (!_this.ctx) {
308
308
  reject(new Error('No audio support'));
309
309
  }
310
- _this.ctx.decodeAudioData(arraybuffer).then(function (decodedData) {
310
+ var success = function (decodedData) {
311
+ if (_this.decodeAudioPromiseMap[name]) {
312
+ delete _this.decodeAudioPromiseMap[name];
313
+ }
311
314
  if (decodedData) {
312
315
  resolve(decodedData);
313
316
  }
314
317
  else {
315
318
  reject(new Error("Error decoding audio " + name));
316
319
  }
317
- }).catch(function (error) {
318
- reject(new Error(error + ". arrayBuffer byteLength: " + (arraybuffer ? arraybuffer.byteLength : 0)));
319
- }).finally(function () {
320
+ };
321
+ var error = function (err) {
320
322
  if (_this.decodeAudioPromiseMap[name]) {
321
323
  delete _this.decodeAudioPromiseMap[name];
322
324
  }
323
- });
325
+ reject(new Error(err + ". arrayBuffer byteLength: " + (arraybuffer ? arraybuffer.byteLength : 0)));
326
+ };
327
+ var promise = _this.ctx.decodeAudioData(arraybuffer, success, error);
328
+ if (promise instanceof Promise) {
329
+ promise.catch(function (err) {
330
+ reject(new Error("catch " + err + ", arrayBuffer byteLength: " + (arraybuffer ? arraybuffer.byteLength : 0)));
331
+ });
332
+ }
324
333
  });
325
334
  this.decodeAudioPromiseMap[name] = promise;
326
335
  return promise;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-sound",
3
- "version": "1.2.0-alpha.2",
3
+ "version": "1.2.0-alpha.3",
4
4
  "description": "@eva/plugin-sound",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-sound.esm.js",
@@ -18,7 +18,7 @@
18
18
  "license": "MIT",
19
19
  "homepage": "https://eva.js.org",
20
20
  "dependencies": {
21
- "@eva/eva.js": "1.2.0-alpha.2",
21
+ "@eva/eva.js": "1.2.0-alpha.3",
22
22
  "eventemitter3": "^3.1.2"
23
23
  }
24
24
  }