Skip to content

Commit

Permalink
Should fix CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
128keaton committed Mar 21, 2022
1 parent 42c191d commit 24afd6f
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 3 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules/
dist/

.idea
.coveralls.yml
Expand Down
21 changes: 21 additions & 0 deletions dist/hikvision.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#! /usr/bin/env node
export interface HikvisionCamera {
address: string;
name: string;
serial: string;
partialSerial: string;
}
/**
* Discover Hikvision cameras on the network
* @param timeout - Defaults to 3 seconds
*/
export declare function discoverCameras(timeout?: number): Promise<HikvisionCamera[]>;
/**
* Does the actual parsing, this library is just a wrapper anyway
* @param devices
*/
declare function parseDevices(devices: never[]): HikvisionCamera[];
export declare const _private: {
parseDevices: typeof parseDevices;
};
export {};
47 changes: 47 additions & 0 deletions dist/hikvision.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#! /usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._private = exports.discoverCameras = void 0;
// eslint-disable-next-line @typescript-eslint/no-var-requires
const mDnsSd = require('node-dns-sd');
/**
* Discover Hikvision cameras on the network
* @param timeout - Defaults to 3 seconds
*/
function discoverCameras(timeout = 3) {
return mDnsSd.discover({
name: '_CGI._tcp.local',
wait: timeout
}).then((devices) => parseDevices(devices));
}
exports.discoverCameras = discoverCameras;
/**
* Does the actual parsing, this library is just a wrapper anyway
* @param devices
*/
function parseDevices(devices) {
return devices.map(device => {
const partialSerial = `${device['modelName']}`.split(' - ')[1];
const additionals = device['packet']['additionals'];
const serialAdditional = additionals.find(additional => {
const name = `${additional['name']}`;
const type = `${additional['type']}`;
return name.includes(partialSerial) && type === 'A';
});
const serial = `${serialAdditional?.['name']}`.replace('.local', '');
return {
address: device['address'],
name: device['modelName'],
serial,
partialSerial
};
});
}
exports._private = {
parseDevices
};
/* istanbul ignore if */
if (require.main == module) {
/* istanbul ignore next */
discoverCameras().then(cameras => console.log(JSON.stringify(cameras, null, 2)));
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "hikvision-mdns",
"version": "0.0.7",
"version": "0.0.8",
"description": "A HikVision discovery tool using mDNS/ZeroConf/Bonjour",
"main": "dist/hikvision.js",
"types": "dist/hikvision.d.ts",
"scripts": {
"clean": "rm -rf dist && mkdir dist",
"build": "npm run clean && tsc",
"build": "npm run clean && tsc && chmod +x dist/hikvision.js",
"test": "jest --config=jest.config.js --coverage"
},
"bin": {
Expand Down
1 change: 1 addition & 0 deletions src/hikvision.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#! /usr/bin/env node
// eslint-disable-next-line @typescript-eslint/no-var-requires
const mDnsSd = require('node-dns-sd');

Expand Down

0 comments on commit 24afd6f

Please sign in to comment.