UNPKG

ts-audio

Version:

44 lines (43 loc) 1.61 kB
import type { EventEmitter } from './EventEmitter'; type callbackType = <T>(param: { [data: string]: T; }) => void; /** * EventHandler class to manage event listeners for an audio context. */ export declare class EventHandler { private emitter; private audioCtx; /** * Creates an instance of EventHandler. * @param emitter - The event emitter instance to manage event listeners. * @param audioCtx - AudioContext instance to monitor state changes. Optional to facilitate testing. */ constructor(emitter: EventEmitter, audioCtx?: AudioContext); /** * Registers a callback for the 'decoded' event. * @param callback - The callback to be invoked when the event occurs. */ ready(callback: callbackType): void; /** * Registers a callback for the 'start' event. * @param callback - The callback to be invoked when the event occurs. */ start(callback: callbackType): void; /** * Registers a callback for the 'end' event. * @param callback - The callback to be invoked when the event occurs. */ end(callback: callbackType): void; /** * Monitors the state changes of the AudioContext and invokes the callback. * @param callback - The callback to be invoked when the AudioContext state changes. */ state(callback: callbackType): void; /** * Disposes the EventHandler by removing the onstatechange listener from the AudioContext. * This method should be called when the EventHandler is no longer needed to prevent memory leaks. */ dispose(): void; } export {};