Skip to content

Commit

Permalink
Fix bug in handling processSound callback when sound hadn't loaded yet (
Browse files Browse the repository at this point in the history
#5414)

Co-authored-by: Noeri Huisman <mrxz@users.noreply.github.com>
  • Loading branch information
mrxz and mrxz authored Dec 15, 2023
1 parent 17f06f6 commit 6882858
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/sound.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module.exports.Component = registerComponent('sound', {

// Remove this key from cache, otherwise we can't play it again
THREE.Cache.remove(data.src);
if (self.data.autoplay || self.mustPlay) { self.playSound(this.processSound); }
if (self.data.autoplay || self.mustPlay) { self.playSound(self.processSound); }
self.el.emit('sound-loaded', self.evtDetail, false);
});
}
Expand Down
17 changes: 17 additions & 0 deletions tests/components/sound.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,23 @@ suite('sound', function () {
assert.ok(sound.play.called);
});

test('plays sound and calls processSound callback when not loaded', function (done) {
var el = this.el;
var processSoundStub = sinon.stub();

el.setAttribute('sound', 'src', 'url(base/tests/assets/test.ogg)');
el.components.sound.playSound(processSoundStub);
assert.notOk(el.components.sound.isPlaying);
assert.ok(el.components.sound.mustPlay);

el.addEventListener('sound-loaded', function () {
assert.ok(el.components.sound.isPlaying);
assert.notOk(el.components.sound.mustPlay);
assert.ok(processSoundStub.calledOnce);
done();
});
});

test('plays sound if sound already playing when changing src', function (done) {
var el = this.el;
var playSoundStub = el.components.sound.playSound = sinon.stub();
Expand Down

0 comments on commit 6882858

Please sign in to comment.