import Parser from "rss-parser"; const DEFAULT_TIMELOOP = 5 * 60; // default timeloop is 5 min class ListenerRss { name = ""; address = ""; timeloop = DEFAULT_TIMELOOP; // time in seconds customfields = []; // private fields parser: Parser; loopRunning = false; constructor( name: String, address: String, timeloop: number, customfields: String[][] ) { this.parser = new Parser(); // if (name !== undefined && name instanceof ListenerInfo) { // // constructor with 1 arg // this.setData({name}); // } else if (address !== undefined && typeof address === "string") { // // construct with between 2 and 4 args // this.setData(new ListenerInfo(name, address, timeloop, customfields)); // } else throw new Error("the constructor must have args"); // this.setParser(); } // setParser() { // // set parser // this.parser = new Parser( // this.customfields !== undefined // ? { // customFields: { // item: this.customfields.map((elt) => { // return Array.isArray(elt[1]) ? elt[1][0] : elt[1]; // }), // }, // } // : {} // ); // if customfield is set -> let's set the parser with, else let the option empty // } // setData({name: String, address: String, timeloop: number = DEFAULT_TIMELOOP}) { // // Set data // this.name = name; // this.address = address; // this.timeloop = // this.timeloop === undefined ? DEFAULT_TIMELOOP : infos._timeloop; // this.customfields = infos._customfields === undefined ? [] : infos._customfields; // } // fetchRSS() { // return this.parser.parseURL(this.address).catch((err) => { // throw new Error("bad address or no access : " + err); // }); // } // /** // * @brief call the callback function each looptime // * @param callback function who's going to be called with the latest get // */ // start(callback) { // this.loopRunning = true; // (async () => { // while (this.loopRunning === true) { // this.fetchRSS().then((obj, err) => callback(obj, err)); // await new Promise((res) => setTimeout(res, 2000)); // } // })(); // } // /** // * @brief stop the async function // */ // stop() { // this.loopRunning = false; // } } module.exports = ListenerRss;