.
This commit is contained in:
1 parent
5af2c80cd1
commit
f7ee34da4f
78 files changed
+9016
-150
No files matched your search
@@ -68,6 +68,7 @@ export interface ApiRiotAccount {
|
||||
export interface ApiUser {
|
||||
_id: string;
|
||||
communityId: string;
|
||||
identityId?: string;
|
||||
role: CommunityRole;
|
||||
kakaoTalkId?: string;
|
||||
kakaoTalkNickname?: string;
|
||||
@@ -198,8 +199,22 @@ export interface ApiAuction {
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface ApiIdentity {
|
||||
id: string;
|
||||
entraOid: string;
|
||||
tenantId?: string;
|
||||
email?: string;
|
||||
displayName?: string;
|
||||
}
|
||||
|
||||
export interface ApiMembership {
|
||||
user: ApiUser;
|
||||
community: ApiCommunity | null;
|
||||
}
|
||||
|
||||
export interface MeResponse {
|
||||
user: ApiUser | null;
|
||||
identity: ApiIdentity | null;
|
||||
memberships: ApiMembership[];
|
||||
}
|
||||
|
||||
export interface MatchesResponse {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { io, type Socket } from 'socket.io-client';
|
||||
import { API_BASE_URL, useAuthUserId } from '../config';
|
||||
import { acquireAccessToken } from '../lib/auth/token-provider';
|
||||
import type { ApiAuction, Position, TeamSide } from './types';
|
||||
|
||||
type ConnectionStatus =
|
||||
@@ -31,37 +32,53 @@ export function useAuctionSocket(matchId: string | undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
const socket = io(`${API_BASE_URL}/auction`, {
|
||||
transports: ['websocket'],
|
||||
auth: authUserId ? { 'x-auth-user-id': authUserId } : {},
|
||||
});
|
||||
|
||||
socketRef.current = socket;
|
||||
let disposed = false;
|
||||
setConnectionStatus('connecting');
|
||||
setError(null);
|
||||
|
||||
socket.on('connect', () => {
|
||||
setConnectionStatus('connected');
|
||||
socket.emit('join', { matchId });
|
||||
});
|
||||
void (async () => {
|
||||
const accessToken = await acquireAccessToken().catch((error) => {
|
||||
console.warn('Failed to acquire socket access token:', error);
|
||||
return null;
|
||||
});
|
||||
if (disposed) return;
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
setConnectionStatus('disconnected');
|
||||
});
|
||||
const socket = io(`${API_BASE_URL}/auction`, {
|
||||
transports: ['websocket'],
|
||||
auth: accessToken
|
||||
? { token: accessToken }
|
||||
: authUserId
|
||||
? { 'x-auth-user-id': authUserId }
|
||||
: {},
|
||||
});
|
||||
|
||||
socket.on('state', (nextAuction: ApiAuction) => {
|
||||
setAuction(nextAuction);
|
||||
setError(null);
|
||||
});
|
||||
socketRef.current = socket;
|
||||
|
||||
socket.on('error', (payload: { message?: string }) => {
|
||||
setConnectionStatus('error');
|
||||
setError(payload.message ?? '실시간 경매 연결 중 오류가 발생했습니다.');
|
||||
});
|
||||
socket.on('connect', () => {
|
||||
setConnectionStatus('connected');
|
||||
socket.emit('join', { matchId });
|
||||
});
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
setConnectionStatus('disconnected');
|
||||
});
|
||||
|
||||
socket.on('state', (nextAuction: ApiAuction) => {
|
||||
setAuction(nextAuction);
|
||||
setError(null);
|
||||
});
|
||||
|
||||
socket.on('error', (payload: { message?: string }) => {
|
||||
setConnectionStatus('error');
|
||||
setError(payload.message ?? '실시간 경매 연결 중 오류가 발생했습니다.');
|
||||
});
|
||||
})();
|
||||
|
||||
return () => {
|
||||
socket.removeAllListeners();
|
||||
socket.disconnect();
|
||||
disposed = true;
|
||||
const socket = socketRef.current;
|
||||
socket?.removeAllListeners();
|
||||
socket?.disconnect();
|
||||
socketRef.current = null;
|
||||
setConnectionStatus('idle');
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user