import React from 'react'; import Typography from '@material-ui/core/Typography'; const RED_COLOR = "#C00"; const GREEN_COLOR = "#666"; function tempDisplay(mC: number): string { return (mC/1000).toFixed(1) + "\u00B0C"; // degrees C. } function cpuDisplay(cpu: number): string { return cpu.toFixed(1)+"%"; } export default class JackHostStatus { deserialize(input: any): JackHostStatus { this.active = input.active; this.restarting = input.restarting; this.underruns = input.underruns; this.cpuUsage = input.cpuUsage; this.msSinceLastUnderrun = input.msSinceLastUnderrun; this.temperaturemC = input.temperaturemC; return this; } hasTemperature() : boolean { return this.temperaturemC >= -100000; } active: boolean = false; restarting: boolean = false; underruns: number = 0; cpuUsage: number = 0; msSinceLastUnderrun: number = -5000*1000; temperaturemC: number = -1000000; static getDisplayView(label: string,status?: JackHostStatus): React.ReactNode { if (!status) { return (
{label}  
); } if (status.restarting) { return (
{label} Restarting   { status.temperaturemC > -100000 && ( 75000? RED_COLOR: GREEN_COLOR}}> {tempDisplay(status.temperaturemC)} ) }
); } else if (!status.active) { return (
{label} Stopped   { status.temperaturemC > -100000 && ( 75000? RED_COLOR: GREEN_COLOR}}> {tempDisplay(status.temperaturemC)} ) }
); } else { let underrunError = status.msSinceLastUnderrun < 15*1000; return (
{label} XRuns: {status.underruns+""}   CPU: {cpuDisplay(status.cpuUsage)}   {tempDisplay(status.temperaturemC)}
); } } };