Files
Nitro-V3/src/api/utils/PlaySound.ts
T
DuckieTM 7feb10ab15 🆙 Init V3
2026-01-31 09:10:52 +01:00

25 lines
684 B
TypeScript

import { MouseEventType, NitroSoundEvent } from '@nitrots/nitro-renderer';
import { DispatchMainEvent } from '../events';
let canPlaySound = false;
export const PlaySound = (sampleCode: string) =>
{
if(!canPlaySound) return;
DispatchMainEvent(new NitroSoundEvent(NitroSoundEvent.PLAY_SOUND, sampleCode));
};
const eventTypes = [ MouseEventType.MOUSE_CLICK ];
const startListening = () =>
{
const stopListening = () => eventTypes.forEach(type => window.removeEventListener(type, onEvent));
const onEvent = (event: Event) => ((canPlaySound = true) && stopListening());
eventTypes.forEach(type => window.addEventListener(type, onEvent));
};
startListening();