-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v0.1.6] 체크시 소리 , 다른페이지에서도 소켓 이벤트 수신
[v0.1.6] 체크시 소리 , 다른페이지에서도 소켓 이벤트 수신
- Loading branch information
Showing
13 changed files
with
106 additions
and
15,191 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
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 was deleted.
Oops, something went wrong.
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,5 @@ | ||
import { createContext } from 'react'; | ||
|
||
const SocketContext = createContext({}); | ||
|
||
export default SocketContext; |
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,62 @@ | ||
import { CheckCircleOutlined, CloseCircleOutlined } from '@ant-design/icons'; | ||
import { notification } from 'antd'; | ||
import moment from 'moment'; | ||
import { useEffect, useState } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { io } from 'socket.io-client'; | ||
import { enterPage } from '../state/actions-creators/enterPage'; | ||
import SocketContext from './socketContext'; | ||
|
||
const SocketProvider = ({ children }) => { | ||
const dispatch = useDispatch(); | ||
const { accessToken } = useSelector(state => state.auth); | ||
const placement = 'bottomRight'; | ||
|
||
const socket = io('https://api.gosrock.band/socket/admin', { | ||
auth: { | ||
token: accessToken | ||
} | ||
}); | ||
|
||
useEffect(() => { | ||
socket.on('connect', data => { | ||
console.log('connection server', data); | ||
}); | ||
socket.on('enter', data => { | ||
dispatch( | ||
enterPage({ | ||
data: data, | ||
enterTime: new Date() | ||
}) | ||
); | ||
|
||
notification.open({ | ||
message: `[${moment(new Date()) | ||
.utc(true) | ||
.format('HH:mm')}] 입장 알림 🔔 `, | ||
description: `${data.name}, ${data.phoneNumber}`, | ||
placement, | ||
icon: | ||
data.success === true ? ( | ||
<CheckCircleOutlined style={{ color: '#89cc8a' }} /> | ||
) : ( | ||
<CloseCircleOutlined style={{ color: '#cc8989' }} /> | ||
) | ||
}); | ||
}); | ||
|
||
return () => { | ||
socket.close(); | ||
}; | ||
}, []); | ||
|
||
socket.on('connect_error', err => { | ||
console.log(err instanceof Error); // true | ||
console.log(err.message); // not authorized | ||
console.log(err.data); // { content: "Please retry later" } | ||
}); | ||
|
||
return <SocketContext.Provider>{children}</SocketContext.Provider>; | ||
}; | ||
|
||
export { SocketProvider }; |
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