Browse Source

웹소켓 드론교통관리 페이지 외 끊기지 않던 현상 수정

pull/2/head
김장현 11 months ago
parent
commit
df4558e5c0
  1. 30
      src/components/websocket/WebsocketClient.js

30
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 = 클래스명 변경시 빨간색! 접속이 원할하지않을때 */

Loading…
Cancel
Save