Skip to content

Commit

Permalink
catch unhandled Promise in decodeAudioData (katspaugh#2079)
Browse files Browse the repository at this point in the history
* ci: disable Chrome for now

headless is broken since Chrome 83 for some reason.

* use Chrome_dev locally

* test: fix precision varying on different platforms

* use promise-based syntax for decodeAudioData and make exception for Safari
  • Loading branch information
thijstriemstra committed Oct 2, 2020
1 parent a33cea8 commit 1a8fea7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ module.exports = function(config) {
'karma-coveralls',
'karma-verbose-reporter'
],
browsers: ['Chrome_ci', 'Firefox_dev'],
browsers: ['Chrome_dev', 'Firefox_dev'],
captureConsole: true,
colors: true,
reporters: ['verbose', 'progress', 'coverage'],
Expand Down Expand Up @@ -125,7 +125,7 @@ module.exports = function(config) {
};

if (ci) {
configuration.browsers = ['Chrome_ci', 'Firefox_ci'];
configuration.browsers = ['Firefox_ci'];

if (process.env.TRAVIS) {
// enable coveralls
Expand Down
2 changes: 1 addition & 1 deletion spec/drawer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('Drawer', function() {
it('handleEvent should return 1 if clicked on wrapper right position', function() {
const {right} = drawer.wrapper.getBoundingClientRect();

expect(drawer.handleEvent({clientX: right}, true)).toBe(1);
expect(drawer.handleEvent({clientX: right}, true)).toBeCloseTo(1, 3);
});

/** @test {handleEvent/right+1} */
Expand Down
19 changes: 14 additions & 5 deletions src/webaudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,20 @@ export default class WebAudio extends util.Observer {
this.ac && this.ac.sampleRate ? this.ac.sampleRate : 44100
);
}
this.offlineAc.decodeAudioData(
arraybuffer,
data => callback(data),
errback
);
if ('AudioContext' in window) {
this.offlineAc.decodeAudioData(arraybuffer).then(
(data) => callback(data)
).catch(
(err) => errback(err)
);
} else {
// Safari: no support for Promise-based decodeAudioData yet
this.offlineAc.decodeAudioData(
arraybuffer,
data => callback(data),
errback
);
}
}

/**
Expand Down

0 comments on commit 1a8fea7

Please sign in to comment.