You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.8 KiB
64 lines
1.8 KiB
7 years ago
|
import { computed, observable } from "mobx";
|
||
|
|
||
|
export class ConnectionState {
|
||
|
/**
|
||
|
* Represents if a client is connected to the sprinklers3 server (eg. via websocket)
|
||
|
* Can be null if there is no client involved
|
||
|
*/
|
||
|
@observable clientToServer: boolean | null = null;
|
||
|
|
||
|
/**
|
||
|
* Represents if the sprinklers3 server is connected to the broker (eg. via mqtt)
|
||
|
* Can be null if there is no broker involved
|
||
|
*/
|
||
|
@observable serverToBroker: boolean | null = null;
|
||
|
|
||
|
/**
|
||
|
* Represents if the device is connected to the broker and we can communicate with it (eg. via mqtt)
|
||
|
* Can be null if there is no device involved
|
||
|
*/
|
||
|
@observable brokerToDevice: boolean | null = null;
|
||
|
|
||
7 years ago
|
/**
|
||
|
* Represents if whoever is trying to access this device has permission to access it.
|
||
|
* Is null if there is no concept of access involved.
|
||
|
*/
|
||
|
@observable hasPermission: boolean | null = null;
|
||
|
|
||
|
@computed get noPermission() {
|
||
|
return this.hasPermission === false;
|
||
|
}
|
||
|
|
||
|
@computed get isAvailable(): boolean {
|
||
|
if (this.hasPermission === false) {
|
||
|
return false;
|
||
|
}
|
||
7 years ago
|
if (this.brokerToDevice != null) {
|
||
7 years ago
|
return true;
|
||
7 years ago
|
}
|
||
|
if (this.serverToBroker != null) {
|
||
|
return this.serverToBroker;
|
||
|
}
|
||
|
if (this.clientToServer != null) {
|
||
|
return this.clientToServer;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
7 years ago
|
|
||
|
@computed get isConnected(): boolean | null {
|
||
|
if (this.hasPermission === false) {
|
||
|
return false;
|
||
|
}
|
||
|
if (this.brokerToDevice != null) {
|
||
|
return this.brokerToDevice;
|
||
|
}
|
||
|
if (this.serverToBroker != null) {
|
||
|
return this.serverToBroker;
|
||
|
}
|
||
|
if (this.clientToServer != null) {
|
||
|
return this.clientToServer;
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
7 years ago
|
}
|