Re-auth on visibility change

This commit is contained in:
Alex Mikhalev 2019-07-22 22:43:25 -06:00
parent d675342908
commit 89562b11b0
2 changed files with 12 additions and 0 deletions

View File

@ -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);

View File

@ -38,8 +38,16 @@ 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() {
return this.tokenStore.accessToken.isValid; return this.tokenStore.accessToken.isValid;