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.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);