aboutsummaryrefslogtreecommitdiff
path: root/modern/src/SocketController.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-05-25 18:43:59 -0700
committerAnton Tananaev <anton@traccar.org>2022-05-25 18:43:59 -0700
commit73c1e0795ea6b27a89b4c9065717dfd9ca879bab (patch)
treefc36ea2ee2408aa084573a5702e7330100a3cddb /modern/src/SocketController.js
parent13d0373b91687da59af67df582ed385f86437298 (diff)
downloadtrackermap-web-73c1e0795ea6b27a89b4c9065717dfd9ca879bab.tar.gz
trackermap-web-73c1e0795ea6b27a89b4c9065717dfd9ca879bab.tar.bz2
trackermap-web-73c1e0795ea6b27a89b4c9065717dfd9ca879bab.zip
Add notification sound
Diffstat (limited to 'modern/src/SocketController.js')
-rw-r--r--modern/src/SocketController.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/modern/src/SocketController.js b/modern/src/SocketController.js
index 57ffa0d5..05236971 100644
--- a/modern/src/SocketController.js
+++ b/modern/src/SocketController.js
@@ -8,6 +8,9 @@ import { useEffectAsync } from './reactHelper';
import { useTranslation } from './common/components/LocalizationProvider';
import { prefixString } from './common/util/stringUtils';
import { snackBarDurationLongMs } from './common/util/duration';
+import usePersistedState from './common/util/usePersistedState';
+
+import alarm from '../public/alarm.mp3';
const SocketController = () => {
const dispatch = useDispatch();
@@ -22,6 +25,9 @@ const SocketController = () => {
const [events, setEvents] = useState([]);
const [notifications, setNotifications] = useState([]);
+ const [soundEvents] = usePersistedState('soundEvents', []);
+ const [soundAlarms] = usePersistedState('soundAlarms', ['sos']);
+
const connectSocket = () => {
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const socket = new WebSocket(`${protocol}//${window.location.host}/api/socket`);
@@ -87,6 +93,14 @@ const SocketController = () => {
})));
}, [events, devices, t]);
+ useEffect(() => {
+ events.forEach((event) => {
+ if (soundEvents.includes(event.type) || (event.type === 'alarm' && soundAlarms.includes(event.attributes.alarm))) {
+ new Audio(alarm).play();
+ }
+ });
+ }, [events, soundEvents, soundAlarms]);
+
return (
<>
{notifications.map((notification) => (