Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const scheduleFunction = (id: number, delay: number, type: TTimerType) => {
const now = performance.now();
const audioBufferSourceNode = new AudioBufferSourceNode(MINIMAL_AUDIO_CONTEXT, { buffer: AUDIO_BUFFER });
audioBufferSourceNode.onended = () => {
const elapsedTime = performance.now() - now;
if (elapsedTime >= delay) {
callIntervalFunction(id, type);
} else {
scheduleFunction(id, delay - elapsedTime, type);
}
};
audioBufferSourceNode.connect(MINIMAL_AUDIO_CONTEXT.destination);
audioBufferSourceNode.start(Math.max(0, MINIMAL_AUDIO_CONTEXT.currentTime + (delay / 1000) - SAMPLE_DURATION));
};