diff --git a/src/components/websocket/WebsocketClient.js b/src/components/websocket/WebsocketClient.js index b5cac196..24cd1b17 100644 --- a/src/components/websocket/WebsocketClient.js +++ b/src/components/websocket/WebsocketClient.js @@ -1,11 +1,13 @@ import React, { useEffect, useState, useRef } from 'react'; import { VscLoading } from 'react-icons/vsc'; import { useDispatch, useSelector } from 'react-redux'; +import { useHistory } from 'react-router-dom'; import { WS_HOST } from '../../configs/constants'; import * as Actions from '../../modules/control/gp/actions/controlGpAction'; const WebsocketClient = () => { const dispatch = useDispatch(); + const history = useHistory(); const reConnectionTime = 5000; //5초 const [isConnection, setIsConnection] = useState(false); @@ -31,21 +33,27 @@ const WebsocketClient = () => { websocket.current.onmessage = e => { const data = e.data; const controlGpList = JSON.parse(data); - + console.log(data); dispatch(Actions.controlGpAction.request(controlGpList)); }; - websocket.current.onclose = event => { - timeout.current = setTimeout(function () { - connect(); - }, reConnectionTime); + // 웹소켓 끊키는 현상 있을시 주석 해제 + // websocket.current.onclose = event => { + // console.log('??????'); + // if (history.location.pathname === '/control') { + // timeout.current = setTimeout(function () { + // connect(); + // }, reConnectionTime); - if (event.wasClean) { - console.log('[Websocket Close] Connection Close'); - } else { - console.log('[Websocket Close] Connection Error'); - } - }; + // if (event.wasClean) { + // console.log('[Websocket Close] Connection Close'); + // } else { + // console.log('[Websocket Close] Connection Error'); + // } + // } else { + // websocket.current.close(); + // } + // }; }; { /* socket_off = 클래스명 변경시 빨간색! 접속이 원할하지않을때 */