Skip to content

Commit

Permalink
adjust device_created event
Browse files Browse the repository at this point in the history
  • Loading branch information
YeonV committed Jan 13, 2025
1 parent 2296b04 commit f880a11
Showing 1 changed file with 4 additions and 30 deletions.
34 changes: 4 additions & 30 deletions src/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import useStore from '../../store/useStore'

import Dashboard from './Dashboard'
import DashboardDetailed from './DashboardDetailed'
import ws from '../../utils/Websocket'
// import ws from '../../utils/Websocket'
import IntroDialog from '../../components/Dialogs/IntroDialog'

const sleep = (ms: number) => {
Expand Down Expand Up @@ -57,38 +57,12 @@ export default function Home() {

document.addEventListener('device_created', handleWebsockets)

return () => {
document.removeEventListener('device_created', handleWebsockets)
}
// return () => {
// document.removeEventListener('device_created', handleWebsockets)
// }
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

useEffect(() => {
const handleWebsockets = () => {
const req = {
event_type: 'device_created',
id: 9001,
type: 'subscribe_event'
}
// console.log("Send");
ws.send(JSON.stringify(req.id && req))
}
document.addEventListener('subs_device_created', handleWebsockets)
return () => {
const removeGetWs = async () => {
const request = {
id: 9001,
type: 'unsubscribe_event',
event_type: 'device_created'
}
ws.send(JSON.stringify(request.id && request))
}
// console.log("Clean Up");
removeGetWs()
document.removeEventListener('subs_device_created', handleWebsockets)
}
}, [])

return !intro ? (
features.dashboardDetailed ? (
<DashboardDetailed />
Expand Down

0 comments on commit f880a11

Please sign in to comment.