diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 00000000..1db3349e --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,81 @@ +const commonRules = { + 'no-console' : 'warn', + 'comma-dangle' : [ 'error', 'always-multiline' ], + 'import/extensions' : 0, + 'import/no-cycle' : 0, + 'quote-props' : 0, + 'import/prefer-default-export' : 0, + 'no-await-in-loop' : 0, + 'no-restricted-syntax' : 0, + 'max-classes-per-file' : 0, + 'no-underscore-dangle' : 0, + 'no-param-reassign' : 0, + 'no-unused-expressions' : 0, + 'no-unused-vars' : 'warn', + 'no-case-declarations' : 0, + 'no-shadow' : 0, + 'brace-style' : ["error", "1tbs", { "allowSingleLine" : true }], + 'lines-between-class-members' : 0, + 'max-len' : ['warn', 200], + 'class-methods-use-this' : 0, + 'no-nested-ternary' : 0, + 'no-use-before-define' : 0, + 'key-spacing' : ['error', { + afterColon : true, + beforeColon : true, + align : { + beforeColon : true, + afterColon : true, + on : 'colon', + }, + }], + '@typescript-eslint/member-delimiter-style' : 1, + 'import/no-extraneous-dependencies' : 0, + // 'import/export' : 0 + 'object-curly-newline' : ['error', {multiline : true, consistent : true}], +}; + +module.exports = { + plugins : ['@typescript-eslint'], + extends : [ + 'airbnb-base', + 'prettier', + ], + env : { + node : true, + jest : true, + mocha : true, + }, + rules : commonRules, + + overrides : [ + { + files : ['*.ts'], + extends : [ + 'airbnb-base', + 'plugin:@typescript-eslint/eslint-recommended', + 'plugin:@typescript-eslint/recommended', + ], + rules : { + ...commonRules, + + '@typescript-eslint/interface-name-prefix' : 0, + '@typescript-eslint/no-non-null-assertion' : 0, + '@typescript-eslint/no-explicit-any' : 0, // TRY: Remove this + '@typescript-eslint/ban-ts-ignore' : 0, // TRY: Remove this + }, + + settings : { + 'import/extensions' : ['.ts'], + 'import/parsers' : { + '@typescript-eslint/parser' : ['.ts'], + }, + 'import/resolver' : { + node : { + extensions : ['.ts', '.d.ts', '.js'], + }, + }, + }, + }, + ], +}; diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 8740328e..00000000 --- a/.eslintrc.json +++ /dev/null @@ -1,78 +0,0 @@ -{ - "extends": ["eslint:recommended", "plugin:node/recommended"], - "env": { - "node": true, - "mocha": true - }, - "rules": { - "node/no-deprecated-api": 0, - "no-console": 0, - "no-param-reassign": 0, - "no-unused-vars": [ - "error", - { - "argsIgnorePattern": "^_" - } - ], - "object-curly-newline": [ - "error", - { - "ObjectPattern": { - "multiline": true - } - } - ], - "strict": 0, - "curly": [ - 2, - "all" - ], - "keyword-spacing": [ - 2, - {} - ], - "space-before-function-paren": [ - 2, - "never" - ], - "no-spaced-func": 2, - "space-infix-ops": 2, - "space-unary-ops": [ - 2, - { - "words": false, - "nonwords": false - } - ], - "no-with": 2, - "brace-style": [ - 2, - "1tbs", - { - "allowSingleLine": true - } - ], - "key-spacing": [ - 2, - { - "beforeColon": false, - "afterColon": true - } - ], - "indent": [ - 2, - "tab", - { - "SwitchCase": 1 - } - ], - "no-mixed-spaces-and-tabs": 2, - "camelcase": [ - 2, - { - "properties": "never" - } - ], - "semi": "error" - } -} diff --git a/.gitignore b/.gitignore index 039b6112..bdf8d0ca 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,5 @@ test.js cam_tests experiments docs -.nyc_output -.vscode +build +.nyc_output/ diff --git a/.mocharc.js b/.mocharc.js index 8a636aa8..b3ec7654 100644 --- a/.mocharc.js +++ b/.mocharc.js @@ -1,4 +1,4 @@ module.exports = { - 'spec': 'test/*.js', - 'exclude': 'test/serverMockup.js' + 'spec': 'compatibilityTest/*.js', + 'exclude': 'compatibilityTest/serverMockup.js' }; diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..378eac25 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +build diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..f8e1636f --- /dev/null +++ b/.prettierrc @@ -0,0 +1,8 @@ +{ + "singleQuote": true, + "semi": true, + "trailingComma": "all", + "arrowParens": "always", + "endOfLine": "lf", + "printWidth": 120 +} diff --git a/CHECKED.md b/CHECKED.md new file mode 100644 index 00000000..1a075cad --- /dev/null +++ b/CHECKED.md @@ -0,0 +1,119 @@ +ONVIF Interfaces + +- [x] connect +- [x] _request +- [x] _requestPart2 +- [x] getSystemDateAndTime +- [x] setSystemDateAndTime accepts SetSystemDateAndTimeOptions +- [x] getCapabilities Capabilities -> GetCapabilitiesResponse +- [x] getServiceCapabilities DeviceServiceCapabilities -> GetServiceCapabilitiesResponse +- [ ] getActiveSources +- [x] getServices includeCapability wrapped into object +- [ ] getDeviceInformation +- [ ] getHostname +- [ ] getScopes +- [ ] setScopes +- [ ] systemReboot +- [ ] setSystemFactoryDefault +- [x] _passwordDigest +- [x] _envelopeHeader +- [x] _envelopeFooter +- [x] _parseUrl +- [x] getNTP cam.device.getNTP +- [x] setNTP cam.device.setNTP +- [ ] getNetworkInterfaces +- [ ] setNetworkInterfaces +- [ ] getNetworkDefaultGateway +- [ ] setNetworkDefaultGateway +- [x] getDNS cam.device.getDNS +- [ ] setDNS +- [ ] getNetworkProtocols +- [ ] getUsers +- [ ] createUsers +- [ ] setUsers +- [ ] deleteUsers +- [ ] sendAuxiliaryCommand +- [ ] getEventProperties +- [ ] getEventServiceCapabilities +- [ ] subscribe +- [ ] createPullPointSubscription +- [ ] renew +- [ ] pullMessages +- [ ] unsubscribe +- [ ] _eventRequest +- [ ] _eventPull +- [ ] _restartEventRequest +- [x] parseEventXML +- [x] getVideoSources +- [x] getVideoSourceConfigurations +- [x] getVideoSourceConfigurationOptions new +- [ ] getVideoEncoderConfiguration +- [ ] getVideoEncoderConfigurationOptions +- [x] getVideoEncoderConfigurations +- [ ] setVideoEncoderConfiguration +- [ ] getAudioSources +- [ ] getAudioEncoderConfigurations +- [ ] getAudioEncoderConfiguration +- [ ] getAudioEncoderConfigurationOptions +- [ ] setAudioEncoderConfiguration +- [ ] getAudioSourceConfigurations +- [ ] getAudioOutputs +- [ ] getAudioOutputConfigurations +- [ ] addAudioEncoderConfiguration +- [ ] addAudioSourceConfiguration +- [ ] addVideoEncoderConfiguration +- [ ] addVideoSourceConfiguration +- [ ] removeAudioEncoderConfiguration +- [ ] removeAudioSourceConfiguration +- [ ] getProfiles +- [ ] createProfile +- [ ] deleteProfile +- [ ] getStreamUri +- [ ] getSnapshotUri +- [ ] setSynchronizationPoint +- [x] getOSDs cam.media.getOSDs (schema strict) +- [x] getOSDOptions cam.media.getOSDOptions (videoSourceConfigurationToken -> configurationToken) +- [ ] createOSD +- [ ] setOSD +- [ ] deleteOSD +- [ ] getMediaServiceCapabilities +- [ ] getPresets +- [ ] gotoPreset +- [ ] setPreset +- [ ] removePreset +- [ ] gotoHomePosition +- [ ] setHomePosition +- [ ] getStatus +- [ ] getNodes +- [ ] getConfigurations +- [ ] getConfigurationOptions +- [ ] relativeMove +- [ ] absoluteMove +- [ ] continuousMove +- [ ] stop +- [ ] _panTiltZoomVectors +- [ ] ptzSendAuxiliaryCommand +- [ ] getImagingSettings +- [ ] setImagingSettings +- [ ] getImagingServiceCapabilities +- [ ] getCurrentImagingPreset +- [ ] setCurrentImagingPreset +- [ ] getVideoSourceOptions +- [ ] imagingGetMoveOptions +- [ ] imagingGetStatus +- [ ] imagingMove +- [ ] imagingStop +- [ ] getRecordings +- [ ] getRecordingJobs +- [ ] createRecordingJob +- [ ] deleteRecordingJob +- [ ] getRecordingSummary +- [ ] getRecordingInformation +- [ ] getRecordingConfiguration +- [ ] getRecordingJobState +- [ ] getRecordingOptions +- [ ] getRecordingServiceCapabilities +- [ ] getTrackConfiguration +- [ ] getRecordingJobConfiguration +- [ ] setRecordingJobMode +- [ ] getReplayUri diff --git a/IMPLEMENTED.md b/IMPLEMENTED.md new file mode 100644 index 00000000..aa0dccc8 --- /dev/null +++ b/IMPLEMENTED.md @@ -0,0 +1,103 @@ +# Implemented methods and properties in typescript + +- [x] activeSource +- [x] activeSources +- [x] capabilities +- [x] defaultProfile +- [x] defaultProfiles +- [ ] events +- [x] preserveAddress +- [x] profiles +- [ ] recordingItem +- [x] scopes +- [x] services +- [x] uri +- [x] videoSources +- [x] xaddrs +- [ ] absoluteMove +- [ ] addAudioEncoderConfiguration +- [ ] addAudioSourceConfiguration +- [ ] addVideoEncoderConfiguration +- [ ] addVideoSourceConfiguration +- [ ] connect +- [ ] continuousMove +- [ ] createOSD +- [ ] createProfile +- [ ] createPullPointSubscription +- [ ] createUsers +- [ ] deleteOSD +- [ ] deleteProfile +- [ ] deleteUsers +- [x] getActiveSources +- [ ] getAudioEncoderConfiguration +- [ ] getAudioEncoderConfigurationOptions +- [ ] getAudioEncoderConfigurations +- [ ] getAudioOutputConfigurations +- [ ] getAudioOutputs +- [ ] getAudioSourceConfigurations +- [ ] getAudioSources +- [x] getCapabilities +- [x] getConfigurationOptions +- [x] getConfigurations +- [ ] getCurrentImagingPreset +- [x] getDeviceInformation +- [ ] getDNS +- [ ] getEventProperties +- [ ] getEventServiceCapabilities +- [x] getHostname +- [ ] getImagingServiceCapabilities +- [ ] getImagingSettings +- [ ] getMediaServiceCapabilities +- [ ] getNetworkDefaultGateway +- [ ] getNetworkInterfaces +- [ ] getNetworkProtocols +- [x] getNodes +- [ ] getNTP +- [ ] getOSDOptions +- [ ] getOSDs +- [x] getPresets +- [ ] getProfiles +- [ ] getRecordings +- [ ] getReplayUri +- [ ] getScopes +- [x] getServiceCapabilities +- [x] getServices +- [x] getSnapshotUri +- [x] getStatus +- [x] getStreamUri +- [x] getSystemDateAndTime +- [ ] getUsers +- [ ] getVideoEncoderConfiguration +- [ ] getVideoEncoderConfigurationOptions +- [ ] getVideoEncoderConfigurations +- [ ] getVideoOutputs +- [ ] getVideoSourceConfigurations +- [ ] getVideoSourceOptions +- [ ] getVideoSources +- [x] gotoHomePosition +- [x] gotoPreset +- [ ] pullMessages +- [ ] relativeMove +- [ ] removeAudioEncoderConfiguration +- [ ] removeAudioSourceConfiguration +- [x] removePreset +- [ ] renew +- [ ] setAudioEncoderConfiguration +- [ ] setCurrentImagingPreset +- [ ] setDNS +- [x] setHomePosition +- [ ] setImagingSettings +- [ ] setNetworkDefaultGateway +- [ ] setNetworkInterfaces +- [ ] setNTP +- [ ] setOSD +- [x] setPreset +- [x] setScopes +- [x] setSystemDateAndTime +- [ ] setSystemFactoryDefault +- [ ] setUsers +- [ ] setVideoEncoderConfiguration +- [ ] stop +- [ ] subscribe +- [x] systemReboot +- [ ] unsubscribe diff --git a/README.md b/README.md index 4a807cdf..dd4f21b4 100644 --- a/README.md +++ b/README.md @@ -13,451 +13,20 @@ The library uses NodeJS. And works on the server-side. [![ONVIF](https://www.onvif.org/wp-content/themes/onvif-public/images/logo.png)](http://onvif.org) -## Troubleshooting -The library is tested on a test bed with 5 x Axis, 2 x Bosch, 1 x Canon, 2 x Hanwha, 4 x HikVision, 1 x Panasonic, 2 x Sony and 2 x unknown vendor cameras. There is a mix of PTZ and Fixed cameras and a mix of Pre-Profile, Profile S, Profile G and Profile T devices. -It is also tested with some Analogue Encoders from Avigilon, Axis, Bosch and HikVision including testing the RS485 output. +This is a new version of the ONVIF library. Previous version was written in JS, and this the typescript library with +interfaces descbring ONVIF data structures. Right now some of the methods from the v.0.7.x were implemented, +the list of supportrted ONVIF commands you can find here: https://github.com/agsh/onvif/blob/v1/IMPLEMENTED.md -We welcome any donations or long term loans cameras from other vendors to test compatibility especially when testing the Media2 API, ONVIF Events and OSD. +The library will be updated because other methods are currently under development. +The documentation for the new library was generated by typedoc and you can find it here: +https://htmlpreview.github.io/?https://github.com/agsh/onvif/blob/v1/docs/index.html -## Installation +The code, which use the old version of the library (0.6.x), should work using the compatibility class: +https://github.com/agsh/onvif/blob/v1/src/compatibility/cam.ts where all methods are located. -### NPM +Thanks a lot for your interest and I will be glad to any questions and comments! -`npm install onvif` - install latest stable version +P.S. I still need device access to test the code, any help would be greatly appreciated. -`npm install agsh/onvif` - install latest version from GitHub - -`npm install agsh/onvif#v1` - install latest development version - -### Clone the latest version from github -`git clone https://github.com/agsh/onvif.git` - -### Tests -In the library directory run `npm test` - -By default the tests use a mockup server to generate ONVIF replies. - -To test with the real device, set appropriate environment variables `HOSTNAME`, `USERNAME`, `PASSWORD`, `PORT` and run -tests. - -### Documentation -To build jsdoc for the library with default theme run `npm run jsdoc`. Otherwise use `jsdoc` with sources from -`./lib/*.js` - -## Quick example - -Special teasing example how to create little funny video server (http://localhost:6147) with 1 ffmpeg and 3 node.js libraries: - - -```shell -sudo apt install ffmpeg -npm install onvif socket.io rtsp-ffmpeg -``` - -```js -const server = require('http').createServer((req, res) => - res.end(` -
- -