shinobi-onvif
v0.2.2
Published
Made by futomi (on Github) and updated by SolinkCorp (on Github). Forked from https://github.com/SolinkCorp/node-onvif and modified for use with Shinobi(CCTV).
Downloads
3,672
Maintainers
Readme
node-onvif
The node-onvif is a Node.js module which allows you to communicate with the network camera which supports the ONVIF specifications.
The ONVIF (Open Network Video Interface) is an open industry forum promoting and developing global standards for interfaces of IP-based physical security products such as network cameras. The ONVIF specifications are available in their web site.
Recently, most of network cameras for business support the ONVIF standard. Furthermore, some network cameras for home support it though the implementation is partial. The node-onvif allows you to control network cameras which implement the ONVIF standard.
The node-onvif provides you with the APIs as follows:
- Discovery the ONVIF network cameras
- Access some services supported by the ONVIF network cameras as follows:
- Device Management Service
- Media Service
- PTZ Service
Besides, the node-onvif provides you with simple APIs that allow you to control ONVIF network cameras easily even if you are not familiar with the ONVIF specifications.
Installation
$ npm install -s node-onvif
Sample Application
This package includes a sample application "ONVIF Network Camera Manager". You can try this module with your PTZ ONVIF network camera easily.
Table of Contents
- Quick Start
- Asynchronous methods
Onvif
objectOnvifDevice
object- Create an
OnvifDevice
object - Properties
- Methods
init([callback])
methodgetInformation()
methodgetCurrentProfile()
methodgetProfileList()
methodchangeProfile(index|token)
methodaddVideoSourceConfiguration(index|token)
methodaddVideoEncoderConfiguration(index|token)
methodgetUdpStreamUrl()
methodfetchSnapshot(callback)
methodptzMove(params[, callback])
methodptzStop([callback])
method
- Create an
- ONVIF commands
OnvifServiceDevice
objectgetCapabilities([callback])
methodgetWsdlUrl([callback])
methodgetDiscoveryMode([callback])
methodsetDiscoveryMode(mode,[callback])
methodgetScopes([callback])
methodsetScopes(params[, callback])
methodaddScopes(params[, callback])
methodremoveScopes(params[, callback])
methodgetHostname([callback])
methodsetHostname(params[, callback])
methodgetDNS([callback])
methodsetDNS(params[, callback])
methodgetNetworkInterfaces([callback])
methodgetNetworkProtocols([callback])
methodsetNetworkProtocols(params[, callback])
methodgetNetworkDefaultGateway([callback])
methodsetNetworkDefaultGateway(params[, callback])
methodgetDeviceInformation([callback])
methodgetSystemDateAndTime([callback])
methodreboot([callback])
methodgetUsers([callback])
methodcreateUsers(params[, callback])
methoddeleteUsers(params[, callback])
methodsetUser(params[, callback])
methodgetRelayOutputs([callback])
methodgetNTP([callback])
methodsetNTP(params[, callback])
methodgetDynamicDNS([callback])
methodgetZeroConfiguration([callback])
methodgetServices(params[, callback])
methodgetServiceCapabilities([callback])
method
OnvifServiceMedia
objectgetStreamUri(params[, callback])
methodgetVideoEncoderConfigurations([callback])
methodgetVideoEncoderConfiguration(params[, callback])
methodgetCompatibleVideoEncoderConfigurations(params[, callback])
methodgetVideoEncoderConfigurationOptions(params[, callback])
methodgetGuaranteedNumberOfVideoEncoderInstances(params[, callback])
methodgetProfiles([callback])
methodgetProfile(params[, callback])
methodcreateProfile(params[, callback])
methoddeleteProfile(params[, callback])
methodgetVideoSources([callback])
methodgetVideoSourceConfiguration(params[, callback])
methodgetVideoSourceConfigurations([callback])
methodgetCompatibleVideoSourceConfigurations(params[, callback])
methodgetVideoSourceConfigurationOptions(params[, callback])
methodgetMetadataConfiguration(params[, callback])
methodgetMetadataConfigurations([callback])
methodgetCompatibleMetadataConfigurations(params[, callback])
methodgetMetadataConfigurationOptions(params[, callback])
methodgetAudioSources([callback])
methodgetAudioSourceConfiguration(params[, callback])
methodgetAudioSourceConfigurations([callback])
methodgetCompatibleAudioSourceConfigurations(params[, callback])
methodgetAudioSourceConfigurationOptions(params[, callback])
methodgetAudioEncoderConfiguration(params[, callback])
methodgetAudioEncoderConfigurations([callback])
methodgetCompatibleAudioEncoderConfigurations(params[, callback])
methodgetAudioEncoderConfigurationOptions(params[, callback])
methodgetSnapshotUri(params[, callback])
method
OnvifServicePtz
objectgetNodes([callback])
methodgetNode(params[, callback])
methodgetConfigurations([callback])
methodgetConfiguration(params[, callback])
methodgetConfigurationOptions(params[, callback])
methodgetStatus(params[, callback])
methodcontinuousMove(params[, callback])
methodabsoluteMove(params[, callback])
methodrelativeMove(params[, callback])
methodstop(params[, callback])
methodgotoHomePosition(params[, callback])
methodsetHomePosition(params[, callback])
methodsetPreset(params[, callback])
methodgetPresets(params[, callback])
methodgotoPreset(params[, callback])
methodremovePreset(params[, callback])
method
OnvifServiceImaging
object- References
- Release Note
- License
Quick Start
This section shows how to discover ONVIF network cameras, how to get the device information, and how to control the PTZ of the device.
Discover ONVIF network cameras
This sample code shows how to discover ONVIF network cameras.
const onvif = require('node-onvif');
console.log('Start the discovery process.');
// Find the ONVIF network cameras.
// It will take about 3 seconds.
onvif.startProbe().then((device_info_list) => {
console.log(device_info_list.length + ' devices were found.');
// Show the device name and the URL of the end point.
device_info_list.forEach((info) => {
console.log('- ' + info.urn);
console.log(' - ' + info.name);
console.log(' - ' + info.xaddrs[0]);
});
}).catch((error) => {
console.error(error);
});
The code above will output the result like this:
Start the discovery process.
5 devices were found.
- urn:uuid:cd279d60-afd3-3a22-00dc-daaa234e772c
- Canon VB-S30D
- http://192.168.10.10:80/onvif/device_service
- urn:uuid:13814000-8752-1052-bfff-045d4b150782
- Sony
- http://192.168.10.14/onvif/device_service
- urn:uuid:4d454930-0000-1000-8000-bcc34217e292
- Panasonic BB-SC384B
- http://192.168.10.12/onvif/device_service
- urn:uuid:00030050-0000-1000-8000-104fa8e2cc96
- Sony
- http://192.168.10.25/onvif/device_service
- urn:uuid:8b10a2e0-3302-48df-9d1a-1197c360e6ca
- Avantgarde-Test
- http://192.168.10.27:36000/onvif/device_service
The most important information for controlling the device is the URL of the end point of the device. You can get the URL from the code info.xaddrs[0]
above.
Create an OnvifDevice
object
In order to control the ONVIF network camera, you have to create an OnfivDevice
object for the device, then initialize the object using the init()
method. This sample code shows how to create an OnvifDevice
object and get the detailed information of the device.
const onvif = require('node-onvif');
// Create an OnvifDevice object
let device = new onvif.OnvifDevice({
xaddr: 'http://192.168.10.10:80/onvif/device_service',
user : 'admin',
pass : '123456'
});
// Initialize the OnvifDevice object
device.init().then((info) => {
// Show the detailed information of the device.
console.log(JSON.stringify(info, null, ' '));
}).catch((error) => {
console.error(error);
});
The code above will output the result like this:
{
"Manufacturer": "Canon",
"Model": "VB-S30D",
"FirmwareVersion": "Ver. 1.3.3",
"SerialNumber": "999999999999",
"HardwareId": "1D"
}
Get the stream URL
This sample code shows how to get the UDP stream URL.
const onvif = require('node-onvif');
// Create an OnvifDevice object
let device = new onvif.OnvifDevice({
xaddr: 'http://192.168.10.14:10080/onvif/device_service',
user : 'admin',
pass : '123456'
});
// Initialize the OnvifDevice object
device.init().then(() => {
// Get the UDP stream URL
let url = device.getUdpStreamUrl();
console.log(url);
}).catch((error) => {
console.error(error);
});
The code above will output the result like this:
rtsp://192.168.10.14:10554/tcp/av0_0
Get the snapshot
This sample code shows how to get the data of the snapshot and save it to a file.
const onvif = require('node-onvif');
const fs = require('fs');
// Create an OnvifDevice object
let device = new onvif.OnvifDevice({
xaddr: 'http://192.168.10.14:10080/onvif/device_service',
user : 'admin',
pass : '123456'
});
// Initialize the OnvifDevice object
device.init().then(() => {
// Get the data of the snapshot
console.log('fetching the data of the snapshot...');
return device.fetchSnapshot();
}).then((res) => {
// Save the data to a file
fs.writeFileSync('snapshot.jpg', res.body, {encoding: 'binary'});
console.log('Done!');
}).catch((error) => {
console.error(error);
});
The code above will output the result like this:
fetching the data of the snapshot...
Done!
You will find a JPEG file named snapshot.jpg
in the current directory.
Control the PTZ
This sample code shows how to pan, tilt, and zoom the ONVIF network camera.
const onvif = require('node-onvif');
// Create an OnvifDevice object
let device = new onvif.OnvifDevice({
xaddr: 'http://192.168.10.14:10080/onvif/device_service',
user : 'admin',
pass : '123456'
});
// Initialize the OnvifDevice object
device.init().then(() => {
// Move the camera
return device.ptzMove({
'speed': {
x: 1.0, // Speed of pan (in the range of -1.0 to 1.0)
y: 0.0, // Speed of tilt (in the range of -1.0 to 1.0)
z: 0.0 // Speed of zoom (in the range of -1.0 to 1.0)
},
'timeout': 1 // seconds
});
}).then(() => {
console.log('Done!');
}).catch((error) => {
console.error(error);
});
If this code has been successfully finished, you could find that the camera turns to the right for a second at the highest speed.
Asynchronous methods
Asynchronous methods implemented in this module return a Promise
object. In the other hand, such methods support callback coding style as well.
device.fetchSnapshot().then((res) => {
// Do something
}).catch((error) => {
console.error(error);
});
device.fetchSnapshot((error, res) => {
if(error) {
console.error(error);
} else {
// Do something
}
});
Though the results of the codes above will be completely same, it is strongly recommended to use the Promise
style. The callback style will be deprecated in the future.
The callback style remains only for backward compatibility becase the versions earlier than v0.1.0 supported only the callback style.
Onvif object
Create an Onvif
object
In order to use the node-onvif module, you have to load the node-onvif module as follows:
const onvif = require('node-onvif');
The variable onvif
in the code above is the Onvif
object.
Methods
This section describes the methods implemented in the Onvif
object.
startProbe([callback])
This method starts the discovery process and tries to find the ONVIF network camera devices. This method returns a Promise
object if the callback
is not passed.
The discovery process will take about 3 seconds. Once the process finished, the resolve()
function will be called with an Array
object containing hash objects representing the found devices. The hash object contains the properties as follows:
Property | Type | Description
:----------|:-------|:-----------
urn
| String | The URN (Uniform Resource Name) assigned to the device (e.g., "urn:uuid:6b2be733-6ad1-4467-8bd0-747bd8efd206")
name
| String | The product name of the device (e.g., "Panasonic BB-SC384B").
hardware
| String | The description of the hardware of the device (e.g., "BB-SC384B").
location
| String | The physical location of the device (e.g., "China", "shenzhen", "office").
types
| Array | The list of types supported by the device (e.g., "dn:NetworkVideoTransmitter", "tds:Device"). Basically, this module is for "dn:NetworkVideoTransmitter".
xaddrs
| Array | The list of URLs of the end points (e.g., "http://192.168.10.17/onvif/device_service", "http://[2408:12:2e20:d000:bec3:42ff:fe17:e292]/onvif/device_service").
scopes
| Array | The list of scopes set to the device (e.g., "onvif://www.onvif.org/Profile/Streaming", "onvif://www.onvif.org/location/office").
The sample code below shows the structure of the hash object representing the found device.
const onvif = require('node-onvif');
// Find the ONVIF network cameras
onvif.startProbe().then((device_list) => {
// Show the information of the found devices
console.log(JSON.stringify(device_list, null, ' '));
}).catch((error) => {
console.error(error);
});
The code above will output the result like this:
[
{
"urn": "urn:uuid:4d454930-0000-1000-8000-bcc34217e292",
"name": "Panasonic BB-SC384B",
"hardware": "BB-SC384B",
"location": "office",
"types": [
"dn:NetworkVideoTransmitter",
"tds:Device"
],
"xaddrs": [
"http://192.168.10.12/onvif/device_service",
"http://[2408:12:2e20:d000:bec3:42ff:fe17:e292]/onvif/device_service"
],
"scopes": [
"onvif://www.onvif.org/Profile/Streaming",
"onvif://www.onvif.org/hardware/BB-SC384B",
"onvif://www.onvif.org/location/office",
"onvif://www.onvif.org/name/Panasonic_BB-SC384B",
""
]
},
{
"urn": "urn:uuid:cd279d60-afd3-3a22-00dc-daaa234e772c",
"name": "Canon VB-S30D",
"hardware": "VB-S30D",
"location": "Canon",
"types": [
"dn:NetworkVideoTransmitter",
"tds:Device"
],
"xaddrs": [
"http://192.168.10.10:80/onvif/device_service",
"http://169.254.240.48:80/onvif/device_service",
"http://[2408:12:2e20:d000:1a0c:acff:fee9:c231]:80/onvif/device_service",
"http://[fe80::1a0c:acff:fee9:c231]:80/onvif/device_service"
],
"scopes": [
"onvif://www.onvif.org/type/video_encoder",
"onvif://www.onvif.org/type/ptz",
"onvif://www.onvif.org/name/Canon_VB-S30D",
"onvif://www.onvif.org/hardware/VB-S30D",
"onvif://www.onvif.org/type/audio_encoder",
"onvif://www.onvif.org/type/video_analytics",
"onvif://www.onvif.org/type/Network_Video_Transmitter",
"onvif://www.onvif.org/Profile/Streaming",
"onvif://www.onvif.org/location/Canon"
]
}
]
stopProbe([callback])
This method aborts the discovery process asynchronously. This method returns a Promise
object if the callback
is not passed.
onvif.stopProbe().then(() => {
console.log('Aborted the discovery process.');
}).catch((error) => {
console.error(error);
});
If the discovery process has been finished when the stopProbe()
method is called, this method do nothing and the resolve()
function will be called.
In most cases, you do not have to call this method because the discovery process is automatically finished in 3 seconds after the startProbe()
method was called.
startDiscovery(callback) (deprecated)
This method is deprecated. Do not use this method now. It will be deleted in the future.
This method starts the discovery process and tries to find the ONVIF network camera devices. Whenever an ONVIF network camera device is found, the callback
function specified to the 1st argument will be called.
When a device is found, the callback
will be passed a hash object as the 1st argument. The properties set to the hash object are as follows:
Property | Type | Description
:----------|:-------|:-----------
urn
| String | The URN (Uniform Resource Name) assigned to the device (e.g., "urn:uuid:6b2be733-6ad1-4467-8bd0-747bd8efd206")
name
| String | The product name of the device (e.g., "Panasonic BB-SC384B").
hardware
| String | The description of the hardware of the device (e.g., "BB-SC384B").
location
| String | The physical location of the device (e.g., "China", "shenzhen", "office").
types
| Array | The list of types supported by the device (e.g., "dn:NetworkVideoTransmitter", "tds:Device"). Basically, this module is for "dn:NetworkVideoTransmitter".
xaddrs
| Array | The list of URLs of the end points (e.g., "http://192.168.10.17/onvif/device_service", "http://[2408:12:2e20:d000:bec3:42ff:fe17:e292]/onvif/device_service").
scopes
| Array | The list of scopes set to the device (e.g., "onvif://www.onvif.org/Profile/Streaming", "onvif://www.onvif.org/location/office").
The sample code below shows the structure of the hash object representing the found device.
const onvif = require('node-onvif');
// Find the ONVIF network cameras
onvif.startDiscovery((info) => {
// Show the information of the found device
console.log(JSON.stringify(info, null, ' '));
});
The code above will output the result like this:
{
"urn": "urn:uuid:4d454930-0000-1000-8000-bcc34217e292",
"name": "Panasonic BB-SC384B",
"hardware": "BB-SC384B",
"location": "office",
"types": [
"dn:NetworkVideoTransmitter",
"tds:Device"
],
"xaddrs": [
"http://192.168.10.17/onvif/device_service",
"http://[2408:12:2e20:d000:bec3:42ff:fe17:e292]/onvif/device_service"
],
"scopes": [
"onvif://www.onvif.org/Profile/Streaming",
"onvif://www.onvif.org/hardware/BB-SC384B",
"onvif://www.onvif.org/location/office",
"onvif://www.onvif.org/name/Panasonic_BB-SC384B",
""
]
}
stopDiscovery([callback]) (deprecated)
This method is deprecated. Do not use this method now. It will be deleted in the future.
This method stops the discovery process asynchronously. If you want to do something waiting for stopping the discovery process successfully, you can pass a callback function to this method as the 1st argument.
const onvif = require('node-onvif');
// Start the discovery process
onvif.startDiscovery((info) => {
// Do something
});
// Stop the discovery process in 3 seconds
setTimeout(() => {
onvif.stopDiscovery(() => {
// If you want to do something after stopping
// the discovery process successfully, write
// codes here.
});
}, 3000);
If you don't need to do anything after the discovery process has been terminated successfully, you can do this:
onvif.stopDiscovery();
OnvifDevice object
The OnvifDevice
object represents an ONVIF network camera device. You can control the ONVIF network camera through this object.
Create an OnvifDevice
object
In order to control an ONVIF network camera, you have to create an OnvifDevice
object from the OnvifDevice
constructor by yourself as follows:
const onvif = require('node-onvif');
// Create an OnvifDevice object
let device = new onvif.OnvifDevice({
xaddr: 'http://192.168.10.14:10080/onvif/device_service',
user : 'admin',
pass : '123456'
});
The variable device
represents an OnvifDevice
object in the code above. The OnvifDevice
constructor requires a hash object containing some properties as follows:
Property | Type | Required | Description
:----------|:-------|:---------|:-----------
xaddr
| String | required | URL of the end point of the targeted device.
user
| String | optional | User name for the user authentication.
pass
| String | optional | Password for the user authentication.
If you know the value of the xaddr
property (the URL of the end point of the targeted device) in advance, you don't need to run the discover process(i.e., you don't need to call the startDiscovery()
method).
Properties
The OnvifDevice
object provides some properties as follows:
Property | | Type | Description
:----------|:---------|:-------|:-----------
services
| | Object |
+- | device
| Object | OnvifServiceDevice
object
+- | media
| Object | OnvifServiceMedia
object
+- | imaging
| Object | OnvifServiceImaging
object
+- | ptz
| Object | OnvifServicePtz
object
These objects will be set when the initialization process is completed calling the init()
method. See the section "ONVIF commands" for details.
Methods
init([callback])
This method initializes the OnvifDevice
object. This method must be called before you control the targeted device. Actually, this method retrieves several information essential to control the device. The process of this method takes a little time to be completed because this method sends several commands to the targeted device and waits for the all relevant responses. Note that you have to wait for the completion of this method to control the device.
This method returns a Promise
object if the callback
is not passed. If the initialization process is completed, the resolve()
function will be called with a hash obect containing the properties as follows:
Property | Type | Description
:-----------------|:-------|:-----------
Manufacturer
| String | The manufactor of the device.
Model
| String | The device model.
FirmwareVersion
| String | The firmware version in the device.
SerialNumber
| String | The serial number of the device.
HardwareId
| String | The hardware ID of the device.
const onvif = require('node-onvif');
// Create an OnvifDevice object
let device = new onvif.OnvifDevice({
xaddr: 'http://192.168.10.14:10080/onvif/device_service',
user : 'admin',
pass : '888888'
});
// Initialize the OnvifDevice object
device.init().then((info) => {
console.log('The OnvifDevice object has been initialized successfully.');
console.log(JSON.stringify(info, null, ' '));
}).catch((error) => {
console.log('[ERROR] ' + error.message);
});
The code above will output the result as follow:
{
"Manufacturer": "Canon",
"Model": "VB-S30D",
"FirmwareVersion": "Ver. 1.3.3",
"SerialNumber": "999999999999",
"HardwareId": "1D"
}
getInformation()
This method returns a hash object consisting of several device information as follow:
Property | Type | Description
:-----------------|:-------|:-----------
Manufacturer
| String | The manufactor of the device.
Model
| String | The device model.
FirmwareVersion
| String | The firmware version in the device.
SerialNumber
| String | The serial number of the device.
HardwareId
| String | The hardware ID of the device.
This object is as same as the object obtained by the init()
method. Actually, the information has been already retreaved when the initialization process was completed (the init()
method was called) and stored in the OnvifDevice
object. The getInformation()
method just returns the stored information.
let info = device.getInformation();
console.log(JSON.stringify(info, null, ' '));
The code above will output the result like this:
{
"Manufacturer": "Vstarcam",
"Model": "Hi3518eV100",
"FirmwareVersion": "2.4",
"SerialNumber": "3056894",
"HardwareId": "1.0"
}
getCurrentProfile()
The ONVIF network cameras have several profiles by default. The profile is a set of configuration values such as the resolution of the video encoder, the URL of the snapshot, the URL of the video stream, the range of PTZ, and so on.
The OnvifDevice
object is sure to select one of them and each method implemented in the OnvifDevice
object is executed using the selected profile. By default, the OnvifDevice
object selects the profile found first in the initialization process.
This method returns a hash object containing the information of the profile currently selected by the OnvifDevice
object.
let profile = device.getCurrentProfile();
console.log(JSON.stringify(profile, null, ' '));
The code above will output the result like this:
{
"token": "PROFILE_000",
"name": "PROFILE_000",
"snapshot": "http://192.168.10.14:81/snapshot.cgi",
"stream": {
"udp": "rtsp://192.168.10.14:10554/tcp/av0_0",
"http": "rtsp://192.168.10.14:10554/tcp/av0_0",
"rtsp": "rtsp://192.168.10.14:10554/tcp/av0_0"
},
"video": {
"source": {
"token": "V_SRC_000",
"name": "V_SRC_000",
"bounds": {
"width": 1280,
"height": 720,
"x": 0,
"y": 0
}
},
"encoder": {
"token": "V_ENC_000",
"name": "V_ENC_000",
"resolution": {
"width": 1280,
"height": 720
},
"quality": 4,
"framerate": 25,
"bitrate": 2048,
"encoding": "H264"
}
},
"audio": {
"source": {
"token": "A_SRC_000",
"name": "A_SRC_000"
},
"encoder": {
"token": "A_ENC_000",
"name": "A_ENC_000",
"bitrate": 64,
"samplerate": 8,
"encoding": "G711"
}
},
"ptz": {
"range": {
"x": {
"min": -1,
"max": 1
},
"y": {
"min": -1,
"max": 1
},
"z": {
"min": 0,
"max": 1
}
}
}
}
getProfileList()
This method returns a list of the profiles set to the device as an Array object. Each element in the Array object is a hash object whose structure is as same as the hash object which can be retrieved by the getCurrentProfile()
method.
See the section "changeProfile()
method" for details.
changeProfile(index|token)
This method changes the current profile to the profile corresponding to the index
specified as the 1st argument, then returns a hash object representing the newly selected profile. The index
is the position in the profile list which can be obtained through the getProfileList()
method, which is in the range of 0 to the length of the list minus 1.
You can pass the profile token instead of the index
. If a Number
value is passed, this method assumes the a index
is passed. If a String
value is passed, this method assumes that a token
is passed.
The sample code below shows how to change the current profile to the profile whose video resolution is the smallest:
// Get the current profile
let profile = device.getCurrentProfile();
// Show the video resolution of the current profile
let reso = profile['video']['encoder']['resolution'];
console.log('- Before: ' + reso['width'] + ' x ' + reso['height']);
// Get a list of the profiles set in the device
let profile_list = device.getProfileList();
// Find the profile whose video resolution is the smallest
let min_square = 4000 * 2000;
let min_index = 0;
for(let i=0; i<profile_list.length; i++) {
let resolution = profile_list[i]['video']['encoder']['resolution'];
let square = resolution['width'] * resolution['height'];
if(square < min_square) {
min_square = square;
min_index = i;
}
}
// Change the current profile
profile = device.changeProfile(min_index);
// Show the video resolution
reso = profile['video']['encoder']['resolution'];
console.log('- After: ' + reso['width'] + ' x ' + reso['height']);
This sample code will output the result like this:
- Before: 1280 x 720
- After: 320 x 180
addVideoSourceConfiguration(index|token)
TBD
addVideoEncoderConfiguration(index|token)
TBD
getUdpStreamUrl()
This method returns the UDP Stream URL. Though the URL can be obtained from the result of the getCurrentProfile()
method as well, this method makes that easy.
let url = device.getUdpStreamUrl();
console.log(url);
The code above will output the result like this:
rtsp://192.168.10.14:10554/tcp/av0_0
fetchSnapshot([callback])
This method fetches a snapshot captured by the camera at the time. The snapshot is obtained as a Buffer
object representing the image data of the snapshot. This method returns a Promise
object if the callback
is not passed.
If the snapshot is captured successfully, a hash object is passed to the resolve()
function. The hash object consists of some properties as follows:
Property | Type | Description
:---------|:-------|:-----------
headers
| Object | headers
object representing the HTTP response header. This object is of the http
module of Node.js.
body
| Object | Buffer
object representing the image data of the snapshot.
The code blow shows how to get the snapshot and save it as an image file:
device.fetchSnapshot().then((res) => {
// Determine the file extention
let ext = 'bin';
let mime_pair = res.headers['content-type'].split('/');
if(mime_pair[0] === 'image') {
ext = mime_pair[1];
}
// Save the data to a file
let fname = 'snapshot.' + ext;
fs.writeFileSync(fname, res.body, {encoding: 'binary'});
console.log('Done!');
}).catch((error) => {
console.error(error);
});
ptzMove(params[, callback])
This method pans, tilts, zooms the camera if the ONVIF network camera supports the PTZ service. This method returns a Promise
object if the callback
is not passed.
This method takes a hash object as the 1st argument. The structure of the hash object is as follows:
Property | | Type | Required |Description
:---------|:----|:--------|:---------|:----------
speed
| | Object | required |
+- | x
| Float | required | Speed of pan in the range of -1.0 to 1.0.
+- | y
| Float | required | Speed of tilt in the range of -1.0 to 1.0.
+- | z
| Float | required | Speed of zoom in the range of -1.0 to 1.0.
timeout
| | Integer | optional | Timeout in seconds (Default: 1)
The speed.x
represents the speed of horizontal movement of the camera. If the value of the speed.x
is positive, the camera will turn to the right. If the value is negative, the camera will turn to the left. If the value is zero, the camera won't move in a horizontal direction.
The speed.y
represents the speed of vertical movement of the camera. If the value of the speed.y
is positive, the camera will turn to the top. If the value is negative, the camera will turn to the bottom. If the value is zero, the camera won't move in a vertical direction.
The speed.z
represents the speed of the zoom of the camera. If the value of the speed.z
is positive, the camera will zoom in. If the value is negative, the camera will zoom out. if the value is zero, the camera won't zoom.
The code below will make the camera turn to the left at the highest speed for 1 second.
let params = {
'speed': {
x: 1.0, // Speed of pan (in the range of -1.0 to 1.0)
y: 0.0, // Speed of tilt (in the range of -1.0 to 1.0)
z: 0.0 // Speed of zoom (in the range of -1.0 to 1.0)
},
'timeout': 1 // seconds
};
// Move the camera
device.ptzMove(params).then(() => {
console.log('Done!');
}).catch((error) => {
console.error(error);
});
ptzStop([callback])
This method stops the movement of the camera caused by the ptzMove()
method. This method returns a Promise
object if the callback
is not passed.
// Create the parameters
let params = {
'speed': {x: 0.5, y: 0.0, z: 0.0},
'timeout': 60 // seconds
};
// Supposed to move the camera for 60 seconds
device.ptzMove(params).then(() => {
console.log('Succeeded to move.');
// Stop to the PTZ in 2 seconds
setTimeout(() => {
device.ptzStop().then(() => {
console.log('Succeeded to stop.');
}).catch((error) => {
console.error(error);
});
}, 2000);
}).catch((error) => {
console.error(error);
});
ONVIF commands
Note that the all sections below are for those who are familiar with the ONVIF specifications.
The ONVIF specifications define a lot of SOAP-based commands. This module implements part of the commands. Actually, most of the methods described in the previous sections are implemented using the methods representing the commands described the sections below.
The methods for the ONVIF commands are exposed in the OnvifServiceDevice
object, the OnvifServiceMedia
object, and OnvifServicePtz
object, which are available from the OnvifDevice.device
property, the OnvifDevice.media
property, and the OnvifDevice.ptz
property, respectively.
For example, if you want to call the GotoHomePosition
command, you can use the gotoHomePosition
method implemented in the OnvifServicePtz
object like this:
// Create a OnvifDevice object
let device = new onvif.OnvifDevice({
xaddr: 'http://192.168.10.14:10080/onvif/device_service',
user : 'admin',
pass : '123456'
});
// Initialize the OnvifDevice object
device.init().then(() => {
// The OnvifServicePtz object
let ptz = device.services.ptz;
if(!ptz) {
throw new Error('Your ONVIF network camera does not support the PTZ service.');
}
// The parameters for the gotoHomePosition() method
let profile = device.getCurrentProfile();
let params = {
'ProfileToken': profile['token'],
'Speed' : 1
};
// Send the GotoHomePosition command using the gotoHomePosition() method
return ptz.gotoHomePosition(params);
}).then((result) => {
console.log(JSON.stringify(result.data, null, ' '));
}).catch((error) => {
console.error(error);
});
The code above will output the result like this:
{
"GotoHomePositionResponse": {
"$": {
"xmlns": "http://www.onvif.org/ver20/ptz/wsdl"
}
}
}
Actually, the response from the targeted ONVIF network camera is SOAP. This module provides some representations of the response. the variable result
in the code above consists of some properties as follows:
Property | Type | Description
:-----------|:-------|:-----------
soap
| String | Raw SOAP response
formatted
| String | Formatted SOAP response in order to be human readable
converted
| Object | JavaScript object converted from SOAP response by xml2js
module
data
| Object | JavaScript object converted from the data in the <Body>
element in the SOAP response
In most cases, only data
property would be enough. If you need to evaluate the response in more detail, you can use the preferable property other than the data
property.
The value of the soap
property would be:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:enc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:rpc="http://www.w3.org/2003/05/soap-rpc" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" xmlns:tt="http://www.onvif.org/ver10/schema"><env:Body><GotoHomePositionResponse xmlns="http://www.onvif.org/ver20/ptz/wsdl"></GotoHomePositionResponse></env:Body></env:Envelope>
The value of the formatted
property would be:
<?xml version="1.0" encoding="UTF-8" ?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:enc="http://www.w3.org/2003/05/soap-encoding"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:rpc="http://www.w3.org/2003/05/soap-rpc" xmlns:xop="http://www.w3.org/2004/08/xop/include"
xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" xmlns:tt="http://www.onvif.org/ver10/schema">
<env:Body>
<GotoHomePositionResponse xmlns="http://www.onvif.org/ver20/ptz/wsdl"></GotoHomePositionResponse>
</env:Body>
</env:Envelope>
The value of the converted
property would be:
{
"$": {
"xmlns:env": "http://www.w3.org/2003/05/soap-envelope",
"xmlns:enc": "http://www.w3.org/2003/05/soap-encoding",
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"xmlns:xsd": "http://www.w3.org/2001/XMLSchema",
"xmlns:rpc": "http://www.w3.org/2003/05/soap-rpc",
"xmlns:xop": "http://www.w3.org/2004/08/xop/include",
"xmlns:tptz": "http://www.onvif.org/ver20/ptz/wsdl",
"xmlns:tt": "http://www.onvif.org/ver10/schema"
},
"Body": {
"GotoHomePositionResponse": {
"$": {
"xmlns": "http://www.onvif.org/ver20/ptz/wsdl"
}
}
}
}
All methods representing the ONVIF commands return the same structured object as one described above. So in the description for each methods described in the sections below, only parameters to be passed to the method are listed.
Note that the first character of the method name implemented in this module is lower case though the corresponding letter of the ONVIF command name is upper case. For example, the ContinuousMove
command specified in the ONVIF specification corresponds to the continuousMove
method implemented in the OnvifServicePtz
object.
OnvifServiceDevice
object
This object represents the ONVIF Device Management Service.
getCapabilities([callback]) method
This method sends a GetCapabilities
command.
getWsdlUrl([callback]) method
This method sends a GetWsdlUrl
command.
getDiscoveryMode([callback]) method
This method sends a GetDiscoveryMode
command.
setDiscoveryMode([callback]) method
This method sends a setDiscoveryMode
command. The 1st argument mode
MUST be either 'Discoverable' or 'NonDiscoverable'
getScopes([callback]) method
This method sends a GetScopes
command.
setScopes(params[, callback]) method
This method sends a SetScopes
command. The 1st argument params
must be a hash object consisting of the properties as follows:
Property | Type | Required |Description
:---------|:--------|:---------|:----------
Scopes
| Array | required | a list of URI
The code below shows how to set some scopes:
let params = {
'Scopes': [
'onvif://www.onvif.org/location/town/Nerima',
'onvif://www.onvif.org/location/city/Tokyo'
]
};
device.services.device.setScopes(params).then((result) => {
console.log(JSON.stringify(result['data'], null, ' '));
}).catch((error) => {
console.error(error);
});
If you want to delete all configurable scopes, specify an empty Array
object as the Scope
property:
let params = {'Scopes': []}
addScopes(params[, callback]) method
This method sends a AddScopes
command. The 1st argument params
must be a hash object consisting of the properties as follows:
Property | Type | Required |Description
:---------|:--------|:---------|:----------
Scopes
| Array | required | a list of URI
The code below shows how to set some scopes:
let params = {
'Scopes': [
'onvif://www.onvif.org/location/town/Nerima',
'onvif://www.onvif.org/location/city/Tokyo'
]
};
device.services.device.addScopes(params).then((result) => {
console.log(JSON.stringify(result['data'], null, ' '));
}).catch((error) => {
console.error(error);
});
removeScopes(params[, callback]) method
This method sends a RemoveScopes
command. The 1st argument params
must be a hash object consisting of the properties as follows:
Property | Type | Required |Description
:---------|:--------|:---------|:----------
Scopes
| Array | required | a list of URI
The code below shows how to set some scopes:
let params = {
'Scopes': [
'onvif://www.onvif.org/location/city/Tokyo',
'onvif://www.onvif.org/location/town/Nerima'
]
};
device.services.device.removeScopes(params).then((result) => {
console.log(JSON.stringify(result['data'], null, ' '));
}).catch((error) => {
console.error(error);
});
getHostname([callback]) method
This method sends a GetHostname
command.
setHostname(params[, callback]) method
This method sends a SetHostname
command. The 1st argument params
must be a hash object consisting of the properties as follows:
Property | Type | Required |Description
:---------|:--------|:---------|:----------
Name
| String | required | a host name
The code below shows how to set some scopes:
let params = {
'Name': 'cam001'
};
device.services.device.setHostname(params).then((result) => {
console.log(JSON.stringify(result['data'], null, ' '));
}).catch((error) => {
console.error(error);
});
getDNS([callback]) method
This method sends a GetDNS
command.
setDNS(params[, callback]) method
This method sends a SetDNS
command. The 1st argument params
must be a hash object consisting of the properties as follows:
Property | | Type | Required |Description
:--------------|:--------------|:--------|:---------|:----------
FromDHCP
| | boolean | required | true or false
SearchDomain
| | Array | optional | a list of search domains
DNSManual
| | Array | optional | a list of DNS addresses
+- | Type
| String | required | "IPv4" or "IPv6"
+- | IPv4Address
| String | optional | IPv4 address
+- | IPv6Address
| String | optional | IPv6 address
let params = {
'FromDHCP' : false,
'SearchDomain': ['futomi.gr.jp', 'hatano.gr.jp'],
'DNSManual' : [
{'Type': 'IPv4', 'IPv4Address': '192.168.10.1'},
{'Type': 'IPv4', 'IPv4Address': '192.168.10.3'}
]
};
return device.services.device.setDNS(params).then((result) => {
console.log(JSON.stringify(result['data'], null, ' '));
}).catch((error) => {
console.error(error);
});
getNetworkInterfaces([callback]) method
This method sends a GetNetworkProtocols
command.
setNetworkInterfaces(params[,callback]) method
This method sends a GetNetworkProtocols
command.
getNetworkProtocols([callback]) method
This method sends a GetNetworkProtocols
command.
setNetworkProtocols(params[, callback]) method
This method sends a SetNetworkProtocols
command. The 1st argument params
must be a hash object consisting of the properties as follows:
Property | | Type | Required |Description
:------------------|:----------|:--------|:---------|:----------
NetworkProtocols
| | Array | required |
+- | Name
| String | required |
+- | Enabled
| Boolean | optional |
+- | Port
| Integer | optional |
let params = {
'NetworkProtocols': [
{'Name': 'HTTP', 'Enabled': true, 'Port': 80},
{'Name': 'RTSP', 'Enabled': true, 'Port': 554},
]
};
device.services.device.setNetworkProtocols(params).then((result) => {
console.log(JSON.stringify(result['data'], null, ' '));
}).catch((error) => {
console.error(error);
});
getNetworkDefaultGateway([callback]) method
This method sends a GetNetworkDefaultGateway
command.
setNetworkDefaultGateway(params[, callback]) method
This method sends a SetNetworkDefaultGateway
command. The 1st argument params
must be a hash object consisting of the properties as follows:
Property | Type | Required |Description
:----------------|:--------|:---------|:----------
NetworkGateway
| Array | required | a list of IP addresses of gateways
let params = {
'NetworkGateway': [
{'IPv4Address': '192.168.10.1'}
]
};
device.services.device.setNetworkDefaultGateway(params).then((result) => {
console.log(JSON.stringify(result['data'], null, ' '));
}).catch((error) => {
console.error(error);
});
getDeviceInformation([callback]) method
This method sends a GetDeviceInformation
command.
getSystemDateAndTime([callback]) method
This method sends a GetSystemDateAndTime
command.
reboot([callback]) method
This method sends a Reboot
command.
getUsers([callback]) method
This method sends a GetUsers
command.
createUsers(params[, callback]) method
This method sends a CreateUsers
command. The 1st argument params
must be a hash object consisting of the properties as follows:
Property | | Type | Required |Description
:--------|:------------|:--------|:---------|:----------
User
| | Array | required | a list of users
+- | Username
| String | required | Username
+- | Password
| String | required | Password
+- | UserLevel
| String | required | Either "Administrator", "Operator", "User", or "Anonymous"
let params = {
'User' : [
{'Username': 'test1', 'Password' : 'password', 'UserLevel': 'Administrator'},
{'Username': 'test2', 'Password' : 'password', 'UserLevel': 'Operator'},
{'Username': 'test3', 'Password' : 'password', 'UserLevel': 'User'}
]
};
device.services.device.createUsers(params).then((result) => {
console.log(JSON.stringify(result['data'], null, ' '));
}).catch((error) => {
console.error(error);
});
deleteUsers(params[, callback]) method
This method sends a DeleteUsers
command. The 1st argument params
must be a hash object consisting of the properties as follows:
Property | | Type | Required |Description
:--------|:------------|:--------|:---------|:----------
User
| | Array | required | a list of users
+- | Username
| String | required | Username
let params = {
'User' : [
{'Username': 'test1'},
{'Username': 'test2'},
{'Username': 'test3'}
]
};
device.services.device.deleteUsers(params).then((result) => {
console.log(JSON.stringify(result['data'], null, ' '));
}).catch((error) => {
console.error(error);
});
setUser(params[, callback]) method
This method sends a SetUser
command. The 1st argument params
must be a hash object consisting of the properties as follows:
Property | | Type | Required |Description
:--------|:------------|:--------|:---------|:----------
User
| | Array | required | a list of users
+- | Username
| String | required | Username
+- | Password
| String | required | Password
+- | UserLevel
| String | required | Either "Administrator", "Operator", "User", or "Anonymous"
let params = {
'User' : [
{'Username': 'test1', 'Password' : 'password', 'UserLevel': 'Administrator'},
{'Username': 'test2', 'Password' : 'password', 'UserLevel': 'Operator'},
{'Username': 'test3', 'Password' : 'password', 'UserLevel': 'User'}
]
};
device.services.device.setUser(params).then((result) => {
console.log(JSON.stringify(result['data'], null, ' '));
}).catch((error) => {
console.error(error);
});
getRelayOutputs([callback]) method
This method sends a RetRelayOutputs
command.
getNTP([callback]) method
This method sends a GetNTP
command.
setNTP(params[, callback]) method
This method sends a SetNTP
command. The 1st argument params
must be a hash object consisting of the properties as follows:
Property | | Type | Required |Description
:-----------|:--------------|:--------|:---------|:----------
FromDHCP
| | Boolean | required | true or false
NTPManual
| | Object | optional |
+- | Type
| String | required | "IPv4" or "IPv6"
+- | IPv4Address
| String | optional | IPv4 address
+- | IPv6Address
| String | optional | IPv6 address
let params = {
'FromDHCP': false,
'NTPManual': {'Type': "IPv4", 'IPv4Address': '192.168.10.1'}
};
device.services.device.setNTP(params).then((result) => {
console.log(JSON.stringify(result['data'], null, ' '));
}).catch((error) => {
console.error(error);
});
getDynamicDNS([callback]) method
This method sends a GetDynamicDNS
command.
getZeroConfiguration([callback]) method
This method sends a GetZeroConfiguration
command.
getServices(params[, callback]) method
This method sends a GetServices
command. The 1st argument params
must be a hash object consisting of the properties as follows:
Property | Type | Required |Description
:-------------------|:--------|:---------|:----------
IncludeCapability
| Boolean | required | true or false
let params = {
'IncludeCapability': true
};
device.services.device.getServices(params).then((result) => {
console.log(JSON.stringify(result['data'], null, ' '));
}).catch((error) => {
console.error(error);
});
getServiceCapabilities([callback]) method
This method sends a GetServiceCapabilities
command.
OnvifServiceMedia
object
This object represents the ONVIF Media Service.
getStreamUri(params[, callback]) method
This method sends a GetStreamUri
command. The 1st argument params
must be a hash object consisting of the properties as follows:
Property | Type | Required |Description
:--------------|:--------|:---------|:----------
ProfileToken
| String | required | a token of the profile
Protocol
| String | required | "UDP", "HTTP", or "RTSP"
let params = {
'ProfileToken': '2_def_profile6',
'Protocol': 'UDP',
};
device.services.media.getStreamUri(params).then((result) => {
console.log(JSON.stringify(result['data'], null, ' '));
}).catch((error) => {
console.error(error);
});
getVideoEncoderConfigurations([callback]) method
This method sends a GetVideoEncoderConfigurations
command.
getVideoEncoderConfiguration(params[, callback]) method
This method sends a GetVideoEncoderConfiguration
command. The 1st argument params
must be a hash object consisting of the properties as follows:
Property | Type | Required |Description
:--------------------|:--------|:---------|:----------
ConfigurationToken
| String | required | a token of the configurationToken
let params = {
'ConfigurationToken': '2_def_conf6'
};
device.services.media.getVideoEncoderConfiguration(params).then((result) => {
console.log(JSON.stringify(result['data'], null, ' '));
}).catch((error) => {
console.error(error);
});
getCompatibleVideoEncoderConfigurations(params[, callback]) method
This method sends a GetCompatibleVideoEncoderConfigurations
command. The 1st argument params
must be a hash object consisting of the properties as follows:
Property | Type | Required |Description
:--------------|:--------|:---------|:----------
ProfileToken
| String | required | a token of the profile
let params = {
'ProfileToken': '2_def_profile6'
};
device.services.media.getCompatibleVideoEncoderConfigurations(params).then((result) => {
console.log(JSON.stringify(result['data'], null, ' '));
}).catch((error) => {
console.error(error);
});
getVideoEncoderConfigurationOptions(params[, callback]) method
This method sends a GetVideoEncoderConfigurationOptions
command. The 1st argument params
must be a hash object consisting of the properties as follows:
Property | Type | Required |Description
:--------------------|:--------|:---------|:----------
ProfileToken
| String | optional | a token of the profile
ConfigurationToken
| String | optional | a token of the configuration
let params = {
'ProfileToken': '2_def_profile6',
'ConfigurationToken': '2_def_conf6'
};
device.services.media.getVideoEncoderConfigurationOptions(params).then((result) => {
console.log(JSON.stringify(result['data'], null, ' '));
}).catch((error) => {
console.error(error);
});
getGuaranteedNumberOfVideoEncoderInstances(params[, callback]) method
This method sends a GetGuaranteedNumberOfVideoEncoderInstances
command. The 1st argument params
must be a hash object consisting of the properties as follows:
Property | Type | Required |Description
:--------------------|:--------|:---------|:----------
ConfigurationToken
| String | required | a token of the configuration
let params = {
'ConfigurationToken': '2_def_conf6',
};
device.services.media.getGuaranteedNumberOfVideoEncoderInstances(params).then((result) => {
console.log(JSON.stringify(result['data'], null, ' '));
}).catch((error) => {
console.error(error);
});
getProfiles([callback]) method
This method sends a GetProfiles
command.
getProfile(params[, callback]) method
This method sends a GetProfile
command. The 1st argument params
must be a hash object consisting of the properties as follows:
Property | Type | Required |Description
:--------------------|:--------|:---------|:----------
ProfileToken
| String | required | a token of the profile
let params = {
'ProfileToken': '2_def_profile6'
};
device.services.media.getProfile(params).then((result) => {
console.log(JSON.stringify(result['data'], null, ' '));
}).catch((error) => {
console.error(error);
});
createProfile(params[, callback]) method
This method sends a CreateProfile
command. The 1st argument params
must be a hash object consisting of the properties as follows:
Property | Type | Required |Description
:--------|:--------|:---------|:----------
Name
| String | required | a name of the profile
Token
| String | optional | a token of the profile
let params = {
'Name': 'TestProfile1',
'Token': 'TestProfile1'
};
device.services.media.createProfile(params).the