audiojs / web-audio-api

Node.js implementation of Web audio API
MIT License
826 stars 67 forks source link

AudioContext's decodeAudioData() doesn't return a Promise when a callback is not given. #93

Open Type1J opened 1 year ago

Type1J commented 1 year ago

From what I can tell, this is already fixed, but there's been no release for a long time. I'll drop my polyfill that monkey patches this functionality into version 0.2.2, which is what you get from npm, right now.

import { AudioContext } from "web-audio-api";

export function installPolyfill() {
  function decodeAudioData_polyfill(audioData, successCallback, errorCallback) {
    if (arguments.length > 1) {
      // Callback
      this.decodeAudioData(audioData, successCallback, errorCallback);
    } else {
      // Promise
      return new Promise((success, reject) => this.decodeAudioData_original(audioData, success, reject));
    }   
  }
  if (!AudioContext.prototype.decodeAudioData_original) {
    AudioContext.prototype.decodeAudioData_original = AudioContext.prototype.decodeAudioData;
    AudioContext.prototype.decodeAudioData = decodeAudioData_polyfill;
  }
}

Please release sometime soon. Until then, please leave this issue open, so that someone having this problem can find this solution.