mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 01:03:35 +00:00
activity connect/disconnect events
This commit is contained in:
@@ -3,4 +3,6 @@ import { EnvironmentService } from './environment.service';
|
|||||||
export abstract class NotificationsService {
|
export abstract class NotificationsService {
|
||||||
init: (environmentService: EnvironmentService) => Promise<void>;
|
init: (environmentService: EnvironmentService) => Promise<void>;
|
||||||
updateConnection: () => Promise<void>;
|
updateConnection: () => Promise<void>;
|
||||||
|
reconnectFromActivity: () => Promise<any>;
|
||||||
|
disconnectFromInactivity: () => Promise<any>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export class NotificationsService implements NotificationsServiceAbstraction {
|
|||||||
private url: string;
|
private url: string;
|
||||||
private connected = false;
|
private connected = false;
|
||||||
private inited = false;
|
private inited = false;
|
||||||
|
private inactive = false;
|
||||||
private reconnectTimer: any = null;
|
private reconnectTimer: any = null;
|
||||||
|
|
||||||
constructor(private userService: UserService, private tokenService: TokenService,
|
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) {
|
private async processNotification(notification: NotificationResponse) {
|
||||||
const appId = await this.appIdService.getAppId();
|
const appId = await this.appIdService.getAppId();
|
||||||
if (notification == null || notification.contextId === appId) {
|
if (notification == null || notification.contextId === appId) {
|
||||||
@@ -125,8 +142,11 @@ export class NotificationsService implements NotificationsServiceAbstraction {
|
|||||||
clearTimeout(this.reconnectTimer);
|
clearTimeout(this.reconnectTimer);
|
||||||
this.reconnectTimer = null;
|
this.reconnectTimer = null;
|
||||||
}
|
}
|
||||||
|
if (this.connected || !this.inited || this.inactive) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const authed = await this.userService.isAuthenticated();
|
const authed = await this.userService.isAuthenticated();
|
||||||
if (this.connected || !this.inited || !authed) {
|
if (!authed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user