aboutsummaryrefslogtreecommitdiff
path: root/modern/src/SocketController.js
diff options
context:
space:
mode:
Diffstat (limited to 'modern/src/SocketController.js')
-rw-r--r--modern/src/SocketController.js28
1 files changed, 16 insertions, 12 deletions
diff --git a/modern/src/SocketController.js b/modern/src/SocketController.js
index c986e363..49874ba7 100644
--- a/modern/src/SocketController.js
+++ b/modern/src/SocketController.js
@@ -13,6 +13,8 @@ import alarm from './resources/alarm.mp3';
import { eventsActions } from './store/events';
import useFeatures from './common/util/useFeatures';
+const logoutCode = 4000;
+
const SocketController = () => {
const dispatch = useDispatch();
const navigate = useNavigate();
@@ -40,19 +42,21 @@ const SocketController = () => {
dispatch(sessionActions.updateSocket(true));
};
- socket.onclose = async () => {
+ socket.onclose = async (event) => {
dispatch(sessionActions.updateSocket(false));
- const devicesResponse = await fetch('/api/devices');
- if (devicesResponse.ok) {
- dispatch(devicesActions.update(await devicesResponse.json()));
- }
- const positionsResponse = await fetch('/api/positions', {
- headers: { 'Content-Type': 'application/json' },
- });
- if (positionsResponse.ok) {
- dispatch(positionsActions.update(await positionsResponse.json()));
+ if (event.code !== logoutCode) {
+ const devicesResponse = await fetch('/api/devices');
+ if (devicesResponse.ok) {
+ dispatch(devicesActions.update(await devicesResponse.json()));
+ }
+ const positionsResponse = await fetch('/api/positions', {
+ headers: { 'Content-Type': 'application/json' },
+ });
+ if (positionsResponse.ok) {
+ dispatch(positionsActions.update(await positionsResponse.json()));
+ }
+ setTimeout(() => connectSocket(), 60000);
}
- setTimeout(() => connectSocket(), 60000);
};
socket.onmessage = (event) => {
@@ -84,7 +88,7 @@ const SocketController = () => {
return () => {
const socket = socketRef.current;
if (socket) {
- socket.close();
+ socket.close(logoutCode);
}
};
}