首页 > 解决方案 > 从 Ng-Idle 中删除 mousemove 等事件

问题描述

我正在使用 Ng-Idle 库来检查用户在 angular webapp 中的不活动情况。

我已经实现了这么远的库

idle.setIdle(5);
idle.setTimeout(0);
idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);
idle.onIdleEnd.subscribe(() => { 
  this.idleState = 'No longer idle.'
  console.log(this.idleState);
  this.idle.watch();
  this.idleState = 'Started.';
});
idle.onIdleStart.subscribe(() => {
  this.idleState = 'You\'ve gone idle!'
  console.log(this.idleState);
});

问题是 DEFAULT_INTERRUPTSOURCES 需要所有这些mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove 滚动中断事件,但我只希望键盘和鼠标单击中断来停止 ng-idle。

我尝试从这些库文件中更改事件 ---> ng-idle-core.umd.js、ng-idle-core.umd.js.map 和 ng-idle-core.metadata.json。仍然没有成功。

如何实现所需的功能?

标签: angularng-idle

解决方案


我通过以下代码得到了想要的结果

idle.setInterrupts(this.createCustomInterruptSources(null));

createCustomInterruptSources(options) {
  return [
      new DocumentInterruptSource('keydown mousedown touchstart touchmove 
      scroll', options),
      new StorageInterruptSource(options)
  ];
}

推荐阅读