4 Commits

Author SHA1 Message Date
4d14526858 1.0.4 2021-04-14 11:47:51 +00:00
8762430204 fix(core): update 2021-04-14 11:47:51 +00:00
48fd0516ed 1.0.3 2021-04-13 08:30:34 +00:00
2847d495e0 fix(core): update 2021-04-13 08:30:33 +00:00
6 changed files with 1240 additions and 212 deletions

1392
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@uptimelink/detector",
"version": "1.0.2",
"version": "1.0.4",
"private": false,
"description": "a detector for answering network questions locally. It does not rely on any online services.",
"main": "dist_ts/index.js",
@ -20,7 +20,10 @@
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.15.0"
},
"dependencies": {},
"dependencies": {
"@pushrocks/smartnetwork": "^2.0.4",
"@pushrocks/smarturl": "^1.0.8"
},
"browserslist": [
"last 1 chrome versions"
],

View File

@ -1,8 +1,21 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as detector from '../ts/index';
let testDetector: detector.Detector;
tap.test('first test', async () => {
console.log(detector.standardExport);
testDetector = new detector.Detector();
expect(testDetector).to.be.instanceOf(detector.Detector);
});
tap.test('should detect an closed port on a local domain', async () => {
const result = await testDetector.isActive('http://localhost:3008');
expect(result).to.be.false;
});
tap.test('should detect an open port on a remote domain', async () => {
const result = await testDetector.isActive('https://lossless.com');
expect(result).to.be.true;
});
tap.start();

View File

@ -1,2 +1,8 @@
const removeme = {};
export { removeme };
// pushrocks scope
import * as smartnetwork from '@pushrocks/smartnetwork';
import * as smarturl from '@pushrocks/smarturl';
export {
smartnetwork,
smarturl
};

View File

@ -0,0 +1,24 @@
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
}
}

View File

@ -1,3 +1 @@
import * as plugins from './detector.plugins';
export let standardExport = 'Hi there! :) This is an exported string';
export * from './detectpr.classes.detector';