1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-27 04:03:00 +02:00

activity connect/disconnect events

This commit is contained in:
Kyle Spearrin 2018-08-22 21:09:58 -04:00
parent 74b31daf14
commit d37fa836da
2 changed files with 23 additions and 1 deletions

View File

@ -3,4 +3,6 @@ import { EnvironmentService } from './environment.service';
export abstract class NotificationsService {
init: (environmentService: EnvironmentService) => Promise<void>;
updateConnection: () => Promise<void>;
reconnectFromActivity: () => Promise<any>;
disconnectFromInactivity: () => Promise<any>;
}

View File

@ -21,6 +21,7 @@ export class NotificationsService implements NotificationsServiceAbstraction {
private url: string;
private connected = false;
private inited = false;
private inactive = false;
private reconnectTimer: any = null;
constructor(private userService: UserService, private tokenService: TokenService,
@ -75,6 +76,22 @@ export class NotificationsService implements NotificationsServiceAbstraction {
}
}
async reconnectFromActivity(): Promise<any> {
this.inactive = false;
if (!this.connected) {
if (await this.userService.isAuthenticated()) {
return this.reconnect().then(() => this.syncService.fullSync(false));
}
}
}
async disconnectFromInactivity(): Promise<any> {
this.inactive = true;
if (this.connected) {
await this.signalrConnection.stop();
}
}
private async processNotification(notification: NotificationResponse) {
const appId = await this.appIdService.getAppId();
if (notification == null || notification.contextId === appId) {
@ -125,8 +142,11 @@ export class NotificationsService implements NotificationsServiceAbstraction {
clearTimeout(this.reconnectTimer);
this.reconnectTimer = null;
}
if (this.connected || !this.inited || this.inactive) {
return;
}
const authed = await this.userService.isAuthenticated();
if (this.connected || !this.inited || !authed) {
if (!authed) {
return;
}