aboutsummaryrefslogtreecommitdiff
path: root/modern/src/SocketController.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-07-10 15:24:10 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2021-07-10 15:24:10 -0700
commit0512964d71a25c172735f2149ef60c3a8b20f683 (patch)
treef47b42326a7e6a0eaa2715ca8066cb3ca7e7bb90 /modern/src/SocketController.js
parent627cf95d59f625dcb0544bfd4c067d99dee4bb93 (diff)
downloadtrackermap-web-0512964d71a25c172735f2149ef60c3a8b20f683.tar.gz
trackermap-web-0512964d71a25c172735f2149ef60c3a8b20f683.tar.bz2
trackermap-web-0512964d71a25c172735f2149ef60c3a8b20f683.zip
Use modified airbnb eslint
Diffstat (limited to 'modern/src/SocketController.js')
-rw-r--r--modern/src/SocketController.js30
1 files changed, 15 insertions, 15 deletions
diff --git a/modern/src/SocketController.js b/modern/src/SocketController.js
index cda693a1..ae82d134 100644
--- a/modern/src/SocketController.js
+++ b/modern/src/SocketController.js
@@ -1,19 +1,19 @@
-import { useDispatch, useSelector } from 'react-redux';
-import { connect } from 'react-redux';
-import { positionsActions, devicesActions, sessionActions } from './store';
+import { useDispatch, useSelector, connect } from 'react-redux';
+
import { useHistory } from 'react-router-dom';
+import { positionsActions, devicesActions, sessionActions } from './store';
import { useEffectAsync } from './reactHelper';
-const displayNotifications = events => {
- if ("Notification" in window) {
- if (Notification.permission === "granted") {
- for (const event of events) {
+const displayNotifications = (events) => {
+ if ('Notification' in window) {
+ if (Notification.permission === 'granted') {
+ events.forEach((event) => {
const notification = new Notification(`Event: ${event.type}`);
setTimeout(notification.close.bind(notification), 4 * 1000);
- }
- } else if (Notification.permission !== "denied") {
- Notification.requestPermission(permission => {
- if (permission === "granted") {
+ });
+ } else if (Notification.permission !== 'denied') {
+ Notification.requestPermission((permission) => {
+ if (permission === 'granted') {
displayNotifications(events);
}
});
@@ -24,11 +24,11 @@ const displayNotifications = events => {
const SocketController = () => {
const dispatch = useDispatch();
const history = useHistory();
- const authenticated = useSelector(state => !!state.session.user);
+ const authenticated = useSelector((state) => !!state.session.user);
const connectSocket = () => {
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
- const socket = new WebSocket(protocol + '//' + window.location.host + '/api/socket');
+ const socket = new WebSocket(`${protocol}//${window.location.host}/api/socket`);
socket.onclose = () => {
setTimeout(() => connectSocket(), 60 * 1000);
@@ -46,7 +46,7 @@ const SocketController = () => {
displayNotifications(data.events);
}
};
- }
+ };
useEffectAsync(async () => {
const response = await fetch('/api/server');
@@ -73,6 +73,6 @@ const SocketController = () => {
}, [authenticated]);
return null;
-}
+};
export default connect()(SocketController);