-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
node_modules/ | ||
dist/ | ||
|
||
.idea | ||
.coveralls.yml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters