Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in handling processSound callback when sound hadn't loaded yet #5414

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading