Skip to content

Commit

Permalink
partially reintroduce decodeAudioData() patches for Chrome v61
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisguttandin committed Jun 9, 2017
1 parent a56d1ab commit 24255b7
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/providers/audio-context-constructor.ts
Expand Up @@ -507,6 +507,11 @@ export const AUDIO_CONTEXT_CONSTRUCTOR_PROVIDER = {

// Bug #21: Safari does not support promises yet.
if (this._isSupportingPromises) {
// Bug #1: Chrome requires a successCallback.
if (successCallback === undefined) {
successCallback = () => {}; // tslint:disable-line:no-empty
}

const promise = this._unpatchedAudioContext
.decodeAudioData(audioData, successCallback, (err: DOMException | Error) => {
if (typeof errorCallback === 'function') {
Expand Down
5 changes: 5 additions & 0 deletions src/providers/offline-audio-context-constructor.ts
Expand Up @@ -204,6 +204,11 @@ export const OFFLINE_AUDIO_CONTEXT_CONSTRUCTOR_PROVIDER = {

// Bug #21: Safari does not support promises yet.
if (this._isSupportingPromises) {
// Bug #1: Chrome requires a successCallback.
if (successCallback === undefined) {
successCallback = () => {}; // tslint:disable-line:no-empty
}

const promise = this._unpatchedOfflineAudioContext
.decodeAudioData(audioData, successCallback, (err: DOMException | Error) => {
if (typeof errorCallback === 'function') {
Expand Down
2 changes: 1 addition & 1 deletion src/testers/decode-audio-data-type-error-support.ts
Expand Up @@ -22,7 +22,7 @@ export class DecodeAudioDataTypeErrorSupportTester {
const audioContext = new this._unpatchedOfflineAudioContextConstructor(1, 1, 44100);

// Bug #21: Safari does not support promises yet.
// Bug #1: Safari requires a successCallback.
// Bug #1: Chrome Canary & Safari requires a successCallback.
return new Promise((resolve) => {
audioContext
.decodeAudioData(<any> null, () => {
Expand Down
2 changes: 1 addition & 1 deletion src/testers/promise-support.ts
Expand Up @@ -20,7 +20,7 @@ export class PromiseSupportTester {
]);

try {
// Bug #1: Safari requires a successCallback.
// Bug #1: Chrome Canary & Safari requires a successCallback.
const promise = audioContext.decodeAudioData(uint32Array.buffer, () => {
// Ignore the success callback.
});
Expand Down
18 changes: 18 additions & 0 deletions test/expectation/chrome/canary/audio-context-constructor.js
Expand Up @@ -2,6 +2,7 @@ import 'core-js/es7/reflect';
import { UNPATCHED_AUDIO_CONTEXT_CONSTRUCTOR_PROVIDER, unpatchedAudioContextConstructor } from '../../../../src/providers/unpatched-audio-context-constructor';
import { ReflectiveInjector } from '@angular/core';
import { WINDOW_PROVIDER } from '../../../../src/providers/window';
import { loadFixture } from '../../../helper/load-fixture';
import { spy } from 'sinon';

describe('audioContextConstructor', () => {
Expand Down Expand Up @@ -92,6 +93,23 @@ describe('audioContextConstructor', () => {

describe('decodeAudioData()', () => {

// bug #1

it('should require the success callback function as a parameter', (done) => {
loadFixture('1000-frames-of-noise.wav', (err, arrayBuffer) => {
expect(err).to.be.null;

audioContext
.decodeAudioData(arrayBuffer, undefined, () => {})
.catch((err) => {
expect(err).to.be.an.instanceOf(TypeError);
expect(err.message).to.equal("Failed to execute 'decodeAudioData' on 'BaseAudioContext': The callback provided as parameter 2 is not a function.");

done();
});
});
});

// bug #6

it('should not call the errorCallback at all', (done) => {
Expand Down
Expand Up @@ -2,6 +2,7 @@ import 'core-js/es7/reflect';
import { UNPATCHED_OFFLINE_AUDIO_CONTEXT_CONSTRUCTOR_PROVIDER, unpatchedOfflineAudioContextConstructor } from '../../../../src/providers/unpatched-offline-audio-context-constructor';
import { ReflectiveInjector } from '@angular/core';
import { WINDOW_PROVIDER } from '../../../../src/providers/window';
import { loadFixture } from '../../../helper/load-fixture';
import { spy } from 'sinon';

describe('offlineAudioContextConstructor', () => {
Expand Down Expand Up @@ -107,6 +108,23 @@ describe('offlineAudioContextConstructor', () => {

describe('decodeAudioData()', () => {

// bug #1

it('should require the success callback function as a parameter', (done) => {
loadFixture('1000-frames-of-noise.wav', (err, arrayBuffer) => {
expect(err).to.be.null;

offlineAudioContext
.decodeAudioData(arrayBuffer, undefined, () => {})
.catch((err) => {
expect(err).to.be.an.instanceOf(TypeError);
expect(err.message).to.equal("Failed to execute 'decodeAudioData' on 'BaseAudioContext': The callback provided as parameter 2 is not a function.");

done();
});
});
});

// bug #6

it('should not call the errorCallback at all', (done) => {
Expand Down

0 comments on commit 24255b7

Please sign in to comment.