import{appHost}from"./servicelocator.js";import events from"./../emby-apiclient/events.js";function onAppResume(){var options,started=this.isStarted();this.stopInterval(),started&&((started=this._lastInterval)&&(options=this.options)&&started+options.timeoutMs<=Date.now()&&onInterval.call(this),this.startInterval())}function onInterval(){this._lastInterval=Date.now();var options=this.options;options&&options.onInterval()}function MethodTimer(options){this.options=options,this.boundOnAppResume=onAppResume.bind(this),this.boundOnInterval=onInterval.bind(this),events.on(appHost,"resume",this.boundOnAppResume),this.startInterval()}MethodTimer.prototype.stopInterval=function(){this._interval&&(("interval"===this._intervalType?clearInterval:clearTimeout)(this._interval),this._interval=null,this._intervalType=null)},MethodTimer.prototype.startInterval=function(){this._lastInterval=Date.now(),"interval"===this.options.type?(this._interval=setInterval(this.boundOnInterval,this.options.timeoutMs),this._intervalType="interval"):this._interval=setTimeout(this.boundOnInterval,this.options.timeoutMs)},MethodTimer.prototype.isStarted=function(){return null!=this._interval},MethodTimer.prototype.destroy=function(){this.options=null,this.boundOnAppResume&&(events.off(appHost,"resume",this.boundOnAppResume),this.boundOnAppResume=null),this.stopInterval(),this.boundOnInterval=null,this._lastInterval=null};export default MethodTimer;