idle reconnects for notifications

This commit is contained in:
Kyle Spearrin 2018-08-22 22:37:55 -04:00
parent 71073874eb
commit 80febf97d3
4 changed files with 33 additions and 6 deletions

2
jslib

@ -1 +1 @@
Subproject commit 74b31daf1463502f72fa311d91ea68b11e109423
Subproject commit 3d02a1ecb8cdb945f3bee2fbb6921b40286575a1

View File

@ -47,6 +47,7 @@ import { RouterService } from './services/router.service';
const BroadcasterSubscriptionId = 'AppComponent';
// Hack due to Angular 5.2 bug
const swal: SweetAlert = _swal as any;
const IdleTimeout = 60000 * 5; // 5 minutes
@Component({
selector: 'app-root',
@ -61,6 +62,8 @@ export class AppComponent implements OnDestroy, OnInit {
});
private lastActivity: number = null;
private idleTimer: number = null;
private isIdle = false;
constructor(private angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics,
private broadcasterService: BroadcasterService, private userService: UserService,
@ -90,9 +93,8 @@ export class AppComponent implements OnDestroy, OnInit {
switch (message.command) {
case 'loggedIn':
case 'loggedOut':
this.notificationsService.updateConnection();
break;
case 'unlocked':
this.notificationsService.updateConnection();
break;
case 'logout':
this.logOut(!!message.expired);
@ -101,6 +103,7 @@ export class AppComponent implements OnDestroy, OnInit {
await this.lockService.lock();
break;
case 'locked':
this.notificationsService.updateConnection();
this.router.navigate(['lock']);
break;
case 'syncStarted':
@ -181,5 +184,29 @@ export class AppComponent implements OnDestroy, OnInit {
this.lastActivity = now;
this.storageService.save(ConstantsService.lastActiveKey, now);
// Idle states
if (this.isIdle) {
this.isIdle = false;
this.idleStateChanged();
}
if (this.idleTimer != null) {
window.clearTimeout(this.idleTimer);
this.idleTimer = null;
}
this.idleTimer = window.setTimeout(() => {
if (!this.isIdle) {
this.isIdle = true;
this.idleStateChanged();
}
}, IdleTimeout);
}
private idleStateChanged() {
if (this.isIdle) {
this.notificationsService.disconnectFromInactivity();
} else {
this.notificationsService.reconnectFromActivity();
}
}
}

View File

@ -115,8 +115,8 @@ const authService = new AuthService(cryptoService, apiService,
userService, tokenService, appIdService, i18nService, platformUtilsService, messagingService);
const exportService = new ExportService(folderService, cipherService, apiService);
const importService = new ImportService(cipherService, folderService, apiService, i18nService, collectionService);
const notificationsService = new NotificationsService(userService, tokenService, syncService, appIdService,
apiService);
const notificationsService = new NotificationsService(userService, syncService, appIdService,
apiService, cryptoService);
const environmentService = new EnvironmentService(apiService, storageService, notificationsService);
const auditService = new AuditService(cryptoFunctionService, apiService);

View File

@ -102,7 +102,7 @@ export class VaultComponent implements OnInit, OnDestroy {
await Promise.all([
this.groupingsComponent.load(),
this.organizationsComponent.load(),
this.ciphersComponent.refresh(),
this.ciphersComponent.load(this.ciphersComponent.filter),
]);
this.changeDetectorRef.detectChanges();
}