openreplay/frontend/app/player/mobile/managers/TouchManager.ts
Andrey Babushkin fd5c0c9747
Add lokalisation (#3092)
* applied eslint

* add locales and lint the project

* removed error boundary

* updated locales

* fix min files

* fix locales
2025-03-06 17:43:15 +01:00

56 lines
1.6 KiB
TypeScript

import { MOUSE_TRAIL } from 'App/constants/storageKeys';
import ListWalker from 'Player/common/ListWalker';
import MouseTrail, { SwipeEvent } from 'Player/web/addons/MouseTrail';
import type { IosClickEvent, IosSwipeEvent } from 'Player/web/messages';
import { MType } from 'Player/web/messages';
import type Screen from 'Player/web/Screen/Screen';
export default class TouchManager extends ListWalker<
IosClickEvent | IosSwipeEvent
> {
private touchTrail: MouseTrail | undefined;
private readonly removeTouchTrail: boolean = false;
constructor(private screen: Screen) {
super();
const canvas = document.createElement('canvas');
canvas.id = 'openreplay-touch-trail';
// canvas.className = styles.canvas;
this.removeTouchTrail = localStorage.getItem(MOUSE_TRAIL) === 'false';
if (!this.removeTouchTrail) {
this.touchTrail = new MouseTrail(canvas, true);
}
this.screen.overlay.appendChild(canvas);
this.touchTrail?.createContext();
}
public updateDimensions({
width,
height,
}: {
width: number;
height: number;
}) {
return this.touchTrail?.resizeCanvas(width, height);
}
public move(t: number) {
const lastTouch = this.moveGetLast(t);
if (lastTouch) {
if (lastTouch.tp === MType.MobileSwipeEvent) {
// not using swipe rn
// this.touchTrail?.createSwipeTrail({
// x: lastTouch.x,
// y: lastTouch.y,
// direction: lastTouch.direction
// } as SwipeEvent)
} else {
this.screen.cursor.move(lastTouch);
this.screen.cursor.mobileClick();
}
}
}
}