detector/ts/detector.classes.detector.ts

29 lines
976 B
TypeScript
Raw Normal View History

2022-07-16 16:15:23 +00:00
import * as plugins from './detector.plugins.js';
2021-04-13 08:30:33 +00:00
export class Detector {
private smartnetworkInstance = new plugins.smartnetwork.SmartNetwork();
public async isActive(urlArg: string): Promise<boolean> {
2022-07-16 16:15:23 +00:00
const parsedUrl = plugins.smarturl.Smarturl.createFromUrl(urlArg);
2021-04-14 11:47:51 +00:00
if (parsedUrl.hostname === 'localhost') {
2021-04-13 08:30:33 +00:00
console.log(`detector target is localhost on port ${parsedUrl.port}`);
2022-07-16 16:15:23 +00:00
const portUnused = await this.smartnetworkInstance.isLocalPortUnused(
parseInt(parsedUrl.port, 10)
);
2021-04-14 11:47:51 +00:00
const portAvailable = !portUnused;
return portAvailable;
2021-04-13 08:30:33 +00:00
} else {
console.log(`detector target is remote domain ${parsedUrl.host} on port ${parsedUrl.port}`);
2022-07-16 16:15:23 +00:00
const postAvailable = await this.smartnetworkInstance.isRemotePortAvailable(
parsedUrl.host,
parseInt(parsedUrl.port, 10)
);
2021-04-14 11:47:51 +00:00
return postAvailable;
2021-04-13 08:30:33 +00:00
}
}
public detectType(urlArg: string) {
console.log('TODO'); // TODO
}
2022-07-16 16:15:23 +00:00
}