mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-11 19:40:47 +01:00
activity connect/disconnect events
This commit is contained in:
parent
74b31daf14
commit
d37fa836da
@ -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>;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user