Browse Source

Re-auth on visibility change

master
Alex Mikhalev 6 years ago
parent
commit
89562b11b0
  1. 4
      client/sprinklersRpc/WebSocketRpcClient.ts
  2. 8
      client/state/AppState.ts

4
client/sprinklersRpc/WebSocketRpcClient.ts

@ -92,6 +92,10 @@ export class WebSocketRpcClient extends s.SprinklersRPC {
this._connect(); this._connect();
} }
reconnect() {
this._connect();
}
stop() { stop() {
if (this.reconnectTimer != null) { if (this.reconnectTimer != null) {
clearTimeout(this.reconnectTimer); clearTimeout(this.reconnectTimer);

8
client/state/AppState.ts

@ -38,7 +38,15 @@ export default class AppState extends TypedEventEmitter<AppEvents> {
when(() => !this.tokenStore.accessToken.isValid, this.checkToken); when(() => !this.tokenStore.accessToken.isValid, this.checkToken);
this.sprinklersRpc.start(); this.sprinklersRpc.start();
}); });
document.addEventListener("visibilitychange", this.onPageFocus);
}
onPageFocus = () => {
if (document.visibilityState === "visible") {
this.sprinklersRpc.reconnect();
} }
};
@computed @computed
get isLoggedIn() { get isLoggedIn() {

Loading…
Cancel
Save