aboutsummaryrefslogtreecommitdiff
path: root/modern/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-09-07 17:18:37 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-09-07 17:18:37 +1200
commit4675139fc0dcf2f9f0acc3171af04fba86de0f79 (patch)
treec6558c96f8bad5f2fe3e71a10b8748ccca3990c2 /modern/src
parent72aa50650203d6db0b17de59bfd98c9d5b06e3e7 (diff)
downloadetbsa-traccar-web-4675139fc0dcf2f9f0acc3171af04fba86de0f79.tar.gz
etbsa-traccar-web-4675139fc0dcf2f9f0acc3171af04fba86de0f79.tar.bz2
etbsa-traccar-web-4675139fc0dcf2f9f0acc3171af04fba86de0f79.zip
Implement native notifications
Diffstat (limited to 'modern/src')
-rw-r--r--modern/src/SocketContoller.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/modern/src/SocketContoller.js b/modern/src/SocketContoller.js
index fe686ed..3cf7feb 100644
--- a/modern/src/SocketContoller.js
+++ b/modern/src/SocketContoller.js
@@ -2,6 +2,23 @@ import { Component } from 'react';
import { connect } from 'react-redux';
import { updatePositions } from './actions';
+const displayNotifications = events => {
+ if ("Notification" in window) {
+ if (Notification.permission === "granted") {
+ for (const event of events) {
+ 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") {
+ displayNotifications(events);
+ }
+ });
+ }
+ }
+};
+
class SocketController extends Component {
connectSocket() {
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
@@ -16,6 +33,9 @@ class SocketController extends Component {
if (data.positions) {
this.props.dispatch(updatePositions(data.positions));
}
+ if (data.events) {
+ displayNotifications(data.events);
+ }
}
}