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.
29 lines
962 B
29 lines
962 B
7 years ago
|
import { WebSocketRpcClient } from "@app/sprinklersRpc/websocketClient";
|
||
7 years ago
|
import HttpApi from "@app/state/HttpApi";
|
||
|
import { UiStore } from "@app/state/UiStore";
|
||
7 years ago
|
import { createBrowserHistory, History } from "history";
|
||
7 years ago
|
|
||
|
const isDev = process.env.NODE_ENV === "development";
|
||
|
const websocketPort = isDev ? 8080 : location.port;
|
||
|
|
||
7 years ago
|
export default class AppState {
|
||
|
history: History = createBrowserHistory();
|
||
7 years ago
|
uiStore = new UiStore();
|
||
|
httpApi = new HttpApi();
|
||
7 years ago
|
tokenStore = this.httpApi.tokenStore;
|
||
|
sprinklersRpc = new WebSocketRpcClient(`ws://${location.hostname}:${websocketPort}`,
|
||
|
this.tokenStore);
|
||
7 years ago
|
|
||
|
async start() {
|
||
|
if (!this.httpApi.tokenStore.accessToken.isValid) {
|
||
|
if (this.httpApi.tokenStore.refreshToken.isValid) {
|
||
|
await this.httpApi.tokenStore.grantRefresh();
|
||
|
} else {
|
||
7 years ago
|
this.history.push("/login");
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
this.sprinklersRpc.start();
|
||
7 years ago
|
}
|
||
|
}
|