mirror of
https://github.com/nttgin/BGPalerter.git
synced 2024-05-19 06:50:08 +00:00
36 lines
959 B
JavaScript
36 lines
959 B
JavaScript
|
import env from "./env";
|
||
|
|
||
|
export default class ConnectorFactory {
|
||
|
|
||
|
constructor() {
|
||
|
this.disconnected = [];
|
||
|
this.connected = [];
|
||
|
|
||
|
}
|
||
|
|
||
|
loadConnectors = () => {
|
||
|
if (this.disconnected.length === 0) {
|
||
|
this.disconnected = config.reports.map(connector => new connector.class(connector.params, env));
|
||
|
}
|
||
|
};
|
||
|
|
||
|
connectConnectors = () =>
|
||
|
Promise.all(this.disconnected.map(connector => {
|
||
|
connector.connect()
|
||
|
.then(() => {
|
||
|
this.connected.push();
|
||
|
});
|
||
|
}));
|
||
|
|
||
|
subscribeConnectors = (params) =>
|
||
|
new Promise((resolve, reject) => {
|
||
|
|
||
|
if (this.connectors.length === 0) {
|
||
|
reject(new Error("No connectors loaded"));
|
||
|
} else {
|
||
|
|
||
|
resolve(Promise.all(this.connectors.map(connector => connector.subscribe(params))));
|
||
|
}
|
||
|
|
||
|
});
|
||
|
}
|