@observertc/client-monitor-js
Version:
ObserveRTC Client Integration Javascript Library
1 lines • 1.1 kB
JavaScript
import{createLogger as t}from"../utils/logger";export class Detectors{_detectors;logger;constructor(...e){this.logger=t(),this._detectors=e}add(t){this._detectors.push(t)}remove(t){this._detectors=this._detectors.filter((e=>e!==t))}clear(){this._detectors=[]}get size(){return this._detectors.length}get listOfNames(){return this._detectors.map((t=>t.name))}[Symbol.iterator](){return this._detectors[Symbol.iterator]()}has(t){return this._detectors.some((e=>e.name===t))}getByName(t){return this._detectors.find((e=>e.name===t))}find(t){return this._detectors.find(t)}filter(t){return this._detectors.filter(t)}disable(t){const e=this.getByName(t);return!!e&&(e.disabled=!0,!0)}enable(t){const e=this.getByName(t);return!!e&&(e.disabled=!1,!0)}disableAll(){for(const t of this._detectors)t.disabled=!0}enableAll(){for(const t of this._detectors)t.disabled=!1}isEnabled(t){const e=this.getByName(t);return Boolean(e)&&!e.disabled}update(){for(const t of this._detectors)if(!t.disabled)try{t.update()}catch(e){this.logger.warn("[Detectors]:",`Error updating detector ${t?.constructor?.name}`,e)}}}