Browse Source

Fixed websocket protocol selection to allow wss

update-deps
Alex Mikhalev 7 years ago
parent
commit
07a16f79a1
  1. 8
      app/sprinklersRpc/websocketClient.ts
  2. 6
      app/state/AppState.ts

8
app/sprinklersRpc/websocketClient.ts

@ -16,6 +16,12 @@ const log = logger.child({ source: "websocket" });
const TIMEOUT_MS = 5000; const TIMEOUT_MS = 5000;
const RECONNECT_TIMEOUT_MS = 5000; const RECONNECT_TIMEOUT_MS = 5000;
const isDev = process.env.NODE_ENV === "development";
const websocketProtocol = (location.protocol === "https:") ? "wss:" : "ws:";
const websocketPort = isDev ? 8080 : location.port;
const DEFAULT_URL = `${websocketProtocol}//${location.hostname}:${websocketPort}`;
// tslint:disable:member-ordering // tslint:disable:member-ordering
export class WSSprinklersDevice extends s.SprinklersDevice { export class WSSprinklersDevice extends s.SprinklersDevice {
@ -80,7 +86,7 @@ export class WebSocketRpcClient implements s.SprinklersRPC {
return this.connectionState.isConnected || false; return this.connectionState.isConnected || false;
} }
constructor(webSocketUrl: string, tokenStore: TokenStore) { constructor(tokenStore: TokenStore, webSocketUrl: string = DEFAULT_URL) {
this.webSocketUrl = webSocketUrl; this.webSocketUrl = webSocketUrl;
this.tokenStore = tokenStore; this.tokenStore = tokenStore;
this.connectionState.clientToServer = false; this.connectionState.clientToServer = false;

6
app/state/AppState.ts

@ -7,17 +7,13 @@ import HttpApi from "@app/state/HttpApi";
import { UiStore } from "@app/state/UiStore"; import { UiStore } from "@app/state/UiStore";
import log from "@common/logger"; import log from "@common/logger";
const isDev = process.env.NODE_ENV === "development";
const websocketPort = isDev ? 8080 : location.port;
export default class AppState { export default class AppState {
history: History = createBrowserHistory(); history: History = createBrowserHistory();
routerStore = new RouterStore(); routerStore = new RouterStore();
uiStore = new UiStore(); uiStore = new UiStore();
httpApi = new HttpApi(); httpApi = new HttpApi();
tokenStore = this.httpApi.tokenStore; tokenStore = this.httpApi.tokenStore;
sprinklersRpc = new WebSocketRpcClient(`ws://${location.hostname}:${websocketPort}`, sprinklersRpc = new WebSocketRpcClient(this.tokenStore);
this.tokenStore);
@computed get isLoggedIn() { @computed get isLoggedIn() {
return this.tokenStore.accessToken.isValid; return this.tokenStore.accessToken.isValid;

Loading…
Cancel
Save