diff options
Diffstat (limited to 'modern')
-rw-r--r-- | modern/src/SocketContoller.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/modern/src/SocketContoller.js b/modern/src/SocketContoller.js index fe686ed8..3cf7feb7 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); + } } } |