mirror of
https://github.com/billsonnn/nitro-react.git
synced 2025-01-31 10:22:36 +01:00
Sound fix for play() before interaction
This commit is contained in:
parent
e8316e3837
commit
dee2b25d8e
@ -1,7 +1,25 @@
|
|||||||
|
import { MouseEventType, TouchEventType } from '@nitrots/nitro-renderer';
|
||||||
import { NitroSoundEvent } from '@nitrots/nitro-renderer/src/nitro/events/NitroSoundEvent';
|
import { NitroSoundEvent } from '@nitrots/nitro-renderer/src/nitro/events/NitroSoundEvent';
|
||||||
import { DispatchMainEvent } from '../../hooks';
|
import { DispatchMainEvent } from '../../hooks';
|
||||||
|
|
||||||
export function PlaySound(sampleCode: string): void
|
let canPlaySound = false;
|
||||||
|
|
||||||
|
export const PlaySound = (sampleCode: string) =>
|
||||||
{
|
{
|
||||||
|
if(!canPlaySound) return;
|
||||||
|
|
||||||
DispatchMainEvent(new NitroSoundEvent(NitroSoundEvent.PLAY_SOUND, sampleCode));
|
DispatchMainEvent(new NitroSoundEvent(NitroSoundEvent.PLAY_SOUND, sampleCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const eventTypes = [ MouseEventType.MOUSE_CLICK, MouseEventType.MOUSE_MOVE, MouseEventType.MOUSE_MOVE, TouchEventType.TOUCH_MOVE, 'focus' ];
|
||||||
|
|
||||||
|
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();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user