Compare commits
2
Commits
d2fe4604dd
...
737702d78c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
737702d78c | ||
|
|
98c2323ff2 |
No files matched your search
@@ -1,4 +1,4 @@
|
||||
VITE_API_BASE_URL=http://localhost:3000
|
||||
VITE_API_BASE_URL=http://126.dahyeon.us:3000
|
||||
VITE_DEFAULT_COMMUNITY_ID=69ebe0adf627c11be2f020a1
|
||||
VITE_MSAL_CLIENT_ID=15fb5a20-47e0-44fa-9a41-b50ca9d0e7e3
|
||||
VITE_MSAL_AUTHORITY=https://login.microsoftonline.com/5ef88004-e953-4b04-93db-64bbf49c6863
|
||||
|
||||
@@ -30,6 +30,11 @@ interface ResetPayload {
|
||||
matchId?: string;
|
||||
}
|
||||
|
||||
interface TickPayload {
|
||||
deadline?: string;
|
||||
serverTime?: string;
|
||||
}
|
||||
|
||||
const MAX_CHAT_MESSAGES = 200;
|
||||
|
||||
function mergeChatMessages(
|
||||
@@ -55,6 +60,7 @@ export function useAuctionSocket(matchId: string | undefined) {
|
||||
const [connectionStatus, setConnectionStatus] =
|
||||
useState<ConnectionStatus>('idle');
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [serverTimeOffsetMs, setServerTimeOffsetMs] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
if (!matchId) {
|
||||
@@ -100,6 +106,16 @@ export function useAuctionSocket(matchId: string | undefined) {
|
||||
setError(null);
|
||||
});
|
||||
|
||||
socket.on('tick', (payload: TickPayload) => {
|
||||
const serverTime =
|
||||
typeof payload?.serverTime === 'string'
|
||||
? Date.parse(payload.serverTime)
|
||||
: NaN;
|
||||
if (Number.isFinite(serverTime)) {
|
||||
setServerTimeOffsetMs(serverTime - Date.now());
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('chat-history', (payload: ChatHistoryPayload) => {
|
||||
setChatMessages(mergeChatMessages([], payload.messages ?? []));
|
||||
});
|
||||
@@ -129,6 +145,7 @@ export function useAuctionSocket(matchId: string | undefined) {
|
||||
socket?.disconnect();
|
||||
socketRef.current = null;
|
||||
setConnectionStatus('idle');
|
||||
setServerTimeOffsetMs(0);
|
||||
};
|
||||
}, [authUserId, matchId]);
|
||||
|
||||
@@ -160,6 +177,7 @@ export function useAuctionSocket(matchId: string | undefined) {
|
||||
resetAt,
|
||||
connectionStatus: visibleConnectionStatus,
|
||||
error,
|
||||
serverTimeOffsetMs: matchId ? serverTimeOffsetMs : 0,
|
||||
placeBid(payload: BidPayload) {
|
||||
emit('bid', payload);
|
||||
},
|
||||
|
||||
@@ -781,9 +781,14 @@ export default function AuctionPage() {
|
||||
}, [showCancelModal]);
|
||||
|
||||
const liveAuction = pickLatestAuction(socket.auction, auctionQuery.data);
|
||||
const syncedNow = now + socket.serverTimeOffsetMs;
|
||||
const auctionState =
|
||||
liveAuction && matchQuery.data
|
||||
? mapApiAuctionToAuctionState(liveAuction, matchQuery.data, new Date(now))
|
||||
? mapApiAuctionToAuctionState(
|
||||
liveAuction,
|
||||
matchQuery.data,
|
||||
new Date(syncedNow),
|
||||
)
|
||||
: null;
|
||||
const availableTeamIndexes = useMemo(() => {
|
||||
const indexes = new Set((auctionState?.teams ?? []).map((team) => team.teamIndex));
|
||||
|
||||
Reference in new issue
Block a user