detector/ts/detectpr.classes.detector.ts
2021-04-14 11:47:51 +00:00

24 lines
985 B
TypeScript

import * as plugins from './detector.plugins';
export class Detector {
private smartnetworkInstance = new plugins.smartnetwork.SmartNetwork();
private smarturlInstance = new plugins.smarturl.Smarturl();
public async isActive(urlArg: string): Promise<boolean> {
const parsedUrl = this.smarturlInstance.parseUrl(urlArg);
if (parsedUrl.hostname === 'localhost') {
console.log(`detector target is localhost on port ${parsedUrl.port}`);
const portUnused = await this.smartnetworkInstance.isLocalPortUnused(parseInt(parsedUrl.port, 10));
const portAvailable = !portUnused;
return portAvailable;
} else {
console.log(`detector target is remote domain ${parsedUrl.host} on port ${parsedUrl.port}`);
const postAvailable = await this.smartnetworkInstance.isRemotePortAvailable(parsedUrl.host, parseInt(parsedUrl.port, 10));
return postAvailable;
}
}
public detectType(urlArg: string) {
console.log('TODO'); // TODO
}
}