generated from nim-od/softeer-mono-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from softeerbootcamp4th/fix-socket-connecting
[Fix] 소켓 연결 오류 해결(비동기 처리, 페이지 이동과 무관하게 연결 유지 및 재구독)
- Loading branch information
Showing
17 changed files
with
153 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
import { useEffect } from 'react'; | ||
import { useLayoutEffect, useRef } from 'react'; | ||
import useAuth from 'src/hooks/useAuth.ts'; | ||
import socketManager from 'src/services/socket.ts'; | ||
import useChatSocket from './useChatSocket.ts'; | ||
import useRacingSocket from './useRacingSocket.ts'; | ||
|
||
export type UseSocketReturnType = ReturnType<typeof useSocket>; | ||
|
||
export default function useSocket() { | ||
const { token } = useAuth(); | ||
const chatSocket = useChatSocket(); | ||
const racingSocket = useRacingSocket(); | ||
|
||
const { onReceiveMessage, onReceiveBlock, ...chatSocketProps } = chatSocket; | ||
|
||
const racingSocket = useRacingSocket(); | ||
const { onReceiveStatus, ...racingSocketProps } = racingSocket; | ||
|
||
useEffect(() => { | ||
socketManager.connectSocketClient({ token, onReceiveMessage, onReceiveStatus, onReceiveBlock }); | ||
}, [socketManager, token]); | ||
const isSocketInitialized = useRef(false); | ||
|
||
useLayoutEffect(() => { | ||
if (!isSocketInitialized.current) { | ||
socketManager.connectSocketClient({ | ||
token, | ||
onReceiveMessage, | ||
onReceiveStatus, | ||
onReceiveBlock, | ||
}); | ||
isSocketInitialized.current = true; | ||
} | ||
}, [token, onReceiveMessage, onReceiveStatus, onReceiveBlock]); | ||
|
||
return { chatSocket: chatSocketProps, racingSocket: racingSocketProps }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { ChatProps } from '@softeer/common/components'; | ||
import STORAGE_KEYS from 'src/constants/storageKey.ts'; | ||
import useStorage from 'src/hooks/storage/index.ts'; | ||
|
||
const useChatListStorage = () => useStorage<ChatProps[]>(STORAGE_KEYS.CHAT_LIST, []); | ||
|
||
export default useChatListStorage; |
Oops, something went wrong.