Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Injectable } from '@angular/core';
  2. import { DEFAULT_INTERRUPTSOURCES, Idle } from '@ng-idle/core';
  3. import { environment } from '../../../environments/environment';
  4. import { BsModalService } from 'ngx-bootstrap';
  5. import { IdlePopupComponent } from '../../components/popup/idle-popup/idle-popup.component';
  6.  
  7. @Injectable()
  8. export class IdleService {
  9.  
  10.   constructor(private idle: Idle,
  11.               private modalService: BsModalService) {
  12.     this.idle.setIdle(environment.idleTime);
  13.     this.idle.setTimeout(environment.idleTimeout);
  14.     this.idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);
  15.   }
  16.  
  17.   init(): void {
  18.     this.startWatch();
  19.     const modalConfig = {
  20.       keyboard: false,
  21.       ignoreBackdropClick: true,
  22.       class: 'modal-sm session-modal'
  23.     };
  24.  
  25.     this.idle.onTimeoutWarning.subscribe((countdown) => {
  26.       if (countdown === 60) {
  27.         this.modalService.show(IdlePopupComponent, modalConfig);
  28.       }
  29.     });
  30.   }
  31.  
  32.   startWatch(): void {
  33.     this.idle.watch();
  34.   }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement