From 2c7dc9d42a44b5202b630a5db40e14147bf7c7f6 Mon Sep 17 00:00:00 2001 From: Victor Ferreira Date: Wed, 3 Oct 2018 09:42:25 -0300 Subject: Rename SocketContoller.js to SockerController.js fix filename --- modern/src/SocketContoller.js | 54 ------------------------------------------ modern/src/SocketController.js | 54 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 54 deletions(-) delete mode 100644 modern/src/SocketContoller.js create mode 100644 modern/src/SocketController.js (limited to 'modern/src') diff --git a/modern/src/SocketContoller.js b/modern/src/SocketContoller.js deleted file mode 100644 index f65fc6c1..00000000 --- a/modern/src/SocketContoller.js +++ /dev/null @@ -1,54 +0,0 @@ -import { Component } from 'react'; -import { connect } from 'react-redux'; -import { updateDevices, 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:'; - const socket = new WebSocket(protocol + '//' + window.location.host + '/api/socket'); - - socket.onclose = () => { - setTimeout(() => this.connectSocket(), 60 * 1000); - }; - - socket.onmessage = (event) => { - const data = JSON.parse(event.data); - if (data.devices) { - this.props.dispatch(updateDevices(data.devices)); - } - if (data.positions) { - this.props.dispatch(updatePositions(data.positions)); - } - if (data.events) { - displayNotifications(data.events); - } - } - } - - componentDidMount() { - this.connectSocket(); - } - - render() { - return null; - } -} - -export default connect()(SocketController); diff --git a/modern/src/SocketController.js b/modern/src/SocketController.js new file mode 100644 index 00000000..f65fc6c1 --- /dev/null +++ b/modern/src/SocketController.js @@ -0,0 +1,54 @@ +import { Component } from 'react'; +import { connect } from 'react-redux'; +import { updateDevices, 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:'; + const socket = new WebSocket(protocol + '//' + window.location.host + '/api/socket'); + + socket.onclose = () => { + setTimeout(() => this.connectSocket(), 60 * 1000); + }; + + socket.onmessage = (event) => { + const data = JSON.parse(event.data); + if (data.devices) { + this.props.dispatch(updateDevices(data.devices)); + } + if (data.positions) { + this.props.dispatch(updatePositions(data.positions)); + } + if (data.events) { + displayNotifications(data.events); + } + } + } + + componentDidMount() { + this.connectSocket(); + } + + render() { + return null; + } +} + +export default connect()(SocketController); -- cgit v1.2.3