throttle 'tilts' from the server
This commit is contained in:
@@ -2,6 +2,7 @@ import { useEffect } from 'react';
|
||||
import { socket } from '@/socket';
|
||||
import throttle from '@/tools/throttle';
|
||||
|
||||
import { thirtyFPS } from '@/constants/time';
|
||||
import type { GameUpdate, Tilt } from '@/types';
|
||||
|
||||
interface UseSocketProps {
|
||||
@@ -38,28 +39,28 @@ export default function useSocket({ gameID, setGameData, setNoGame }: UseSocketP
|
||||
};
|
||||
}, [gameID]);
|
||||
|
||||
const flipCard = (cardIndex: number) => {
|
||||
const emitFlip = (cardIndex: number) => {
|
||||
socket.emit('flip-card', {
|
||||
gameID,
|
||||
cardIndex,
|
||||
});
|
||||
};
|
||||
|
||||
const handleSettings = (gameData: GameUpdate) => {
|
||||
const emitSettings = (gameData: GameUpdate) => {
|
||||
socket.emit('settings', {
|
||||
gameID,
|
||||
gameData,
|
||||
});
|
||||
};
|
||||
|
||||
const redraw = (cardIndex: number) => {
|
||||
const emitRedraw = (cardIndex: number) => {
|
||||
socket.emit('redraw', {
|
||||
gameID,
|
||||
cardIndex,
|
||||
});
|
||||
};
|
||||
|
||||
const select = (cardIndex: number, cardID: string) => {
|
||||
const emitSelect = (cardIndex: number, cardID: string) => {
|
||||
socket.emit('select', {
|
||||
gameID,
|
||||
cardIndex,
|
||||
@@ -72,13 +73,13 @@ export default function useSocket({ gameID, setGameData, setNoGame }: UseSocketP
|
||||
cardIndex,
|
||||
tilt,
|
||||
});
|
||||
}, 33.3);
|
||||
}, thirtyFPS);
|
||||
|
||||
return {
|
||||
flipCard,
|
||||
handleSettings,
|
||||
redraw,
|
||||
select,
|
||||
emitFlip,
|
||||
emitSettings,
|
||||
emitRedraw,
|
||||
emitSelect,
|
||||
emitTilt,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user