aboutsummaryrefslogtreecommitdiff
path: root/modern
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-09-05 11:21:22 -0700
committerAnton Tananaev <anton@traccar.org>2022-09-05 11:21:22 -0700
commit7285abacc34695dc431b5278014a077a1deadc8e (patch)
tree9b7c843a8ea918d10fc551fdc0d924681fd91453 /modern
parent1beb6c174a0622126d704ecc2dd26a8d1b70460d (diff)
downloadtrackermap-web-7285abacc34695dc431b5278014a077a1deadc8e.tar.gz
trackermap-web-7285abacc34695dc431b5278014a077a1deadc8e.tar.bz2
trackermap-web-7285abacc34695dc431b5278014a077a1deadc8e.zip
Logout websocket handling
Diffstat (limited to 'modern')
-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);
}
};
}