Skip to main content

removeEventListener

removeEventListener(
type: SoundEventsEnum,
callback: (event: SoundEvent) => void,
filter?: { originalId?: string; instancePattern?: RegExp }
): void;

Remove an event listener for a specific SoundEventsEnum type. Optionally, provide a filter to narrow down the events.

ParameterTypeDescription
typeSoundEventsEnumThe event type to stop listening for
callback(event: SoundEvent) => voidThe callback function that was originally registered
filter{ originalId?: string; instancePattern?: RegExp } (optional)Filter that was used when adding the listener

Filter Options

PropertyTypeDescription
originalIdstring (optional)Only remove listeners registered for a specific sound ID
instancePatternRegExp (optional)Only remove listeners registered with a specific instance pattern

Example

import { SoundHub, SoundEventsEnum } from 'soundhub';

const soundHub = new SoundHub();

const onPlay = (event) => {
console.log('Sound played:', event);
};

// Add listener
soundHub.addEventListener(SoundEventsEnum.PLAY, onPlay);

// Remove listener
soundHub.removeEventListener(SoundEventsEnum.PLAY, onPlay);