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