Skip to content

Commit 7821cf6

Browse files
committed
fix: don't fail loading immediately for NativeAudio if xhr options are supplied when NativeAudio is a connection; ignore xhr options instead
1 parent 967e110 commit 7821cf6

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

ember-stereo/src/-private/utils/strategizer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { isEmpty } from '@ember/utils';
66
import { cached } from 'tracked-toolbox';
77
import { assert } from '@ember/debug';
88
import { getOwner, setOwner } from '@ember/application';
9+
import debug from 'debug';
10+
911
export default class Strategizer {
1012
@tracked urls;
1113
@tracked options;
@@ -102,7 +104,10 @@ export default class Strategizer {
102104
strategies.push(this.buildStrategy(connection, url));
103105
});
104106
});
107+
105108
if (this.useMobileStrategy) {
109+
debug('ember-stereo:strategizer')(`re-rodering to prioritize native audio first`);
110+
106111
/*
107112
* Take our standard strategy and reorder it to prioritize native audio
108113
* first since it's most likely to succeed and play immediately with our

ember-stereo/src/stereo-connections/native-audio.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,8 @@ export default class NativeAudio extends BaseSound {
6363
}
6464

6565
if (this.options?.xhr) {
66-
return this.trigger('audio-load-error', {
67-
sound: this,
68-
error: 'xhr options are not supported in NativeAudio',
69-
});
66+
this.debug('xhr options are not supported in NativeAudio, ignoring and trying to load anyway')
67+
audio.load();
7068
} else {
7169
audio.load();
7270
}
@@ -435,7 +433,7 @@ export default class NativeAudio extends BaseSound {
435433
}
436434

437435
get shouldRetry() {
438-
return this.retryCount < 1 && !this.options?.xhr;
436+
return this.retryCount < 1;
439437
}
440438

441439
retry() {

test-app/tests/unit/stereo-connections/native-audio-test.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { module, test } from 'qunit';
1+
import { module, test, skip } from 'qunit';
22
import { setupTest } from 'ember-qunit';
33
import sinon from 'sinon';
44
import SharedAudioAccess from 'ember-stereo/-private/utils/shared-audio-access';
@@ -388,25 +388,17 @@ module('Unit | Connection | Native Audio', function (hooks) {
388388
);
389389
});
390390

391-
test('does not support xhr options', async function (assert) {
392-
assert.expect(2);
391+
skip('it ignores xhr options', async function (assert) {
393392
let stereo = this.owner.lookup('service:stereo');
394393
let url1 = '/good/5000/silence.mp3';
395394

396-
let { failures } = await stereo.load(url1, {
395+
await stereo.load(url1, {
397396
silenceErrors: true,
398397
useConnections: ['NativeAudio'],
399398
xhr: {
400399
withCredentials: true,
401400
},
402401
});
403-
404-
let erroredSound = failures[0]?.erroredSound;
405-
assert.strictEqual(erroredSound.retryCount, 0);
406-
assert.strictEqual(
407-
erroredSound.error,
408-
'xhr options are not supported in NativeAudio'
409-
);
410402
});
411403

412404
test('audio-position-changed events get fired', async function (assert) {

0 commit comments

Comments
 (0)