limited event trigger to max 10 per second
This commit is contained in:
parent
8e136cebe8
commit
2c4c98b0e5
@ -15,6 +15,8 @@ import { UserInputChatEvent } from "./Events/UserInputChatEvent";
|
|||||||
import { GameStateEvent } from './Events/ApiGameStateEvent';
|
import { GameStateEvent } from './Events/ApiGameStateEvent';
|
||||||
import { deepFreezeClone as deepFreezeClone } from '../utility';
|
import { deepFreezeClone as deepFreezeClone } from '../utility';
|
||||||
import { HasMovedEvent } from './Events/HasMovedEvent';
|
import { HasMovedEvent } from './Events/HasMovedEvent';
|
||||||
|
import { Math } from 'phaser';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,6 +65,7 @@ class IframeListener {
|
|||||||
private readonly iframes = new Set<HTMLIFrameElement>();
|
private readonly iframes = new Set<HTMLIFrameElement>();
|
||||||
private readonly scripts = new Map<string, HTMLIFrameElement>();
|
private readonly scripts = new Map<string, HTMLIFrameElement>();
|
||||||
private sendMoveEvents: boolean = false;
|
private sendMoveEvents: boolean = false;
|
||||||
|
private lastMoveTimestamp: number = 0
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
window.addEventListener("message", (message: TypedMessageEvent<IframeEvent<keyof IframeEventMap>>) => {
|
window.addEventListener("message", (message: TypedMessageEvent<IframeEvent<keyof IframeEventMap>>) => {
|
||||||
@ -237,11 +240,15 @@ class IframeListener {
|
|||||||
|
|
||||||
hasMovedEvent(event: HasMovedEvent) {
|
hasMovedEvent(event: HasMovedEvent) {
|
||||||
if (this.sendMoveEvents) {
|
if (this.sendMoveEvents) {
|
||||||
|
if (this.lastMoveTimestamp < Date.now() - 100) {
|
||||||
|
this.lastMoveTimestamp = Date.now()
|
||||||
this.postMessage({
|
this.postMessage({
|
||||||
'type': 'hasMovedEvent',
|
'type': 'hasMovedEvent',
|
||||||
'data': event
|
'data': event
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sendButtonClickedEvent(popupId: number, buttonId: number): void {
|
sendButtonClickedEvent(popupId: number, buttonId: number): void {
|
||||||
|
Loading…
Reference in New Issue
Block a user