1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-06 09:20:43 +01:00

[PM-6426] Implementing reconnect timer timeout for NotificationService using the TaskSchedulerService

This commit is contained in:
Cesar Gonzalez 2024-04-01 12:00:46 -05:00
parent f60a37fe2c
commit 5d41e8b627
No known key found for this signature in database
GPG Key ID: 3381A5457F8CCECF

View File

@ -18,6 +18,8 @@ import { EnvironmentService } from "../platform/abstractions/environment.service
import { LogService } from "../platform/abstractions/log.service"; import { LogService } from "../platform/abstractions/log.service";
import { MessagingService } from "../platform/abstractions/messaging.service"; import { MessagingService } from "../platform/abstractions/messaging.service";
import { StateService } from "../platform/abstractions/state.service"; import { StateService } from "../platform/abstractions/state.service";
import { TaskSchedulerService } from "../platform/abstractions/task-scheduler.service";
import { ScheduledTaskNames } from "../platform/enums/scheduled-task-name.enum";
import { SyncService } from "../vault/abstractions/sync/sync.service.abstraction"; import { SyncService } from "../vault/abstractions/sync/sync.service.abstraction";
export class NotificationsService implements NotificationsServiceAbstraction { export class NotificationsService implements NotificationsServiceAbstraction {
@ -26,7 +28,7 @@ export class NotificationsService implements NotificationsServiceAbstraction {
private connected = false; private connected = false;
private inited = false; private inited = false;
private inactive = false; private inactive = false;
private reconnectTimer: any = null; private reconnectTimer: number | NodeJS.Timeout = null;
constructor( constructor(
private logService: LogService, private logService: LogService,
@ -38,6 +40,7 @@ export class NotificationsService implements NotificationsServiceAbstraction {
private stateService: StateService, private stateService: StateService,
private authService: AuthService, private authService: AuthService,
private messagingService: MessagingService, private messagingService: MessagingService,
private taskSchedulerService: TaskSchedulerService,
) { ) {
this.environmentService.environment$.subscribe(() => { this.environmentService.environment$.subscribe(() => {
if (!this.inited) { if (!this.inited) {
@ -211,10 +214,11 @@ export class NotificationsService implements NotificationsServiceAbstraction {
} }
private async reconnect(sync: boolean) { private async reconnect(sync: boolean) {
if (this.reconnectTimer != null) { void this.taskSchedulerService.clearScheduledTask({
clearTimeout(this.reconnectTimer); taskName: ScheduledTaskNames.notificationsReconnectTimeout,
this.reconnectTimer = null; timeoutId: this.reconnectTimer,
} });
if (this.connected || !this.inited || this.inactive) { if (this.connected || !this.inited || this.inactive) {
return; return;
} }
@ -234,7 +238,11 @@ export class NotificationsService implements NotificationsServiceAbstraction {
} }
if (!this.connected) { if (!this.connected) {
this.reconnectTimer = setTimeout(() => this.reconnect(sync), this.random(120000, 300000)); this.reconnectTimer = await this.taskSchedulerService.setTimeout(
() => this.reconnect(sync),
this.random(120000, 300000),
ScheduledTaskNames.notificationsReconnectTimeout,
);
} }
} }