-
Notifications
You must be signed in to change notification settings - Fork 0
๐จfeat : Socket module ์ ๋ฆฌ ๋ฐ manager control ์ถ๊ฐ #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
raymondanythings
wants to merge
7
commits into
master
Choose a base branch
from
feature/#3-socket-optimization
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
85a2ded
โป๏ธrefactor : Io -> Manager๋ก ์ฌ ๋ณ๊ฒฝ
raymondanythings 712da1f
Merge branch 'master' into feature/#3-socket-optimization
raymondanythings 2c4093b
๐จfeat : socket ๋ฐ์ธ๋ -> hooks๋ก ๋ณ๊ฒฝ
raymondanythings 13d8cef
๐จfeat : Socket ๋๊ธฐ์ค, ๋ฐฉ์
์ฅ namespace ๋ถ๊ธฐ
raymondanythings 13dcd0e
๐จfeat : ๋ก๊ทธ์ธํ์ด์ง apollo ์
์
raymondanythings ce7f81b
๐จfeat : ๋ก๊ทธ์ธ ๊ด๋ จ ๋ก์ง ์ถ๊ฐ
raymondanythings ba63c79
๐งchore : node wrtc ์ด๊ธฐ์ธํ
raymondanythings File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,3 +1,3 @@ | ||
VITE_SOCKET_SERVER_URL=http://localhost:4000 | ||
VITE_SERVER_URL=http://localhost:4000 | ||
VITE_SOCKET_SERVER_URL=http://localhost:3050 | ||
VITE_SOCKET_SERVER_PORT=3050 | ||
VITE_AUTH_KEY=_PLUG_AUTH_ |
This file contains hidden or 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,15 @@ | ||
import type { CodegenConfig } from '@graphql-codegen/cli' | ||
|
||
const config: CodegenConfig = { | ||
overwrite: true, | ||
schema: 'http://localhost:4000/graphql', | ||
documents: ['src/**/*.tsx'], | ||
ignoreNoDocuments: true, | ||
generates: { | ||
'./src/__api__/types.ts': { | ||
plugins: ['typescript', 'typescript-operations'], | ||
}, | ||
}, | ||
} | ||
|
||
export default config |
This file contains hidden or 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 hidden or 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,74 @@ | ||
export type Maybe<T> = T | null; | ||
export type InputMaybe<T> = Maybe<T>; | ||
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] }; | ||
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> }; | ||
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> }; | ||
/** All built-in and custom scalars, mapped to their actual values */ | ||
export type Scalars = { | ||
ID: string; | ||
String: string; | ||
Boolean: boolean; | ||
Int: number; | ||
Float: number; | ||
DateTime: any; | ||
}; | ||
|
||
export type LoginInput = { | ||
nickname: Scalars['String']; | ||
}; | ||
|
||
export type LoginOutput = { | ||
__typename?: 'LoginOutput'; | ||
error?: Maybe<Scalars['String']>; | ||
ok: Scalars['Boolean']; | ||
token?: Maybe<Scalars['String']>; | ||
user?: Maybe<User>; | ||
}; | ||
|
||
export type Mutation = { | ||
__typename?: 'Mutation'; | ||
login: LoginOutput; | ||
}; | ||
|
||
|
||
export type MutationLoginArgs = { | ||
input: LoginInput; | ||
}; | ||
|
||
export type Query = { | ||
__typename?: 'Query'; | ||
getMe: UserProfileOutput; | ||
}; | ||
|
||
export type User = { | ||
__typename?: 'User'; | ||
createdAt: Scalars['DateTime']; | ||
id: Scalars['Float']; | ||
nickname: Scalars['String']; | ||
role?: Maybe<UserRole>; | ||
updatedAt: Scalars['DateTime']; | ||
}; | ||
|
||
export type UserProfileOutput = { | ||
__typename?: 'UserProfileOutput'; | ||
error?: Maybe<Scalars['String']>; | ||
ok: Scalars['Boolean']; | ||
user?: Maybe<User>; | ||
}; | ||
|
||
export enum UserRole { | ||
Admin = 'Admin', | ||
Client = 'Client' | ||
} | ||
|
||
export type GetMeQueryVariables = Exact<{ [key: string]: never; }>; | ||
|
||
|
||
export type GetMeQuery = { __typename?: 'Query', getMe: { __typename?: 'UserProfileOutput', ok: boolean, error?: string | null, user?: { __typename?: 'User', id: number, nickname: string, createdAt: any, updatedAt: any, role?: UserRole | null } | null } }; | ||
|
||
export type LoginMutationVariables = Exact<{ | ||
LoginInput: LoginInput; | ||
}>; | ||
|
||
|
||
export type LoginMutation = { __typename?: 'Mutation', login: { __typename?: 'LoginOutput', ok: boolean, token?: string | null, error?: string | null, user?: { __typename?: 'User', id: number, nickname: string, updatedAt: any, createdAt: any, role?: UserRole | null } | null } }; |
This file contains hidden or 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 { ApolloClient } from '@apollo/client' | ||
import { InMemoryCache } from '@apollo/client/cache' | ||
|
||
export const client = new ApolloClient({ | ||
uri: `${import.meta.env.VITE_SERVER_URL}/graphql`, | ||
cache: new InMemoryCache(), | ||
}) |
This file contains hidden or 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 hidden or 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 hidden or 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 +1,43 @@ | ||
export {} | ||
import { useEffect, useRef, useState } from 'react' | ||
import { useContext } from 'react' | ||
import { SocketContext } from 'context/socketManager' | ||
|
||
interface useSocketProps { | ||
nsp: string | ||
} | ||
|
||
const useSocket = ({ nsp }: useSocketProps) => { | ||
const { manager } = useContext(SocketContext) | ||
const [isError, setIsError] = useState<string | null>(null) | ||
|
||
const socket = useRef( | ||
manager.create_socket(nsp, { | ||
auth: { | ||
token: localStorage.getItem('_PLUG_AUTH_') || '', | ||
}, | ||
}), | ||
) | ||
useEffect(() => { | ||
if (socket.current) { | ||
socket.current.listen('connect_error', ({ message }: Error) => { | ||
if (!isError) { | ||
setIsError(message) | ||
} | ||
}) | ||
socket.current.listen('connect', () => { | ||
if (isError) { | ||
setIsError(null) | ||
} | ||
}) | ||
} | ||
}, [socket.current, isError]) | ||
return { | ||
manager, | ||
socket: socket.current, | ||
isError, | ||
isConnected: socket.current.connected, | ||
isLoading: !socket.current, | ||
} | ||
} | ||
|
||
export default useSocket |
This file contains hidden or 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 hidden or 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,34 @@ | ||
import { Manager as M, Socket } from 'socket.io-client' | ||
import { SocketOptions } from 'socket.io-client/build/esm/socket' | ||
|
||
export class Manager extends M { | ||
private readonly sockets: { [key: string]: Socket } = {} | ||
private readonly latestSocketNsp = null | ||
create_socket(nsp: string, opts?: Partial<SocketOptions> | undefined): Socket { | ||
//TODO: ์ต๊ทผ์ฌ์ฉํ ์์ผ ์ปค๋ฅ์ ์ข ๋ฃ | ||
|
||
if (this.sockets.hasOwnProperty(nsp)) { | ||
return this.sockets[nsp] | ||
} | ||
|
||
// if (this.latestSocketNsp) { | ||
|
||
// } | ||
const socket = this.socket(nsp, opts) | ||
|
||
socket.publicId = nsp | ||
socket.listen = function bindEventListnerOnSocket(ev, lisnter) { | ||
if (this.hasListeners(ev)) { | ||
socket.off(ev) | ||
} | ||
socket.on(ev, lisnter) | ||
return socket | ||
} | ||
this.sockets[nsp] = socket | ||
return socket | ||
} | ||
|
||
isExistNsp(url: string) { | ||
return !!this.sockets[url] | ||
} | ||
} |
This file contains hidden or 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,10 +1,14 @@ | ||
import { ApolloProvider } from '@apollo/client/react' | ||
import { client } from './apollo' | ||
import React from 'react' | ||
import ReactDOM from 'react-dom/client' | ||
import './index.css' | ||
import Router from './router/Routes' | ||
|
||
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( | ||
<React.StrictMode> | ||
<Router /> | ||
<ApolloProvider client={client}> | ||
<Router /> | ||
</ApolloProvider> | ||
</React.StrictMode>, | ||
) |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
graphQl ๋ฅผ ๋์ ํ์ จ๋ค์.