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