| |
@@ -0,0 +1,58 @@
|
| |
+ import React from 'react';
|
| |
+ import PropTypes from 'prop-types';
|
| |
+ import { connect } from 'react-redux';
|
| |
+ import {
|
| |
+ sendHeartbeat,
|
| |
+ } from "../core/actions/heartbeat";
|
| |
+
|
| |
+
|
| |
+ class Heartbeat extends React.PureComponent {
|
| |
+
|
| |
+ constructor(props) {
|
| |
+ super(props);
|
| |
+ this.timeout = null;
|
| |
+ this.interval = 60 * 1000;
|
| |
+ this.ping = this.ping.bind(this);
|
| |
+ }
|
| |
+
|
| |
+ componentWillMount() {
|
| |
+ if (this.timeout !== null) {
|
| |
+ clearTimeout(this.timeout);
|
| |
+ }
|
| |
+ this.ping();
|
| |
+ }
|
| |
+
|
| |
+ componentWillUnmount() {
|
| |
+ if (this.timeout === null) {
|
| |
+ return;
|
| |
+ }
|
| |
+ clearTimeout(this.timeout);
|
| |
+ this.timeout = null;
|
| |
+ }
|
| |
+
|
| |
+ ping() {
|
| |
+ this.props.sendHeartbeat();
|
| |
+ this.timeout = setTimeout(this.ping, this.interval);
|
| |
+ }
|
| |
+
|
| |
+ render() {
|
| |
+ return null;
|
| |
+ }
|
| |
+ }
|
| |
+ Heartbeat.propTypes = {
|
| |
+ connected: PropTypes.bool,
|
| |
+ }
|
| |
+ Heartbeat.defaultProps = {
|
| |
+ connected: true,
|
| |
+ }
|
| |
+
|
| |
+
|
| |
+ const mapStateToProps = (state) => {
|
| |
+ return {
|
| |
+ connected: state.ui.heartbeat === "connected",
|
| |
+ }
|
| |
+ };
|
| |
+
|
| |
+ export default connect(mapStateToProps, {
|
| |
+ sendHeartbeat,
|
| |
+ })(Heartbeat);
|
| |
Fixes #530