Skip to content

Commit c4c7cf3

Browse files
committed
Cleanup legacy browser support in libopenal.js. NFC
This brings libopenal.js inline with libwebaudio.js in a couple of ways: - Only support webkitAudioContext on older safari versions. - Drop support for `new AudioContext` that does not accept options. This change should make is easy for us to remove this support once we drop support for Safari < 14.5.
1 parent 86ea17d commit c4c7cf3

2 files changed

Lines changed: 23 additions & 15 deletions

File tree

src/lib/libopenal.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ var LibraryOpenAL = {
2020
QUEUE_INTERVAL: 25,
2121
QUEUE_LOOKAHEAD: 100.0 / 1000.0,
2222

23+
#if MIN_SAFARI_VERSION < 140500
24+
AudioContext: globalThis.AudioContext ?? globalThis.webkitAudioContext,
25+
#else
26+
AudioContext: globalThis.AudioContext,
27+
#endif
28+
2329
DEVICE_NAME: 'Emscripten OpenAL',
2430
CAPTURE_DEVICE_NAME: 'Emscripten OpenAL capture',
2531

@@ -1649,7 +1655,11 @@ var LibraryOpenAL = {
16491655
return 0;
16501656
}
16511657
1652-
var AudioContext = window.AudioContext || window.webkitAudioContext;
1658+
#if MIN_SAFARI_VERSION < 140500
1659+
// We depend on the global AudioContext for modern browser, but
1660+
// old older safari versions we may still need to use webkitAudioContext.
1661+
var AudioContext = AL.AudioContext;
1662+
#endif
16531663
16541664
if (!AL.sharedCaptureAudioCtx) {
16551665
try {
@@ -2047,7 +2057,7 @@ var LibraryOpenAL = {
20472057
}
20482058
}
20492059
2050-
if (globalThis.AudioContext || globalThis.webkitAudioContext) {
2060+
if (AL.AudioContext) {
20512061
var deviceId = AL.newId();
20522062
AL.deviceRefCounts[deviceId] = 0;
20532063
return deviceId;
@@ -2077,7 +2087,7 @@ var LibraryOpenAL = {
20772087
return 0;
20782088
}
20792089
2080-
var options = null;
2090+
var options;
20812091
var attrs = [];
20822092
var hrtf = null;
20832093
pAttrList >>= 2;
@@ -2142,15 +2152,13 @@ var LibraryOpenAL = {
21422152
}
21432153
}
21442154
2145-
var AudioContext = window.AudioContext || window.webkitAudioContext;
2146-
var ac = null;
2155+
#if MIN_SAFARI_VERSION < 140500
2156+
var AudioContext = window.AudioContext ?? window.webkitAudioContext;
2157+
#endif
2158+
2159+
var ac;
21472160
try {
2148-
// Only try to pass options if there are any, for compat with browsers that don't support this
2149-
if (options) {
2150-
ac = new AudioContext(options);
2151-
} else {
2152-
ac = new AudioContext();
2153-
}
2161+
ac = new AudioContext(options);
21542162
} catch (e) {
21552163
if (e.name === 'NotSupportedError') {
21562164
#if OPENAL_DEBUG
@@ -2372,14 +2380,14 @@ var LibraryOpenAL = {
23722380
ret = 'Out of Memory';
23732381
break;
23742382
case 0x1004 /* ALC_DEFAULT_DEVICE_SPECIFIER */:
2375-
if (globalThis.AudioContext || globalThis.webkitAudioContext) {
2383+
if (AL.AudioContext) {
23762384
ret = AL.DEVICE_NAME;
23772385
} else {
23782386
return 0;
23792387
}
23802388
break;
23812389
case 0x1005 /* ALC_DEVICE_SPECIFIER */:
2382-
if (globalThis.AudioContext || globalThis.webkitAudioContext) {
2390+
if (AL.AudioContext) {
23832391
ret = AL.DEVICE_NAME + '\0';
23842392
} else {
23852393
ret = '\0';

test/codesize/test_codesize_hello_dylink_all.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"a.out.js": 267933,
2+
"a.out.js": 267629,
33
"a.out.nodebug.wasm": 588309,
4-
"total": 856242,
4+
"total": 855938,
55
"sent": [
66
"IMG_Init",
77
"IMG_Load",

0 commit comments

Comments
 (0)