From d37fa836da523ae69413881f4af929c6808a688b Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 22 Aug 2018 21:09:58 -0400 Subject: [PATCH] activity connect/disconnect events --- src/abstractions/notifications.service.ts | 2 ++ src/services/notifications.service.ts | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/abstractions/notifications.service.ts b/src/abstractions/notifications.service.ts index 540b9885fce..1908c436bcb 100644 --- a/src/abstractions/notifications.service.ts +++ b/src/abstractions/notifications.service.ts @@ -3,4 +3,6 @@ import { EnvironmentService } from './environment.service'; export abstract class NotificationsService { init: (environmentService: EnvironmentService) => Promise; updateConnection: () => Promise; + reconnectFromActivity: () => Promise; + disconnectFromInactivity: () => Promise; } diff --git a/src/services/notifications.service.ts b/src/services/notifications.service.ts index fe5bf96c387..f9af37ed404 100644 --- a/src/services/notifications.service.ts +++ b/src/services/notifications.service.ts @@ -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 { + this.inactive = false; + if (!this.connected) { + if (await this.userService.isAuthenticated()) { + return this.reconnect().then(() => this.syncService.fullSync(false)); + } + } + } + + async disconnectFromInactivity(): Promise { + 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; }