Skip to content

Commit 6dbc4e2

Browse files
committed
When targeting a build that unconditionally has AudioContext() API, do not emit code to check for its presence.
1 parent 598210e commit 6dbc4e2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/lib/libwebaudio.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ var LibraryWebAudio = {
5454
// this avoids the user needing to manually add the dependency on the command line.
5555
emscripten_create_audio_context__deps: ['$emscriptenRegisterAudioObject', '$emscriptenGetAudioObject'],
5656
emscripten_create_audio_context: (options) => {
57+
// Safari added unprefixed AudioContext support in Safari 14.5 on iOS: https://caniuse.com/audio-api
58+
#if MIN_SAFARI_VERSION < 140500 || ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL
5759
var ctx = window.AudioContext || window.webkitAudioContext;
5860
#if ASSERTIONS
5961
if (!ctx) console.error('emscripten_create_audio_context failed! Web Audio is not supported.');
62+
#endif
6063
#endif
6164

6265
var opts = options ? {
@@ -69,7 +72,12 @@ var LibraryWebAudio = {
6972
console.dir(opts);
7073
#endif
7174

75+
#if MIN_SAFARI_VERSION < 140500 || ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL
7276
return ctx && emscriptenRegisterAudioObject(new ctx(opts));
77+
#else
78+
// We are targeting an environment where we can assume that new AudioContext() will unconditionally succeed.
79+
return emscriptenRegisterAudioObject(new AudioContext(opts));
80+
#endif
7381
},
7482

7583
emscripten_resume_audio_context_async: (contextHandle, callback, userData) => {

0 commit comments

Comments
 (0)