@ng-idle/core: Timeout happening on one idle instance is causing the interrupt to stop working on the other idle instance

I’m using “@ng-idle/core”: “~11.1.0” and Angular 13 application.

I have two idle instances, one for auto logout and another one for screensaver.

If my screensaver is “Active” and if timeout happens on the first instance(i,e. autologout) and if I try to interrupt the screen then screensaver is not going off and its blocking the UI.(One thing is clear that interrupt subscription stops working in this scenario).

How to resolve this issue?.

Sample code for reference:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import {Component, NgZone, OnInit} from '@angular/core';
import {DEFAULT_INTERRUPTSOURCES, Idle, LocalStorage, LocalStorageExpiry} from '@ng-idle/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit{
title = 'my-idle-app';
private readonly screenSaver!: HTMLElement;
private readonly screenSaverText!: Text;
idleTime1: number = 1;
private screenSaverIdle = new Idle(new LocalStorageExpiry(new LocalStorage()), this.ngZone);
constructor(readonly ngZone: NgZone, private idle1: Idle) {
this.screenSaver = document.createElement('div');
this.screenSaver.id = 'screensaver';
this.screenSaver.className = 'screen-saver';
this.screenSaverText = document.createTextNode('---%');
const movingTxt = document.createElement('span');
movingTxt.appendChild(this.screenSaverText);
this.screenSaver.appendChild(movingTxt);
this.removeScreenSaver();
this.screenSaverIdle.setIdleName('screenSaverIdleService');
this.screenSaverIdle.setInterrupts(DEFAULT_INTERRUPTSOURCES);
this.screenSaverIdle.setTimeout(false);
this.screenSaverIdle.setIdle(10);
this.screenSaverIdle.watch();
this.screenSaverIdle.onIdleStart.subscribe(() => {
document.body.appendChild(this.screenSaver);
});
this.screenSaverIdle.onIdleEnd.subscribe(() => {
console.log('IDLE END ::');
this.removeScreenSaver();
});
}
ngOnInit() {
this.idle1.setIdleName('AutoLogoutIdleService');
this.idle1.setInterrupts(DEFAULT_INTERRUPTSOURCES);
this.idle1.setIdle(this.idleTime1);
this.idle1.setTimeout(10);
this.idle1.onIdleStart.subscribe(() => {
console.log("IDLE 1 STARTS")
});
this.idle1.onIdleEnd.subscribe({
next: () => {
console.log("IDLE 1 END");
},
complete: () => {
console.log("idle 1 completed");
}
});
this.idle1.onTimeout.subscribe(()=> {
console.log("User session timed Out",);
});
this.idle1.watch();
}
private removeScreenSaver() {
const ex = document.getElementById('screensaver');
if (ex) {
document.body.removeChild(ex);
}
}
}
</code>
<code>import {Component, NgZone, OnInit} from '@angular/core'; import {DEFAULT_INTERRUPTSOURCES, Idle, LocalStorage, LocalStorageExpiry} from '@ng-idle/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'] }) export class AppComponent implements OnInit{ title = 'my-idle-app'; private readonly screenSaver!: HTMLElement; private readonly screenSaverText!: Text; idleTime1: number = 1; private screenSaverIdle = new Idle(new LocalStorageExpiry(new LocalStorage()), this.ngZone); constructor(readonly ngZone: NgZone, private idle1: Idle) { this.screenSaver = document.createElement('div'); this.screenSaver.id = 'screensaver'; this.screenSaver.className = 'screen-saver'; this.screenSaverText = document.createTextNode('---%'); const movingTxt = document.createElement('span'); movingTxt.appendChild(this.screenSaverText); this.screenSaver.appendChild(movingTxt); this.removeScreenSaver(); this.screenSaverIdle.setIdleName('screenSaverIdleService'); this.screenSaverIdle.setInterrupts(DEFAULT_INTERRUPTSOURCES); this.screenSaverIdle.setTimeout(false); this.screenSaverIdle.setIdle(10); this.screenSaverIdle.watch(); this.screenSaverIdle.onIdleStart.subscribe(() => { document.body.appendChild(this.screenSaver); }); this.screenSaverIdle.onIdleEnd.subscribe(() => { console.log('IDLE END ::'); this.removeScreenSaver(); }); } ngOnInit() { this.idle1.setIdleName('AutoLogoutIdleService'); this.idle1.setInterrupts(DEFAULT_INTERRUPTSOURCES); this.idle1.setIdle(this.idleTime1); this.idle1.setTimeout(10); this.idle1.onIdleStart.subscribe(() => { console.log("IDLE 1 STARTS") }); this.idle1.onIdleEnd.subscribe({ next: () => { console.log("IDLE 1 END"); }, complete: () => { console.log("idle 1 completed"); } }); this.idle1.onTimeout.subscribe(()=> { console.log("User session timed Out",); }); this.idle1.watch(); } private removeScreenSaver() { const ex = document.getElementById('screensaver'); if (ex) { document.body.removeChild(ex); } } } </code>
import {Component, NgZone, OnInit} from '@angular/core';
import {DEFAULT_INTERRUPTSOURCES, Idle, LocalStorage, LocalStorageExpiry} from '@ng-idle/core';


@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit{
  title = 'my-idle-app';
  private readonly screenSaver!: HTMLElement;
  private readonly screenSaverText!: Text;
  idleTime1: number = 1;
  private screenSaverIdle = new Idle(new LocalStorageExpiry(new LocalStorage()), this.ngZone);

  constructor(readonly ngZone: NgZone, private idle1: Idle) {
    this.screenSaver = document.createElement('div');
    this.screenSaver.id = 'screensaver';
    this.screenSaver.className = 'screen-saver';
    this.screenSaverText = document.createTextNode('---%');
    const movingTxt = document.createElement('span');
    movingTxt.appendChild(this.screenSaverText);
    this.screenSaver.appendChild(movingTxt);
    this.removeScreenSaver();

    this.screenSaverIdle.setIdleName('screenSaverIdleService');
    this.screenSaverIdle.setInterrupts(DEFAULT_INTERRUPTSOURCES);
    this.screenSaverIdle.setTimeout(false);
    this.screenSaverIdle.setIdle(10);
    this.screenSaverIdle.watch();

    this.screenSaverIdle.onIdleStart.subscribe(() => {
      document.body.appendChild(this.screenSaver);
    });

    this.screenSaverIdle.onIdleEnd.subscribe(() => {
      console.log('IDLE END ::');
      this.removeScreenSaver();
    });
  }

  ngOnInit() {
    this.idle1.setIdleName('AutoLogoutIdleService');
    this.idle1.setInterrupts(DEFAULT_INTERRUPTSOURCES);

    this.idle1.setIdle(this.idleTime1);
    this.idle1.setTimeout(10);

    this.idle1.onIdleStart.subscribe(() => {
      console.log("IDLE 1 STARTS")
    });

    this.idle1.onIdleEnd.subscribe({
      next: () => {
        console.log("IDLE 1 END");
      },
      complete: () => {
        console.log("idle 1 completed");
      }
    });

    this.idle1.onTimeout.subscribe(()=> {
      console.log("User session timed Out",);
    });

    this.idle1.watch();
  }

  private removeScreenSaver() {
    const ex = document.getElementById('screensaver');
    if (ex) {
      document.body.removeChild(ex);
    }
  }
}

I analyzed the source code of the ng-idle library and it seems like, since timeout value is “false” for screensaver ideal instance it should not cancel the interrupt subscription.

So, my question will be regarding the instances of the services being created. Is it causing any problem here?.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật