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

8
client/state/AppState.ts

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

Loading…
Cancel
Save