Skip to content
This repository has been archived by the owner on May 22, 2021. It is now read-only.

Commit

Permalink
Network latency
Browse files Browse the repository at this point in the history
  • Loading branch information
rhpijnacker-philips committed May 10, 2020
1 parent 36f5b24 commit 6fbf629
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 2 deletions.
32 changes: 32 additions & 0 deletions src/client/PingChecker.tsx
@@ -0,0 +1,32 @@
import React, { useState } from 'react';

import { Button } from '@material-ui/core';

import ping from './ping';

const PING_HOST = 'rehearse20.sijben.dev'

const PingChecker = () => {
const [isPinging, setIsPingBusy] = useState(false);
const [averagePing, setAveragePing] = useState(0);

const startPing = () => {
setIsPingBusy(true);
setAveragePing(undefined);
ping(PING_HOST).then(results => {
setIsPingBusy(false);
setAveragePing(results.avg);
});
};

return (
<div>
Check network latency:
<Button onClick={startPing}>Start</Button>
{isPinging ? 'Measuring ...' : ''}
{averagePing ? `${averagePing} msec.` : ''}
</div>
);
};

export default PingChecker;
7 changes: 6 additions & 1 deletion src/client/index.tsx
Expand Up @@ -5,6 +5,7 @@ import {
Button,
Container,
CssBaseline,
Link,
TextField,
Typography,
} from '@material-ui/core';
Expand All @@ -13,8 +14,11 @@ import {
makeStyles,
ThemeProvider,
} from '@material-ui/core/styles';
import * as color from '@material-ui/core/colors';

const theme = createMuiTheme({ palette: { type: 'dark' } });
const theme = createMuiTheme({
palette: { type: 'dark', primary: { main: color.lightBlue['300'] } },
});

const useStyles = makeStyles((theme) => ({
paper: {
Expand Down Expand Up @@ -98,6 +102,7 @@ const Index = () => {
Enter
</Button>
</form>
<Link href="settings.html">Settings</Link>
</div>
</Container>
</ThemeProvider>
Expand Down
8 changes: 7 additions & 1 deletion src/client/ping.ts
@@ -1,6 +1,12 @@
import child_process from 'child_process';

export default function ping(target) {
interface PingResults {
min: number;
avg: number;
max: number;
}

export default function ping(target): Promise<PingResults> {
return new Promise((resolve) => {
let min, avg, max;
const args =
Expand Down
18 changes: 18 additions & 0 deletions src/client/settings.html
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width" />
<link rel="stylesheet" href="node_modules/typeface-roboto/index.css" />
<title>Rehearse 2.0 - Settings</title>
</head>

<body>
<div id="root"></div>
</body>
<script>
require('./settings.js');
</script>

</html>
50 changes: 50 additions & 0 deletions src/client/settings.tsx
@@ -0,0 +1,50 @@
import React, { useState } from 'react';
import ReactDOM from 'react-dom';

import {
Button,
Container,
CssBaseline,
Link,
TextField,
Typography,
} from '@material-ui/core';
import {
createMuiTheme,
makeStyles,
ThemeProvider,
} from '@material-ui/core/styles';
import * as color from '@material-ui/core/colors';

import PingChecker from './PingChecker';

const theme = createMuiTheme({
palette: { type: 'dark', primary: { main: color.lightBlue['300'] } },
});

const useStyles = makeStyles((theme) => ({
paper: {
marginTop: theme.spacing(8),
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
},
form: {
width: '100%', // Fix IE 11 issue.
marginTop: theme.spacing(1),
},
submit: {},
}));

const Settings = () => {
const classes = useStyles();

return (
<ThemeProvider theme={theme}>
<PingChecker />
<Link href="index.html">&lt; Back</Link>
</ThemeProvider>
);
};

ReactDOM.render(<Settings />, document.getElementById('root'));

0 comments on commit 6fbf629

Please sign in to comment.