diff --git a/app/components/DeviceView.tsx b/app/components/DeviceView.tsx index 9d0f1d2..323eb12 100644 --- a/app/components/DeviceView.tsx +++ b/app/components/DeviceView.tsx @@ -8,7 +8,8 @@ import { ConnectionState as ConState, SprinklersDevice } from "@common/sprinkler import { ProgramTable, RunSectionForm, SectionRunnerView, SectionTable } from "."; import "./DeviceView.scss"; -function ConnectionState({ connectionState, className }: { connectionState: ConState, className?: string }) { +const ConnectionState = observer(({ connectionState, className }: + { connectionState: ConState, className?: string }) => { const connected = connectionState.isConnected; const classes = classNames({ connectionState: true, @@ -31,7 +32,7 @@ function ConnectionState({ connectionState, className }: { connectionState: ConS {connectionText} ); -} +}); interface DeviceViewProps { deviceId: string; @@ -62,11 +63,11 @@ class DeviceView extends React.Component { Raspberry Pi Grinklers Device - - + + - + diff --git a/app/components/SectionRunnerView.tsx b/app/components/SectionRunnerView.tsx index 4763d5d..d745526 100644 --- a/app/components/SectionRunnerView.tsx +++ b/app/components/SectionRunnerView.tsx @@ -27,7 +27,7 @@ function SectionRunView({ run, sections }: const duration = Duration.fromSeconds(run.duration); const cancel = run.cancel; return ( - + '{section.name}' for {duration.toString()} diff --git a/app/sprinklers/websocket.ts b/app/sprinklers/websocket.ts index 9ee48cb..13b95db 100644 --- a/app/sprinklers/websocket.ts +++ b/app/sprinklers/websocket.ts @@ -6,7 +6,7 @@ import * as requests from "@common/sprinklers/requests"; import * as schema from "@common/sprinklers/schema/index"; import { seralizeRequest } from "@common/sprinklers/schema/requests"; import * as ws from "@common/sprinklers/websocketData"; -import { autorun, observable } from "mobx"; +import { action, autorun, observable } from "mobx"; const log = logger.child({ source: "websocket" }); @@ -102,15 +102,25 @@ export class WebSocketApiClient implements s.ISprinklersApi { this.connectionState.clientToServer = true; } + /* tslint:disable-next-line:member-ordering */ + private onDisconnect = action(() => { + this.connectionState.serverToBroker = null; + this.connectionState.clientToServer = false; + }); + private onClose(event: CloseEvent) { log.info({ reason: event.reason, wasClean: event.wasClean }, "disconnected from websocket"); - this.connectionState.clientToServer = false; + this.onDisconnect(); } private onError(event: Event) { - log.error(event, "websocket error"); - this.connectionState.clientToServer = false; + log.error({ event }, "websocket error"); + action(() => { + this.connectionState.serverToBroker = null; + this.connectionState.clientToServer = false; + }); + this.onDisconnect(); } private onMessage(event: MessageEvent) {