removeEventListenersForInstance
Remove every listener that was added with an instanceId filter for this id, whatever event type it listens to. The hub calls this itself when a sound stops or ends, so you rarely need it.
removeEventListenersForInstance(instanceId: string): void;
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
instanceId | string | required | The instance id used in the filter, such as 'laser:3', or a plain sound id such as 'music'. |
Returns
Nothing.
Example
import { SoundHub, SoundEventsEnum } from 'soundhub';
const soundHub = new SoundHub();
await soundHub.loadSound('laser', '/audio/laser.mp3');
soundHub.play('laser', { overlap: true, trackProgress: true }); // becomes 'laser:1'
soundHub.addEventListener(SoundEventsEnum.PROGRESS, (event) => {
console.log(event.progress);
}, { instanceId: 'laser:1' });
soundHub.addEventListener(SoundEventsEnum.ENDED, () => {
console.log('laser:1 done');
}, { instanceId: 'laser:1' });
// Drop both at once
soundHub.removeEventListenersForInstance('laser:1');
Good to know
- Only listeners whose filter has exactly this
instanceIdare removed. Listeners filtered onsoundId,originalIdorinstancePattern, and listeners without a filter, stay. - The hub already runs this for a sound or instance when it is stopped, when it ends (after the
endedevent has been delivered) and when it is cleaned up. AninstanceIdlistener therefore lasts for one playback. - No event is dispatched.
See also
removeEventListener: remove one listener by callback and filter.addEventListener: the filter fields explained.hasEventListener: check whether any listener is left for a type.