Skip to content

Commit

Permalink
fix: resolved infinite invalidation loop caused by faulty soundproxy …
Browse files Browse the repository at this point in the history
…task. Updated dependencies
  • Loading branch information
jkeen committed Nov 18, 2021
1 parent fa660fa commit f830a88
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion addon/-private/utils/sound-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class SoundProxy extends Evented {
*waitForLoad() {
yield waitForProperty(this, 'url', (v) => !!v)
debug('ember-stereo:sound-proxy')(`waiting for ${this.url} to load`)
while (true) {
while (!this.value) {
let alreadyLoaded = this.stereo.findLoadedSound(this.url);
if (alreadyLoaded) {
this.value = alreadyLoaded;
Expand Down
17 changes: 11 additions & 6 deletions addon/modifiers/sound-position-progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import Modifier from 'ember-modifier';

import { once } from '@ember/runloop';
export default class SoundPositionProgressModifier extends Modifier {
@service stereo;

Expand All @@ -21,10 +21,14 @@ export default class SoundPositionProgressModifier extends Modifier {
}

get loadedSound() {
return this.stereo.findSound(this.url);
return this.stereo.findLoadedSound(this.url);
}

@action onPositionChange() {
once(this, this.modifyPosition, ...arguments, 500);
}

@action onPositionChange({ newPosition }) {
modifyPosition({ newPosition }) {
this.element.style.width = `${((newPosition || this.loadedSound.position) / this.loadedSound.duration) * 100}%`;
this.element.style.pointerEvents = 'none';
}
Expand All @@ -36,16 +40,17 @@ export default class SoundPositionProgressModifier extends Modifier {
didReceiveArguments() {
if (this.url) {
this.stereo.soundProxy(this.url).afterLoad(sound => {
sound.on('audio-position-will-change', this.onPositionChange);
sound.on('audio-position-changed', this.onPositionChange);
sound.on('audio-position-will-change', this.onPositionChange.bind(this));
sound.on('audio-position-changed', this.onPositionChange.bind(this));
})
}
}

willRemove() {
try {
if (this.loadedSound) {
this.loadedSound.off('audio-position-changed', this.onPositionChange);
this.loadedSound.off('audio-position-changed', this.onPositionChange.bind(this));
this.loadedSound.off('audio-position-will-change', this.onPositionChange.bind(this));
}
} catch (e) { /* geez, relax */ }
}
Expand Down
3 changes: 2 additions & 1 deletion addon/services/stereo.js
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,8 @@ export default class Stereo extends Service.extend(EmberEvented) {
return this.soundCache.find(identifiers);
}

findSound(identifier) {
findSound(_identifier) {
let identifier = new StereoUrl(_identifier).key
return this.soundProxy(identifier)?.value;

//TODO: use a Proxy? it'd be neat to be able to 'find' a sound
Expand Down

0 comments on commit f830a88

Please sign in to comment.