Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
4d14526858 | |||
8762430204 | |||
48fd0516ed | |||
2847d495e0 |
1392
package-lock.json
generated
1392
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@uptimelink/detector",
|
"name": "@uptimelink/detector",
|
||||||
"version": "1.0.2",
|
"version": "1.0.4",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a detector for answering network questions locally. It does not rely on any online services.",
|
"description": "a detector for answering network questions locally. It does not rely on any online services.",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -20,7 +20,10 @@
|
|||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
"dependencies": {},
|
"dependencies": {
|
||||||
|
"@pushrocks/smartnetwork": "^2.0.4",
|
||||||
|
"@pushrocks/smarturl": "^1.0.8"
|
||||||
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
],
|
],
|
||||||
|
15
test/test.ts
15
test/test.ts
@ -1,8 +1,21 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import * as detector from '../ts/index';
|
import * as detector from '../ts/index';
|
||||||
|
|
||||||
|
let testDetector: detector.Detector;
|
||||||
|
|
||||||
tap.test('first test', async () => {
|
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();
|
tap.start();
|
||||||
|
@ -1,2 +1,8 @@
|
|||||||
const removeme = {};
|
// pushrocks scope
|
||||||
export { removeme };
|
import * as smartnetwork from '@pushrocks/smartnetwork';
|
||||||
|
import * as smarturl from '@pushrocks/smarturl';
|
||||||
|
|
||||||
|
export {
|
||||||
|
smartnetwork,
|
||||||
|
smarturl
|
||||||
|
};
|
||||||
|
24
ts/detectpr.classes.detector.ts
Normal file
24
ts/detectpr.classes.detector.ts
Normal 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
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1 @@
|
|||||||
import * as plugins from './detector.plugins';
|
export * from './detectpr.classes.detector';
|
||||||
|
|
||||||
export let standardExport = 'Hi there! :) This is an exported string';
|
|
Reference in New Issue
Block a user