Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix bug in handling processSound callback when sound hadn't loaded yet
  • Loading branch information
mrxz committed Dec 15, 2023
commit 0c44ebc84e49e306a671dfe7ad1a50923f75ecf0
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