Latest commit

History

55 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

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
    • Search Service
    • Replay 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.

ONVIF Network Camera Manager


Table of Contents


This section shows how to discover ONVIF network cameras, how to get the device information, and how to control the PTZ of the device.

This sample code shows how to discover ONVIF network cameras.

constonvif=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.

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.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.10:80/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.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"
}

This sample code shows how to get the UDP stream URL.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Get the UDP stream URLleturl=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

This sample code shows how to get the data of the snapshot and save it to a file.

constonvif=require('node-onvif');constfs=require('fs');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Get the data of the snapshotconsole.log('fetching the data of the snapshot...');returndevice.fetchSnapshot();}).then((res)=>{// Save the data to a filefs.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.

This sample code shows how to pan, tilt, and zoom the ONVIF network camera.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Move the camerareturndevice.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 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.


In order to use the node-onvif module, you have to load the node-onvif module as follows:

constonvif=require('node-onvif');

The variable onvif in the code above is the Onvif object.

This section describes the methods implemented in the Onvif object.

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:

PropertyTypeDescription
urnStringThe URN (Uniform Resource Name) assigned to the device (e.g., "urn:uuid:6b2be733-6ad1-4467-8bd0-747bd8efd206")
nameStringThe product name of the device (e.g., "Panasonic BB-SC384B").
hardwareStringThe description of the hardware of the device (e.g., "BB-SC384B").
locationStringThe physical location of the device (e.g., "China", "shenzhen", "office").
typesArrayThe list of types supported by the device (e.g., "dn:NetworkVideoTransmitter", "tds:Device"). Basically, this module is for "dn:NetworkVideoTransmitter".
xaddrsArrayThe 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").
scopesArrayThe 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.

constonvif=require('node-onvif');// Find the ONVIF network camerasonvif.startProbe().then((device_list)=>{// Show the information of the found devicesconsole.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"]}]

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.

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:

PropertyTypeDescription
urnStringThe URN (Uniform Resource Name) assigned to the device (e.g., "urn:uuid:6b2be733-6ad1-4467-8bd0-747bd8efd206")
nameStringThe product name of the device (e.g., "Panasonic BB-SC384B").
hardwareStringThe description of the hardware of the device (e.g., "BB-SC384B").
locationStringThe physical location of the device (e.g., "China", "shenzhen", "office").
typesArrayThe list of types supported by the device (e.g., "dn:NetworkVideoTransmitter", "tds:Device"). Basically, this module is for "dn:NetworkVideoTransmitter".
xaddrsArrayThe 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").
scopesArrayThe 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.

constonvif=require('node-onvif');// Find the ONVIF network camerasonvif.startDiscovery((info)=>{// Show the information of the found deviceconsole.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",""]}

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.

constonvif=require('node-onvif');// Start the discovery processonvif.startDiscovery((info)=>{// Do something});// Stop the discovery process in 3 secondssetTimeout(()=>{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();

The OnvifDevice object represents an ONVIF network camera device. You can control the ONVIF network camera through this object.

In order to control an ONVIF network camera, you have to create an OnvifDevice object from the OnvifDevice constructor by yourself as follows:

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.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:

PropertyTypeRequiredDescription
xaddrStringrequiredURL of the end point of the targeted device.
userStringoptionalUser name for the user authentication.
passStringoptionalPassword 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).

The OnvifDevice object provides some properties as follows:

PropertyTypeDescription
servicesObject
+-deviceObjectOnvifServiceDevice object
+-mediaObjectOnvifServiceMedia object
+-ptzObjectOnvifServicePtz object
+-searchObjectOnvifServiceSearch object
+-replayObjectOnvifServiceReplay object

These objects will be set when the initialization process is completed calling the init() method. See the section "ONVIF commands" for details.

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:

PropertyTypeDescription
ManufacturerStringThe manufactor of the device.
ModelStringThe device model.
FirmwareVersionStringThe firmware version in the device.
SerialNumberStringThe serial number of the device.
HardwareIdStringThe hardware ID of the device.
constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '888888'});// Initialize the OnvifDevice objectdevice.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"}

This method returns a hash object consisting of several device information as follow:

PropertyTypeDescription
ManufacturerStringThe manufactor of the device.
ModelStringThe device model.
FirmwareVersionStringThe firmware version in the device.
SerialNumberStringThe serial number of the device.
HardwareIdStringThe 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.

letinfo=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"}

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.

letprofile=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}}}}

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.

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 profileletprofile=device.getCurrentProfile();// Show the video resolution of the current profileletreso=profile['video']['encoder']['resolution'];console.log('- Before: '+reso['width']+' x '+reso['height']);// Get a list of the profiles set in the deviceletprofile_list=device.getProfileList();// Find the profile whose video resolution is the smallestletmin_square=4000*2000;letmin_index=0;for(leti=0;i<profile_list.length;i++){letresolution=profile_list[i]['video']['encoder']['resolution'];letsquare=resolution['width']*resolution['height'];if(square<min_square){min_square=square;min_index=i;}}// Change the current profileprofile=device.changeProfile(min_index);// Show the video resolutionreso=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

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.

leturl=device.getUdpStreamUrl();console.log(url);

The code above will output the result like this:

rtsp://192.168.10.14:10554/tcp/av0_0

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:

PropertyTypeDescription
headersObjectheaders object representing the HTTP response header. This object is of the http module of Node.js.
bodyObjectBuffer 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 extentionletext='bin';letmime_pair=res.headers['content-type'].split('/');if(mime_pair[0]==='image'){ext=mime_pair[1];}// Save the data to a fileletfname='snapshot.'+ext;fs.writeFileSync(fname,res.body,{encoding: 'binary'});console.log('Done!');}).catch((error)=>{console.error(error);});

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:

PropertyTypeRequiredDescription
speedObjectrequired
+-xFloatrequiredSpeed of pan in the range of -1.0 to 1.0.
+-yFloatrequiredSpeed of tilt in the range of -1.0 to 1.0.
+-zFloatrequiredSpeed of zoom in the range of -1.0 to 1.0.
timeoutIntegeroptionalTimeout 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.

letparams={'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 cameradevice.ptzMove(params).then(()=>{console.log('Done!');}).catch((error)=>{console.error(error);});

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 parametersletparams={'speed': {x: 0.5,y: 0.0,z: 0.0},'timeout': 60// seconds};// Supposed to move the camera for 60 secondsdevice.ptzMove(params).then(()=>{console.log('Succeeded to move.');// Stop to the PTZ in 2 secondssetTimeout(()=>{device.ptzStop().then(()=>{console.log('Succeeded to stop.');}).catch((error)=>{console.error(error);});},2000);}).catch((error)=>{console.error(error);});

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 objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// The OnvifServicePtz objectletptz=device.services.ptz;if(!ptz){thrownewError('Your ONVIF network camera does not support the PTZ service.');}// The parameters for the gotoHomePosition() methodletprofile=device.getCurrentProfile();letparams={'ProfileToken': profile['token'],'Speed' : 1};// Send the GotoHomePosition command using the gotoHomePosition() methodreturnptz.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:

PropertyTypeDescription
soapStringRaw SOAP response
formattedStringFormatted SOAP response in order to be human readable
convertedObjectJavaScript object converted from SOAP response by xml2js module
dataObjectJavaScript 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:Envelopexmlns: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><GotoHomePositionResponsexmlns="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:Envelopexmlns: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>
<GotoHomePositionResponsexmlns="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.


This object represents the ONVIF Device Management Service.

This method sends a GetCapabilities command.

This method sends a GetWsdlUrl command.

This method sends a GetDiscoveryMode command.

This method sends a GetScopes command.

This method sends a SetScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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:

letparams={'Scopes': []}

This method sends a AddScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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);});

This method sends a RemoveScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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);});

This method sends a GetHostname command.

This method sends a SetHostname command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NameStringrequireda host name

The code below shows how to set some scopes:

letparams={'Name': 'cam001'};device.services.device.setHostname(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetDNS command.

This method sends a SetDNS command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
FromDHCPbooleanrequiredtrue or false
SearchDomainArrayoptionala list of search domains
DNSManualArrayoptionala list of DNS addresses
+-TypeStringrequired"IPv4" or "IPv6"
+-IPv4AddressStringoptionalIPv4 address
+-IPv6AddressStringoptionalIPv6 address
letparams={'FromDHCP' : false,'SearchDomain': ['futomi.gr.jp','hatano.gr.jp'],'DNSManual' : [{'Type': 'IPv4','IPv4Address': '192.168.10.1'},{'Type': 'IPv4','IPv4Address': '192.168.10.3'}]};returndevice.services.device.setDNS(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetNetworkProtocols command.

This method sends a GetNetworkProtocols command.

This method sends a SetNetworkProtocols command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NetworkProtocolsArrayrequired
+-NameStringrequired
+-EnabledBooleanoptional
+-PortIntegeroptional
letparams={'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);});

This method sends a GetNetworkDefaultGateway command.

This method sends a SetNetworkDefaultGateway command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NetworkGatewayArrayrequireda list of IP addresses of gateways
letparams={'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);});

This method sends a GetDeviceInformation command.

This method sends a GetSystemDateAndTime command.

This method sends a Reboot command.

This method sends a GetUsers command.

This method sends a CreateUsers command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
+-PasswordStringrequiredPassword
+-UserLevelStringrequiredEither "Administrator", "Operator", "User", or "Anonymous"
letparams={'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);});

This method sends a DeleteUsers command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
letparams={'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);});

This method sends a SetUser command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
+-PasswordStringrequiredPassword
+-UserLevelStringrequiredEither "Administrator", "Operator", "User", or "Anonymous"
letparams={'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);});

This method sends a RetRelayOutputs command.

This method sends a GetNTP command.

This method sends a SetNTP command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
FromDHCPBooleanrequiredtrue or false
NTPManualObjectoptional
+-TypeStringrequired"IPv4" or "IPv6"
+-IPv4AddressStringoptionalIPv4 address
+-IPv6AddressStringoptionalIPv6 address
letparams={'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);});

This method sends a GetDynamicDNS command.

This method sends a GetZeroConfiguration command.

This method sends a GetServices command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
IncludeCapabilityBooleanrequiredtrue or false
letparams={'IncludeCapability': true};device.services.device.getServices(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetServiceCapabilities command.


This object represents the ONVIF Media Service.

This method sends a GetStreamUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
ProtocolStringrequired"UDP", "HTTP", or "RTSP"
letparams={'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);});

This method sends a GetVideoEncoderConfigurations command.

This method sends a GetVideoEncoderConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configurationToken
letparams={'ConfigurationToken': '2_def_conf6'};device.services.media.getVideoEncoderConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetCompatibleVideoEncoderConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleVideoEncoderConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoEncoderConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'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);});

This method sends a GetGuaranteedNumberOfVideoEncoderInstances command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': '2_def_conf6',};device.services.media.getGuaranteedNumberOfVideoEncoderInstances(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetProfiles command.

This method sends a GetProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a CreateProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NameStringrequireda name of the profile
TokenStringoptionala token of the profile
letparams={'Name': 'TestProfile1','Token': 'TestProfile1'};device.services.media.createProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a DeleteProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
TokenStringrequireda token of the profile
letparams={'ProfileToken': 'TestProfile1'};device.services.media.deleteProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSources command.

This method sends a GetVideoSourceConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': '2_def_conf6'};device.services.media.getVideoSourceConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSourceConfigurations command.

This method sends a GetCompatibleVideoSourceConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
TokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleVideoSourceConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSourceConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': '2_def_conf6'};device.services.media.getVideoSourceConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'metadata1',};device.services.media.getMetadataConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfigurations command.

This method sends a GetCompatibleMetadataConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleMetadataConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': 'Conf001'};device.services.media.getMetadataConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSources command.

This method sends a GetAudioSourceConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig',};device.services.media.getAudioSourceConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSourceConfigurations command.

This method sends a GetCompatibleAudioSourceConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleAudioSourceConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSourceConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioSourceConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioEncoderConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfigurations command.

This method sends a GetCompatibleAudioEncoderConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleAudioEncoderConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioEncoderConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a getSnapshotUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getSnapshotUri(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF PTZ Service.

This method sends a getNodes command.

This method sends a GetNode command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NodeTokenStringrequireda token of the node
letparams={'NodeToken': 'PtzNode'};device.services.ptz.getNode(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetConfigurations command.

This method sends a GetConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the targeted PTZ configuration
letparams={'ConfigurationToken': 'PtzConf1'};device.services.ptz.getConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the targeted PTZ node
letparams={'ConfigurationToken': 'PtzConf1'};device.services.ptz.getConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetStatus command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the targeted PTZ node
letparams={'ProfileToken': 'PtzConf1'};device.services.ptz.getStatus(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a ContinuousMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
VelocityObjectrequired
+-xFloatrequiredSpeed of pan (in the range of -1.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of -1.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of -1.0 to 1.0)
TimeoutIntengeroptionalTimeout (seconds)
letparams={'ProfileToken': '2_def_profile6','Velocity' : {'x': -1,'y': 0,'z': 0},'Timeout' : 1};device.services.ptz.continuousMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a AbsoluteMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PositionObjectrequired
+-xFloatrequiredPosition of pan (The range depends on the profile)
+-yFloatrequiredPosition of tilt (The range depends on the profile)
+-zFloatrequiredPosition of zoom (The range depends on the profile)
SpeedObjectrequired
+-xFloatrequiredSpeed of pan (in the range of -1.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of -1.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of -1.0 to 1.0)
letparams={'ProfileToken': cam['ProfileToken'],'Position' : {'x': 0,'y': 0,'z': 0.003},'Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.absoluteMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a RelativeMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
TranslationObjectrequired
 | `x` | Float | required | Translation of pan (in the range of -1.0 to 1.0)
| `y` | Float | required | Translation of tilt (in the range of -1.0 to 1.0)
| `z` | Float | required | Translation of zoom (in the range of -1.0 to 1.0)

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)

letparams={'ProfileToken': '2_def_profile6','Translation' : {'x': 0.1,'y': 0.1,'z': 0},'Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.relativeMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a stop command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PanTiltBooleanoptionaltrue or false
ZoomBooleanoptionaltrue or false
letparams={'ProfileToken': '2_def_profile6','PanTilt': true,'Zoom': true};device.services.ptz.stop(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GotoHomePosition command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
SpeedFloatoptionalSpeed in the range of 0.0 to 1.0
letparams={'ProfileToken': '2_def_profile6','Speed': 0.5};device.services.ptz.gotoHomePosition(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a SetHomePosition command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.ptz.setHomePosition(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a SetPreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringoptionala token of the preset
PresetNameStringoptionala name of the preset
letparams={'ProfileToken': '2_def_profile6','PresetName' : 'PresetTest1'};device.services.ptz.setPreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetPresets command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.ptz.getPresets(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GotoPreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringrequireda token of the preset
SpeedObjectrequired
+-xFloatrequiredSpeed of pan (in the range of 0.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of 0.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of 0.0 to 1.0)
letparams={'ProfileToken': '2_def_profile6','PresetToken' : '12','Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.gotoPreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a RemovePreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringrequireda token of the preset
letparams={'ProfileToken': '2_def_profile6','PresetToken' : '12'};device.services.ptz.removePreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF Search Service.

This method sends a GetServiceCapabilities command.

This method sends a GetRecordingSummary command.

This method sends a FindRecordings command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopeObjectrequiredscope defines the dataset to consider for this search
+-IncludedSourcesArrayoptionala list of sources that are included in the scope
+-+-TypeStringoptional
+-+-TokenStringrequired
+-IncludedRecordingsArrayoptionala list of recordings that are included in the scope
+-RecordingInformationFilterStringoptionalan xpath expression used to specify what recordings to search
+-ExtensionStringoptionalextension point
MaxMatchesIntegeroptionalthe search will be completed after this many matches
KeepAliveTimeIntegerrequiredthe time the search session will be kept alive after responding to this and subsequent requests
letparams={'Scope': {'IncludedSources': [{'Type': 'sourceType','Token': 'sourceToken'}],'IncludedRecordings': ['recording1'],'RecordingInformationFilter': 'filter','Extension': 'extension',},'MaxMatches': 3,'KeepAliveTime': 100};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetRecordingSearchResults command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
SearchTokenStringrequiredthe search session to get results from
MinResultsIntegeroptionalthe minimum number of results to return in one response
MaxResultsIntegeroptionalthe maximum number of results to return in one response
WaitTimeIntegeroptionalthe maximum time before responding to the request
letparams={'SearchToken': 'token','MinResults': 3,'MaxResults': 14,'WaitTime': 50};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF Replay Service.

This method sends a GetServiceCapabilities command.

This method sends a GetReplayUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
StreamSetupObjectrequiredthe connection parameters to be used for the stream
+-StreamStringrequiredeither RTP-Unicast, RTP-Multicast
+-TransportObjectrequired
+-+-ProtocolStringrequiredeither UDP, TCP, RTSP, HTTP
+-+-TunnelObjectoptionalTODO not implemented
RecordingTokenStringrequiredidentifier of the recording to be streamed
letparams={'StreamSetup': {'Stream': 'RTP-Unicast','Transport': {'Protocol': 'TCP'},},'RecordingToken': 'token'};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This module is based on the ONVIF specifications:


  • v0.1.7 (2018-08-14)
    • Newly added the lastResponse property to the OnvifDevice object for debug. This property is used to investigate SOAP parse error.
  • v0.1.6 (2018-08-13)
    • Fixed the bug of SOAP name space handling. (Issue #38)
  • v0.1.5 (2018-08-13)
  • v0.1.4 (2018-03-25)
    • Clarified the instruction of the installation in the README.md and Added the engines section to the package.json. (Pull Request #24)
    • Fixed the bug of the loop of SearchDomain. (Pull Request #23)
  • v0.1.3 (2018-02-11)
  • v0.1.0 (2017-08-30)
    • Rewrote all scripts to be modern coding style such as let, const, and Promise. All of the asynchronous methods now return a Promise object.
    • Dramatically improved the discovery processs.
    • Supported the devices which do not support the GetSystemDateAndTime command. In the earlier versions, the init method failed if the targeted device did not support the command. Now the init() method will work well with such devices.
    • The startDiscovery() and stopDiscovery() mehtods became deprecated.
    • Newly added the startProbe() and stopProbe() methods.
    • Appended a failure reason text to an Error.message parsing a SOAP message from a device.
    • Fixed bugs of the OnvifServicePtz.getNode(), OnvifServicePtz.getConfiguration(), and OnvifServicePtz.getConfigurationOptions() methods. The methods sent a wrong SOAP message.
    • Implemented the Speed parameter in the OnvifServicePtz.relativeMove() method.

The MIT License (MIT)

Copyright (c) 2016 - 2018 Futomi Hatano

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

The node-onvif is a Node.js module which allows you to communicate with the network camera which supports the ONVIF specifications.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Latest commit

History

55 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

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
    • Search Service
    • Replay 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.

ONVIF Network Camera Manager


Table of Contents


This section shows how to discover ONVIF network cameras, how to get the device information, and how to control the PTZ of the device.

This sample code shows how to discover ONVIF network cameras.

constonvif=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.

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.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.10:80/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.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"
}

This sample code shows how to get the UDP stream URL.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Get the UDP stream URLleturl=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

This sample code shows how to get the data of the snapshot and save it to a file.

constonvif=require('node-onvif');constfs=require('fs');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Get the data of the snapshotconsole.log('fetching the data of the snapshot...');returndevice.fetchSnapshot();}).then((res)=>{// Save the data to a filefs.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.

This sample code shows how to pan, tilt, and zoom the ONVIF network camera.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Move the camerareturndevice.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 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.


In order to use the node-onvif module, you have to load the node-onvif module as follows:

constonvif=require('node-onvif');

The variable onvif in the code above is the Onvif object.

This section describes the methods implemented in the Onvif object.

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:

PropertyTypeDescription
urnStringThe URN (Uniform Resource Name) assigned to the device (e.g., "urn:uuid:6b2be733-6ad1-4467-8bd0-747bd8efd206")
nameStringThe product name of the device (e.g., "Panasonic BB-SC384B").
hardwareStringThe description of the hardware of the device (e.g., "BB-SC384B").
locationStringThe physical location of the device (e.g., "China", "shenzhen", "office").
typesArrayThe list of types supported by the device (e.g., "dn:NetworkVideoTransmitter", "tds:Device"). Basically, this module is for "dn:NetworkVideoTransmitter".
xaddrsArrayThe 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").
scopesArrayThe 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.

constonvif=require('node-onvif');// Find the ONVIF network camerasonvif.startProbe().then((device_list)=>{// Show the information of the found devicesconsole.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"]}]

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.

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:

PropertyTypeDescription
urnStringThe URN (Uniform Resource Name) assigned to the device (e.g., "urn:uuid:6b2be733-6ad1-4467-8bd0-747bd8efd206")
nameStringThe product name of the device (e.g., "Panasonic BB-SC384B").
hardwareStringThe description of the hardware of the device (e.g., "BB-SC384B").
locationStringThe physical location of the device (e.g., "China", "shenzhen", "office").
typesArrayThe list of types supported by the device (e.g., "dn:NetworkVideoTransmitter", "tds:Device"). Basically, this module is for "dn:NetworkVideoTransmitter".
xaddrsArrayThe 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").
scopesArrayThe 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.

constonvif=require('node-onvif');// Find the ONVIF network camerasonvif.startDiscovery((info)=>{// Show the information of the found deviceconsole.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",""]}

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.

constonvif=require('node-onvif');// Start the discovery processonvif.startDiscovery((info)=>{// Do something});// Stop the discovery process in 3 secondssetTimeout(()=>{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();

The OnvifDevice object represents an ONVIF network camera device. You can control the ONVIF network camera through this object.

In order to control an ONVIF network camera, you have to create an OnvifDevice object from the OnvifDevice constructor by yourself as follows:

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.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:

PropertyTypeRequiredDescription
xaddrStringrequiredURL of the end point of the targeted device.
userStringoptionalUser name for the user authentication.
passStringoptionalPassword 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).

The OnvifDevice object provides some properties as follows:

PropertyTypeDescription
servicesObject
+-deviceObjectOnvifServiceDevice object
+-mediaObjectOnvifServiceMedia object
+-ptzObjectOnvifServicePtz object
+-searchObjectOnvifServiceSearch object
+-replayObjectOnvifServiceReplay object

These objects will be set when the initialization process is completed calling the init() method. See the section "ONVIF commands" for details.

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:

PropertyTypeDescription
ManufacturerStringThe manufactor of the device.
ModelStringThe device model.
FirmwareVersionStringThe firmware version in the device.
SerialNumberStringThe serial number of the device.
HardwareIdStringThe hardware ID of the device.
constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '888888'});// Initialize the OnvifDevice objectdevice.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"}

This method returns a hash object consisting of several device information as follow:

PropertyTypeDescription
ManufacturerStringThe manufactor of the device.
ModelStringThe device model.
FirmwareVersionStringThe firmware version in the device.
SerialNumberStringThe serial number of the device.
HardwareIdStringThe 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.

letinfo=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"}

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.

letprofile=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}}}}

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.

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 profileletprofile=device.getCurrentProfile();// Show the video resolution of the current profileletreso=profile['video']['encoder']['resolution'];console.log('- Before: '+reso['width']+' x '+reso['height']);// Get a list of the profiles set in the deviceletprofile_list=device.getProfileList();// Find the profile whose video resolution is the smallestletmin_square=4000*2000;letmin_index=0;for(leti=0;i<profile_list.length;i++){letresolution=profile_list[i]['video']['encoder']['resolution'];letsquare=resolution['width']*resolution['height'];if(square<min_square){min_square=square;min_index=i;}}// Change the current profileprofile=device.changeProfile(min_index);// Show the video resolutionreso=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

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.

leturl=device.getUdpStreamUrl();console.log(url);

The code above will output the result like this:

rtsp://192.168.10.14:10554/tcp/av0_0

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:

PropertyTypeDescription
headersObjectheaders object representing the HTTP response header. This object is of the http module of Node.js.
bodyObjectBuffer 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 extentionletext='bin';letmime_pair=res.headers['content-type'].split('/');if(mime_pair[0]==='image'){ext=mime_pair[1];}// Save the data to a fileletfname='snapshot.'+ext;fs.writeFileSync(fname,res.body,{encoding: 'binary'});console.log('Done!');}).catch((error)=>{console.error(error);});

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:

PropertyTypeRequiredDescription
speedObjectrequired
+-xFloatrequiredSpeed of pan in the range of -1.0 to 1.0.
+-yFloatrequiredSpeed of tilt in the range of -1.0 to 1.0.
+-zFloatrequiredSpeed of zoom in the range of -1.0 to 1.0.
timeoutIntegeroptionalTimeout 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.

letparams={'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 cameradevice.ptzMove(params).then(()=>{console.log('Done!');}).catch((error)=>{console.error(error);});

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 parametersletparams={'speed': {x: 0.5,y: 0.0,z: 0.0},'timeout': 60// seconds};// Supposed to move the camera for 60 secondsdevice.ptzMove(params).then(()=>{console.log('Succeeded to move.');// Stop to the PTZ in 2 secondssetTimeout(()=>{device.ptzStop().then(()=>{console.log('Succeeded to stop.');}).catch((error)=>{console.error(error);});},2000);}).catch((error)=>{console.error(error);});

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 objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// The OnvifServicePtz objectletptz=device.services.ptz;if(!ptz){thrownewError('Your ONVIF network camera does not support the PTZ service.');}// The parameters for the gotoHomePosition() methodletprofile=device.getCurrentProfile();letparams={'ProfileToken': profile['token'],'Speed' : 1};// Send the GotoHomePosition command using the gotoHomePosition() methodreturnptz.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:

PropertyTypeDescription
soapStringRaw SOAP response
formattedStringFormatted SOAP response in order to be human readable
convertedObjectJavaScript object converted from SOAP response by xml2js module
dataObjectJavaScript 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:Envelopexmlns: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><GotoHomePositionResponsexmlns="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:Envelopexmlns: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>
<GotoHomePositionResponsexmlns="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.


This object represents the ONVIF Device Management Service.

This method sends a GetCapabilities command.

This method sends a GetWsdlUrl command.

This method sends a GetDiscoveryMode command.

This method sends a GetScopes command.

This method sends a SetScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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:

letparams={'Scopes': []}

This method sends a AddScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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);});

This method sends a RemoveScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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);});

This method sends a GetHostname command.

This method sends a SetHostname command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NameStringrequireda host name

The code below shows how to set some scopes:

letparams={'Name': 'cam001'};device.services.device.setHostname(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetDNS command.

This method sends a SetDNS command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
FromDHCPbooleanrequiredtrue or false
SearchDomainArrayoptionala list of search domains
DNSManualArrayoptionala list of DNS addresses
+-TypeStringrequired"IPv4" or "IPv6"
+-IPv4AddressStringoptionalIPv4 address
+-IPv6AddressStringoptionalIPv6 address
letparams={'FromDHCP' : false,'SearchDomain': ['futomi.gr.jp','hatano.gr.jp'],'DNSManual' : [{'Type': 'IPv4','IPv4Address': '192.168.10.1'},{'Type': 'IPv4','IPv4Address': '192.168.10.3'}]};returndevice.services.device.setDNS(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetNetworkProtocols command.

This method sends a GetNetworkProtocols command.

This method sends a SetNetworkProtocols command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NetworkProtocolsArrayrequired
+-NameStringrequired
+-EnabledBooleanoptional
+-PortIntegeroptional
letparams={'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);});

This method sends a GetNetworkDefaultGateway command.

This method sends a SetNetworkDefaultGateway command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NetworkGatewayArrayrequireda list of IP addresses of gateways
letparams={'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);});

This method sends a GetDeviceInformation command.

This method sends a GetSystemDateAndTime command.

This method sends a Reboot command.

This method sends a GetUsers command.

This method sends a CreateUsers command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
+-PasswordStringrequiredPassword
+-UserLevelStringrequiredEither "Administrator", "Operator", "User", or "Anonymous"
letparams={'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);});

This method sends a DeleteUsers command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
letparams={'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);});

This method sends a SetUser command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
+-PasswordStringrequiredPassword
+-UserLevelStringrequiredEither "Administrator", "Operator", "User", or "Anonymous"
letparams={'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);});

This method sends a RetRelayOutputs command.

This method sends a GetNTP command.

This method sends a SetNTP command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
FromDHCPBooleanrequiredtrue or false
NTPManualObjectoptional
+-TypeStringrequired"IPv4" or "IPv6"
+-IPv4AddressStringoptionalIPv4 address
+-IPv6AddressStringoptionalIPv6 address
letparams={'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);});

This method sends a GetDynamicDNS command.

This method sends a GetZeroConfiguration command.

This method sends a GetServices command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
IncludeCapabilityBooleanrequiredtrue or false
letparams={'IncludeCapability': true};device.services.device.getServices(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetServiceCapabilities command.


This object represents the ONVIF Media Service.

This method sends a GetStreamUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
ProtocolStringrequired"UDP", "HTTP", or "RTSP"
letparams={'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);});

This method sends a GetVideoEncoderConfigurations command.

This method sends a GetVideoEncoderConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configurationToken
letparams={'ConfigurationToken': '2_def_conf6'};device.services.media.getVideoEncoderConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetCompatibleVideoEncoderConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleVideoEncoderConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoEncoderConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'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);});

This method sends a GetGuaranteedNumberOfVideoEncoderInstances command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': '2_def_conf6',};device.services.media.getGuaranteedNumberOfVideoEncoderInstances(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetProfiles command.

This method sends a GetProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a CreateProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NameStringrequireda name of the profile
TokenStringoptionala token of the profile
letparams={'Name': 'TestProfile1','Token': 'TestProfile1'};device.services.media.createProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a DeleteProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
TokenStringrequireda token of the profile
letparams={'ProfileToken': 'TestProfile1'};device.services.media.deleteProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSources command.

This method sends a GetVideoSourceConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': '2_def_conf6'};device.services.media.getVideoSourceConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSourceConfigurations command.

This method sends a GetCompatibleVideoSourceConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
TokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleVideoSourceConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSourceConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': '2_def_conf6'};device.services.media.getVideoSourceConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'metadata1',};device.services.media.getMetadataConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfigurations command.

This method sends a GetCompatibleMetadataConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleMetadataConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': 'Conf001'};device.services.media.getMetadataConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSources command.

This method sends a GetAudioSourceConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig',};device.services.media.getAudioSourceConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSourceConfigurations command.

This method sends a GetCompatibleAudioSourceConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleAudioSourceConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSourceConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioSourceConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioEncoderConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfigurations command.

This method sends a GetCompatibleAudioEncoderConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleAudioEncoderConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioEncoderConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a getSnapshotUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getSnapshotUri(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF PTZ Service.

This method sends a getNodes command.

This method sends a GetNode command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NodeTokenStringrequireda token of the node
letparams={'NodeToken': 'PtzNode'};device.services.ptz.getNode(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetConfigurations command.

This method sends a GetConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the targeted PTZ configuration
letparams={'ConfigurationToken': 'PtzConf1'};device.services.ptz.getConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the targeted PTZ node
letparams={'ConfigurationToken': 'PtzConf1'};device.services.ptz.getConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetStatus command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the targeted PTZ node
letparams={'ProfileToken': 'PtzConf1'};device.services.ptz.getStatus(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a ContinuousMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
VelocityObjectrequired
+-xFloatrequiredSpeed of pan (in the range of -1.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of -1.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of -1.0 to 1.0)
TimeoutIntengeroptionalTimeout (seconds)
letparams={'ProfileToken': '2_def_profile6','Velocity' : {'x': -1,'y': 0,'z': 0},'Timeout' : 1};device.services.ptz.continuousMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a AbsoluteMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PositionObjectrequired
+-xFloatrequiredPosition of pan (The range depends on the profile)
+-yFloatrequiredPosition of tilt (The range depends on the profile)
+-zFloatrequiredPosition of zoom (The range depends on the profile)
SpeedObjectrequired
+-xFloatrequiredSpeed of pan (in the range of -1.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of -1.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of -1.0 to 1.0)
letparams={'ProfileToken': cam['ProfileToken'],'Position' : {'x': 0,'y': 0,'z': 0.003},'Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.absoluteMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a RelativeMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
TranslationObjectrequired
 | `x` | Float | required | Translation of pan (in the range of -1.0 to 1.0)
| `y` | Float | required | Translation of tilt (in the range of -1.0 to 1.0)
| `z` | Float | required | Translation of zoom (in the range of -1.0 to 1.0)

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)

letparams={'ProfileToken': '2_def_profile6','Translation' : {'x': 0.1,'y': 0.1,'z': 0},'Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.relativeMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a stop command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PanTiltBooleanoptionaltrue or false
ZoomBooleanoptionaltrue or false
letparams={'ProfileToken': '2_def_profile6','PanTilt': true,'Zoom': true};device.services.ptz.stop(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GotoHomePosition command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
SpeedFloatoptionalSpeed in the range of 0.0 to 1.0
letparams={'ProfileToken': '2_def_profile6','Speed': 0.5};device.services.ptz.gotoHomePosition(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a SetHomePosition command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.ptz.setHomePosition(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a SetPreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringoptionala token of the preset
PresetNameStringoptionala name of the preset
letparams={'ProfileToken': '2_def_profile6','PresetName' : 'PresetTest1'};device.services.ptz.setPreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetPresets command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.ptz.getPresets(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GotoPreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringrequireda token of the preset
SpeedObjectrequired
+-xFloatrequiredSpeed of pan (in the range of 0.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of 0.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of 0.0 to 1.0)
letparams={'ProfileToken': '2_def_profile6','PresetToken' : '12','Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.gotoPreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a RemovePreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringrequireda token of the preset
letparams={'ProfileToken': '2_def_profile6','PresetToken' : '12'};device.services.ptz.removePreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF Search Service.

This method sends a GetServiceCapabilities command.

This method sends a GetRecordingSummary command.

This method sends a FindRecordings command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopeObjectrequiredscope defines the dataset to consider for this search
+-IncludedSourcesArrayoptionala list of sources that are included in the scope
+-+-TypeStringoptional
+-+-TokenStringrequired
+-IncludedRecordingsArrayoptionala list of recordings that are included in the scope
+-RecordingInformationFilterStringoptionalan xpath expression used to specify what recordings to search
+-ExtensionStringoptionalextension point
MaxMatchesIntegeroptionalthe search will be completed after this many matches
KeepAliveTimeIntegerrequiredthe time the search session will be kept alive after responding to this and subsequent requests
letparams={'Scope': {'IncludedSources': [{'Type': 'sourceType','Token': 'sourceToken'}],'IncludedRecordings': ['recording1'],'RecordingInformationFilter': 'filter','Extension': 'extension',},'MaxMatches': 3,'KeepAliveTime': 100};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetRecordingSearchResults command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
SearchTokenStringrequiredthe search session to get results from
MinResultsIntegeroptionalthe minimum number of results to return in one response
MaxResultsIntegeroptionalthe maximum number of results to return in one response
WaitTimeIntegeroptionalthe maximum time before responding to the request
letparams={'SearchToken': 'token','MinResults': 3,'MaxResults': 14,'WaitTime': 50};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF Replay Service.

This method sends a GetServiceCapabilities command.

This method sends a GetReplayUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
StreamSetupObjectrequiredthe connection parameters to be used for the stream
+-StreamStringrequiredeither RTP-Unicast, RTP-Multicast
+-TransportObjectrequired
+-+-ProtocolStringrequiredeither UDP, TCP, RTSP, HTTP
+-+-TunnelObjectoptionalTODO not implemented
RecordingTokenStringrequiredidentifier of the recording to be streamed
letparams={'StreamSetup': {'Stream': 'RTP-Unicast','Transport': {'Protocol': 'TCP'},},'RecordingToken': 'token'};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This module is based on the ONVIF specifications:


  • v0.1.7 (2018-08-14)
    • Newly added the lastResponse property to the OnvifDevice object for debug. This property is used to investigate SOAP parse error.
  • v0.1.6 (2018-08-13)
    • Fixed the bug of SOAP name space handling. (Issue #38)
  • v0.1.5 (2018-08-13)
  • v0.1.4 (2018-03-25)
    • Clarified the instruction of the installation in the README.md and Added the engines section to the package.json. (Pull Request #24)
    • Fixed the bug of the loop of SearchDomain. (Pull Request #23)
  • v0.1.3 (2018-02-11)
  • v0.1.0 (2017-08-30)
    • Rewrote all scripts to be modern coding style such as let, const, and Promise. All of the asynchronous methods now return a Promise object.
    • Dramatically improved the discovery processs.
    • Supported the devices which do not support the GetSystemDateAndTime command. In the earlier versions, the init method failed if the targeted device did not support the command. Now the init() method will work well with such devices.
    • The startDiscovery() and stopDiscovery() mehtods became deprecated.
    • Newly added the startProbe() and stopProbe() methods.
    • Appended a failure reason text to an Error.message parsing a SOAP message from a device.
    • Fixed bugs of the OnvifServicePtz.getNode(), OnvifServicePtz.getConfiguration(), and OnvifServicePtz.getConfigurationOptions() methods. The methods sent a wrong SOAP message.
    • Implemented the Speed parameter in the OnvifServicePtz.relativeMove() method.

The MIT License (MIT)

Copyright (c) 2016 - 2018 Futomi Hatano

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

The node-onvif is a Node.js module which allows you to communicate with the network camera which supports the ONVIF specifications.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

55 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

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
    • Search Service
    • Replay 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.

ONVIF Network Camera Manager


Table of Contents


This section shows how to discover ONVIF network cameras, how to get the device information, and how to control the PTZ of the device.

This sample code shows how to discover ONVIF network cameras.

constonvif=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.

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.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.10:80/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.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"
}

This sample code shows how to get the UDP stream URL.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Get the UDP stream URLleturl=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

This sample code shows how to get the data of the snapshot and save it to a file.

constonvif=require('node-onvif');constfs=require('fs');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Get the data of the snapshotconsole.log('fetching the data of the snapshot...');returndevice.fetchSnapshot();}).then((res)=>{// Save the data to a filefs.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.

This sample code shows how to pan, tilt, and zoom the ONVIF network camera.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Move the camerareturndevice.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 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.


In order to use the node-onvif module, you have to load the node-onvif module as follows:

constonvif=require('node-onvif');

The variable onvif in the code above is the Onvif object.

This section describes the methods implemented in the Onvif object.

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:

PropertyTypeDescription
urnStringThe URN (Uniform Resource Name) assigned to the device (e.g., "urn:uuid:6b2be733-6ad1-4467-8bd0-747bd8efd206")
nameStringThe product name of the device (e.g., "Panasonic BB-SC384B").
hardwareStringThe description of the hardware of the device (e.g., "BB-SC384B").
locationStringThe physical location of the device (e.g., "China", "shenzhen", "office").
typesArrayThe list of types supported by the device (e.g., "dn:NetworkVideoTransmitter", "tds:Device"). Basically, this module is for "dn:NetworkVideoTransmitter".
xaddrsArrayThe 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").
scopesArrayThe 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.

constonvif=require('node-onvif');// Find the ONVIF network camerasonvif.startProbe().then((device_list)=>{// Show the information of the found devicesconsole.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"]}]

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.

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:

PropertyTypeDescription
urnStringThe URN (Uniform Resource Name) assigned to the device (e.g., "urn:uuid:6b2be733-6ad1-4467-8bd0-747bd8efd206")
nameStringThe product name of the device (e.g., "Panasonic BB-SC384B").
hardwareStringThe description of the hardware of the device (e.g., "BB-SC384B").
locationStringThe physical location of the device (e.g., "China", "shenzhen", "office").
typesArrayThe list of types supported by the device (e.g., "dn:NetworkVideoTransmitter", "tds:Device"). Basically, this module is for "dn:NetworkVideoTransmitter".
xaddrsArrayThe 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").
scopesArrayThe 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.

constonvif=require('node-onvif');// Find the ONVIF network camerasonvif.startDiscovery((info)=>{// Show the information of the found deviceconsole.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",""]}

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.

constonvif=require('node-onvif');// Start the discovery processonvif.startDiscovery((info)=>{// Do something});// Stop the discovery process in 3 secondssetTimeout(()=>{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();

The OnvifDevice object represents an ONVIF network camera device. You can control the ONVIF network camera through this object.

In order to control an ONVIF network camera, you have to create an OnvifDevice object from the OnvifDevice constructor by yourself as follows:

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.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:

PropertyTypeRequiredDescription
xaddrStringrequiredURL of the end point of the targeted device.
userStringoptionalUser name for the user authentication.
passStringoptionalPassword 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).

The OnvifDevice object provides some properties as follows:

PropertyTypeDescription
servicesObject
+-deviceObjectOnvifServiceDevice object
+-mediaObjectOnvifServiceMedia object
+-ptzObjectOnvifServicePtz object
+-searchObjectOnvifServiceSearch object
+-replayObjectOnvifServiceReplay object

These objects will be set when the initialization process is completed calling the init() method. See the section "ONVIF commands" for details.

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:

PropertyTypeDescription
ManufacturerStringThe manufactor of the device.
ModelStringThe device model.
FirmwareVersionStringThe firmware version in the device.
SerialNumberStringThe serial number of the device.
HardwareIdStringThe hardware ID of the device.
constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '888888'});// Initialize the OnvifDevice objectdevice.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"}

This method returns a hash object consisting of several device information as follow:

PropertyTypeDescription
ManufacturerStringThe manufactor of the device.
ModelStringThe device model.
FirmwareVersionStringThe firmware version in the device.
SerialNumberStringThe serial number of the device.
HardwareIdStringThe 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.

letinfo=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"}

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.

letprofile=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}}}}

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.

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 profileletprofile=device.getCurrentProfile();// Show the video resolution of the current profileletreso=profile['video']['encoder']['resolution'];console.log('- Before: '+reso['width']+' x '+reso['height']);// Get a list of the profiles set in the deviceletprofile_list=device.getProfileList();// Find the profile whose video resolution is the smallestletmin_square=4000*2000;letmin_index=0;for(leti=0;i<profile_list.length;i++){letresolution=profile_list[i]['video']['encoder']['resolution'];letsquare=resolution['width']*resolution['height'];if(square<min_square){min_square=square;min_index=i;}}// Change the current profileprofile=device.changeProfile(min_index);// Show the video resolutionreso=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

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.

leturl=device.getUdpStreamUrl();console.log(url);

The code above will output the result like this:

rtsp://192.168.10.14:10554/tcp/av0_0

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:

PropertyTypeDescription
headersObjectheaders object representing the HTTP response header. This object is of the http module of Node.js.
bodyObjectBuffer 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 extentionletext='bin';letmime_pair=res.headers['content-type'].split('/');if(mime_pair[0]==='image'){ext=mime_pair[1];}// Save the data to a fileletfname='snapshot.'+ext;fs.writeFileSync(fname,res.body,{encoding: 'binary'});console.log('Done!');}).catch((error)=>{console.error(error);});

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:

PropertyTypeRequiredDescription
speedObjectrequired
+-xFloatrequiredSpeed of pan in the range of -1.0 to 1.0.
+-yFloatrequiredSpeed of tilt in the range of -1.0 to 1.0.
+-zFloatrequiredSpeed of zoom in the range of -1.0 to 1.0.
timeoutIntegeroptionalTimeout 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.

letparams={'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 cameradevice.ptzMove(params).then(()=>{console.log('Done!');}).catch((error)=>{console.error(error);});

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 parametersletparams={'speed': {x: 0.5,y: 0.0,z: 0.0},'timeout': 60// seconds};// Supposed to move the camera for 60 secondsdevice.ptzMove(params).then(()=>{console.log('Succeeded to move.');// Stop to the PTZ in 2 secondssetTimeout(()=>{device.ptzStop().then(()=>{console.log('Succeeded to stop.');}).catch((error)=>{console.error(error);});},2000);}).catch((error)=>{console.error(error);});

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 objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// The OnvifServicePtz objectletptz=device.services.ptz;if(!ptz){thrownewError('Your ONVIF network camera does not support the PTZ service.');}// The parameters for the gotoHomePosition() methodletprofile=device.getCurrentProfile();letparams={'ProfileToken': profile['token'],'Speed' : 1};// Send the GotoHomePosition command using the gotoHomePosition() methodreturnptz.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:

PropertyTypeDescription
soapStringRaw SOAP response
formattedStringFormatted SOAP response in order to be human readable
convertedObjectJavaScript object converted from SOAP response by xml2js module
dataObjectJavaScript 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:Envelopexmlns: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><GotoHomePositionResponsexmlns="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:Envelopexmlns: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>
<GotoHomePositionResponsexmlns="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.


This object represents the ONVIF Device Management Service.

This method sends a GetCapabilities command.

This method sends a GetWsdlUrl command.

This method sends a GetDiscoveryMode command.

This method sends a GetScopes command.

This method sends a SetScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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:

letparams={'Scopes': []}

This method sends a AddScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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);});

This method sends a RemoveScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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);});

This method sends a GetHostname command.

This method sends a SetHostname command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NameStringrequireda host name

The code below shows how to set some scopes:

letparams={'Name': 'cam001'};device.services.device.setHostname(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetDNS command.

This method sends a SetDNS command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
FromDHCPbooleanrequiredtrue or false
SearchDomainArrayoptionala list of search domains
DNSManualArrayoptionala list of DNS addresses
+-TypeStringrequired"IPv4" or "IPv6"
+-IPv4AddressStringoptionalIPv4 address
+-IPv6AddressStringoptionalIPv6 address
letparams={'FromDHCP' : false,'SearchDomain': ['futomi.gr.jp','hatano.gr.jp'],'DNSManual' : [{'Type': 'IPv4','IPv4Address': '192.168.10.1'},{'Type': 'IPv4','IPv4Address': '192.168.10.3'}]};returndevice.services.device.setDNS(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetNetworkProtocols command.

This method sends a GetNetworkProtocols command.

This method sends a SetNetworkProtocols command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NetworkProtocolsArrayrequired
+-NameStringrequired
+-EnabledBooleanoptional
+-PortIntegeroptional
letparams={'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);});

This method sends a GetNetworkDefaultGateway command.

This method sends a SetNetworkDefaultGateway command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NetworkGatewayArrayrequireda list of IP addresses of gateways
letparams={'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);});

This method sends a GetDeviceInformation command.

This method sends a GetSystemDateAndTime command.

This method sends a Reboot command.

This method sends a GetUsers command.

This method sends a CreateUsers command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
+-PasswordStringrequiredPassword
+-UserLevelStringrequiredEither "Administrator", "Operator", "User", or "Anonymous"
letparams={'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);});

This method sends a DeleteUsers command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
letparams={'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);});

This method sends a SetUser command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
+-PasswordStringrequiredPassword
+-UserLevelStringrequiredEither "Administrator", "Operator", "User", or "Anonymous"
letparams={'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);});

This method sends a RetRelayOutputs command.

This method sends a GetNTP command.

This method sends a SetNTP command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
FromDHCPBooleanrequiredtrue or false
NTPManualObjectoptional
+-TypeStringrequired"IPv4" or "IPv6"
+-IPv4AddressStringoptionalIPv4 address
+-IPv6AddressStringoptionalIPv6 address
letparams={'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);});

This method sends a GetDynamicDNS command.

This method sends a GetZeroConfiguration command.

This method sends a GetServices command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
IncludeCapabilityBooleanrequiredtrue or false
letparams={'IncludeCapability': true};device.services.device.getServices(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetServiceCapabilities command.


This object represents the ONVIF Media Service.

This method sends a GetStreamUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
ProtocolStringrequired"UDP", "HTTP", or "RTSP"
letparams={'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);});

This method sends a GetVideoEncoderConfigurations command.

This method sends a GetVideoEncoderConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configurationToken
letparams={'ConfigurationToken': '2_def_conf6'};device.services.media.getVideoEncoderConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetCompatibleVideoEncoderConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleVideoEncoderConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoEncoderConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'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);});

This method sends a GetGuaranteedNumberOfVideoEncoderInstances command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': '2_def_conf6',};device.services.media.getGuaranteedNumberOfVideoEncoderInstances(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetProfiles command.

This method sends a GetProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a CreateProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NameStringrequireda name of the profile
TokenStringoptionala token of the profile
letparams={'Name': 'TestProfile1','Token': 'TestProfile1'};device.services.media.createProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a DeleteProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
TokenStringrequireda token of the profile
letparams={'ProfileToken': 'TestProfile1'};device.services.media.deleteProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSources command.

This method sends a GetVideoSourceConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': '2_def_conf6'};device.services.media.getVideoSourceConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSourceConfigurations command.

This method sends a GetCompatibleVideoSourceConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
TokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleVideoSourceConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSourceConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': '2_def_conf6'};device.services.media.getVideoSourceConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'metadata1',};device.services.media.getMetadataConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfigurations command.

This method sends a GetCompatibleMetadataConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleMetadataConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': 'Conf001'};device.services.media.getMetadataConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSources command.

This method sends a GetAudioSourceConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig',};device.services.media.getAudioSourceConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSourceConfigurations command.

This method sends a GetCompatibleAudioSourceConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleAudioSourceConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSourceConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioSourceConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioEncoderConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfigurations command.

This method sends a GetCompatibleAudioEncoderConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleAudioEncoderConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioEncoderConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a getSnapshotUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getSnapshotUri(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF PTZ Service.

This method sends a getNodes command.

This method sends a GetNode command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NodeTokenStringrequireda token of the node
letparams={'NodeToken': 'PtzNode'};device.services.ptz.getNode(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetConfigurations command.

This method sends a GetConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the targeted PTZ configuration
letparams={'ConfigurationToken': 'PtzConf1'};device.services.ptz.getConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the targeted PTZ node
letparams={'ConfigurationToken': 'PtzConf1'};device.services.ptz.getConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetStatus command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the targeted PTZ node
letparams={'ProfileToken': 'PtzConf1'};device.services.ptz.getStatus(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a ContinuousMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
VelocityObjectrequired
+-xFloatrequiredSpeed of pan (in the range of -1.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of -1.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of -1.0 to 1.0)
TimeoutIntengeroptionalTimeout (seconds)
letparams={'ProfileToken': '2_def_profile6','Velocity' : {'x': -1,'y': 0,'z': 0},'Timeout' : 1};device.services.ptz.continuousMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a AbsoluteMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PositionObjectrequired
+-xFloatrequiredPosition of pan (The range depends on the profile)
+-yFloatrequiredPosition of tilt (The range depends on the profile)
+-zFloatrequiredPosition of zoom (The range depends on the profile)
SpeedObjectrequired
+-xFloatrequiredSpeed of pan (in the range of -1.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of -1.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of -1.0 to 1.0)
letparams={'ProfileToken': cam['ProfileToken'],'Position' : {'x': 0,'y': 0,'z': 0.003},'Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.absoluteMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a RelativeMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
TranslationObjectrequired
 | `x` | Float | required | Translation of pan (in the range of -1.0 to 1.0)
| `y` | Float | required | Translation of tilt (in the range of -1.0 to 1.0)
| `z` | Float | required | Translation of zoom (in the range of -1.0 to 1.0)

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)

letparams={'ProfileToken': '2_def_profile6','Translation' : {'x': 0.1,'y': 0.1,'z': 0},'Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.relativeMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a stop command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PanTiltBooleanoptionaltrue or false
ZoomBooleanoptionaltrue or false
letparams={'ProfileToken': '2_def_profile6','PanTilt': true,'Zoom': true};device.services.ptz.stop(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GotoHomePosition command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
SpeedFloatoptionalSpeed in the range of 0.0 to 1.0
letparams={'ProfileToken': '2_def_profile6','Speed': 0.5};device.services.ptz.gotoHomePosition(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a SetHomePosition command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.ptz.setHomePosition(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a SetPreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringoptionala token of the preset
PresetNameStringoptionala name of the preset
letparams={'ProfileToken': '2_def_profile6','PresetName' : 'PresetTest1'};device.services.ptz.setPreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetPresets command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.ptz.getPresets(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GotoPreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringrequireda token of the preset
SpeedObjectrequired
+-xFloatrequiredSpeed of pan (in the range of 0.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of 0.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of 0.0 to 1.0)
letparams={'ProfileToken': '2_def_profile6','PresetToken' : '12','Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.gotoPreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a RemovePreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringrequireda token of the preset
letparams={'ProfileToken': '2_def_profile6','PresetToken' : '12'};device.services.ptz.removePreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF Search Service.

This method sends a GetServiceCapabilities command.

This method sends a GetRecordingSummary command.

This method sends a FindRecordings command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopeObjectrequiredscope defines the dataset to consider for this search
+-IncludedSourcesArrayoptionala list of sources that are included in the scope
+-+-TypeStringoptional
+-+-TokenStringrequired
+-IncludedRecordingsArrayoptionala list of recordings that are included in the scope
+-RecordingInformationFilterStringoptionalan xpath expression used to specify what recordings to search
+-ExtensionStringoptionalextension point
MaxMatchesIntegeroptionalthe search will be completed after this many matches
KeepAliveTimeIntegerrequiredthe time the search session will be kept alive after responding to this and subsequent requests
letparams={'Scope': {'IncludedSources': [{'Type': 'sourceType','Token': 'sourceToken'}],'IncludedRecordings': ['recording1'],'RecordingInformationFilter': 'filter','Extension': 'extension',},'MaxMatches': 3,'KeepAliveTime': 100};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetRecordingSearchResults command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
SearchTokenStringrequiredthe search session to get results from
MinResultsIntegeroptionalthe minimum number of results to return in one response
MaxResultsIntegeroptionalthe maximum number of results to return in one response
WaitTimeIntegeroptionalthe maximum time before responding to the request
letparams={'SearchToken': 'token','MinResults': 3,'MaxResults': 14,'WaitTime': 50};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF Replay Service.

This method sends a GetServiceCapabilities command.

This method sends a GetReplayUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
StreamSetupObjectrequiredthe connection parameters to be used for the stream
+-StreamStringrequiredeither RTP-Unicast, RTP-Multicast
+-TransportObjectrequired
+-+-ProtocolStringrequiredeither UDP, TCP, RTSP, HTTP
+-+-TunnelObjectoptionalTODO not implemented
RecordingTokenStringrequiredidentifier of the recording to be streamed
letparams={'StreamSetup': {'Stream': 'RTP-Unicast','Transport': {'Protocol': 'TCP'},},'RecordingToken': 'token'};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This module is based on the ONVIF specifications:


  • v0.1.7 (2018-08-14)
    • Newly added the lastResponse property to the OnvifDevice object for debug. This property is used to investigate SOAP parse error.
  • v0.1.6 (2018-08-13)
    • Fixed the bug of SOAP name space handling. (Issue #38)
  • v0.1.5 (2018-08-13)
  • v0.1.4 (2018-03-25)
    • Clarified the instruction of the installation in the README.md and Added the engines section to the package.json. (Pull Request #24)
    • Fixed the bug of the loop of SearchDomain. (Pull Request #23)
  • v0.1.3 (2018-02-11)
  • v0.1.0 (2017-08-30)
    • Rewrote all scripts to be modern coding style such as let, const, and Promise. All of the asynchronous methods now return a Promise object.
    • Dramatically improved the discovery processs.
    • Supported the devices which do not support the GetSystemDateAndTime command. In the earlier versions, the init method failed if the targeted device did not support the command. Now the init() method will work well with such devices.
    • The startDiscovery() and stopDiscovery() mehtods became deprecated.
    • Newly added the startProbe() and stopProbe() methods.
    • Appended a failure reason text to an Error.message parsing a SOAP message from a device.
    • Fixed bugs of the OnvifServicePtz.getNode(), OnvifServicePtz.getConfiguration(), and OnvifServicePtz.getConfigurationOptions() methods. The methods sent a wrong SOAP message.
    • Implemented the Speed parameter in the OnvifServicePtz.relativeMove() method.

The MIT License (MIT)

Copyright (c) 2016 - 2018 Futomi Hatano

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

The node-onvif is a Node.js module which allows you to communicate with the network camera which supports the ONVIF specifications.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

55 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

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
    • Search Service
    • Replay 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.

ONVIF Network Camera Manager


Table of Contents


This section shows how to discover ONVIF network cameras, how to get the device information, and how to control the PTZ of the device.

This sample code shows how to discover ONVIF network cameras.

constonvif=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.

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.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.10:80/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.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"
}

This sample code shows how to get the UDP stream URL.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Get the UDP stream URLleturl=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

This sample code shows how to get the data of the snapshot and save it to a file.

constonvif=require('node-onvif');constfs=require('fs');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Get the data of the snapshotconsole.log('fetching the data of the snapshot...');returndevice.fetchSnapshot();}).then((res)=>{// Save the data to a filefs.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.

This sample code shows how to pan, tilt, and zoom the ONVIF network camera.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Move the camerareturndevice.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 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.


In order to use the node-onvif module, you have to load the node-onvif module as follows:

constonvif=require('node-onvif');

The variable onvif in the code above is the Onvif object.

This section describes the methods implemented in the Onvif object.

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:

PropertyTypeDescription
urnStringThe URN (Uniform Resource Name) assigned to the device (e.g., "urn:uuid:6b2be733-6ad1-4467-8bd0-747bd8efd206")
nameStringThe product name of the device (e.g., "Panasonic BB-SC384B").
hardwareStringThe description of the hardware of the device (e.g., "BB-SC384B").
locationStringThe physical location of the device (e.g., "China", "shenzhen", "office").
typesArrayThe list of types supported by the device (e.g., "dn:NetworkVideoTransmitter", "tds:Device"). Basically, this module is for "dn:NetworkVideoTransmitter".
xaddrsArrayThe 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").
scopesArrayThe 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.

constonvif=require('node-onvif');// Find the ONVIF network camerasonvif.startProbe().then((device_list)=>{// Show the information of the found devicesconsole.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"]}]

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.

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:

PropertyTypeDescription
urnStringThe URN (Uniform Resource Name) assigned to the device (e.g., "urn:uuid:6b2be733-6ad1-4467-8bd0-747bd8efd206")
nameStringThe product name of the device (e.g., "Panasonic BB-SC384B").
hardwareStringThe description of the hardware of the device (e.g., "BB-SC384B").
locationStringThe physical location of the device (e.g., "China", "shenzhen", "office").
typesArrayThe list of types supported by the device (e.g., "dn:NetworkVideoTransmitter", "tds:Device"). Basically, this module is for "dn:NetworkVideoTransmitter".
xaddrsArrayThe 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").
scopesArrayThe 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.

constonvif=require('node-onvif');// Find the ONVIF network camerasonvif.startDiscovery((info)=>{// Show the information of the found deviceconsole.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",""]}

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.

constonvif=require('node-onvif');// Start the discovery processonvif.startDiscovery((info)=>{// Do something});// Stop the discovery process in 3 secondssetTimeout(()=>{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();

The OnvifDevice object represents an ONVIF network camera device. You can control the ONVIF network camera through this object.

In order to control an ONVIF network camera, you have to create an OnvifDevice object from the OnvifDevice constructor by yourself as follows:

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.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:

PropertyTypeRequiredDescription
xaddrStringrequiredURL of the end point of the targeted device.
userStringoptionalUser name for the user authentication.
passStringoptionalPassword 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).

The OnvifDevice object provides some properties as follows:

PropertyTypeDescription
servicesObject
+-deviceObjectOnvifServiceDevice object
+-mediaObjectOnvifServiceMedia object
+-ptzObjectOnvifServicePtz object
+-searchObjectOnvifServiceSearch object
+-replayObjectOnvifServiceReplay object

These objects will be set when the initialization process is completed calling the init() method. See the section "ONVIF commands" for details.

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:

PropertyTypeDescription
ManufacturerStringThe manufactor of the device.
ModelStringThe device model.
FirmwareVersionStringThe firmware version in the device.
SerialNumberStringThe serial number of the device.
HardwareIdStringThe hardware ID of the device.
constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '888888'});// Initialize the OnvifDevice objectdevice.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"}

This method returns a hash object consisting of several device information as follow:

PropertyTypeDescription
ManufacturerStringThe manufactor of the device.
ModelStringThe device model.
FirmwareVersionStringThe firmware version in the device.
SerialNumberStringThe serial number of the device.
HardwareIdStringThe 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.

letinfo=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"}

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.

letprofile=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}}}}

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.

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 profileletprofile=device.getCurrentProfile();// Show the video resolution of the current profileletreso=profile['video']['encoder']['resolution'];console.log('- Before: '+reso['width']+' x '+reso['height']);// Get a list of the profiles set in the deviceletprofile_list=device.getProfileList();// Find the profile whose video resolution is the smallestletmin_square=4000*2000;letmin_index=0;for(leti=0;i<profile_list.length;i++){letresolution=profile_list[i]['video']['encoder']['resolution'];letsquare=resolution['width']*resolution['height'];if(square<min_square){min_square=square;min_index=i;}}// Change the current profileprofile=device.changeProfile(min_index);// Show the video resolutionreso=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

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.

leturl=device.getUdpStreamUrl();console.log(url);

The code above will output the result like this:

rtsp://192.168.10.14:10554/tcp/av0_0

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:

PropertyTypeDescription
headersObjectheaders object representing the HTTP response header. This object is of the http module of Node.js.
bodyObjectBuffer 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 extentionletext='bin';letmime_pair=res.headers['content-type'].split('/');if(mime_pair[0]==='image'){ext=mime_pair[1];}// Save the data to a fileletfname='snapshot.'+ext;fs.writeFileSync(fname,res.body,{encoding: 'binary'});console.log('Done!');}).catch((error)=>{console.error(error);});

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:

PropertyTypeRequiredDescription
speedObjectrequired
+-xFloatrequiredSpeed of pan in the range of -1.0 to 1.0.
+-yFloatrequiredSpeed of tilt in the range of -1.0 to 1.0.
+-zFloatrequiredSpeed of zoom in the range of -1.0 to 1.0.
timeoutIntegeroptionalTimeout 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.

letparams={'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 cameradevice.ptzMove(params).then(()=>{console.log('Done!');}).catch((error)=>{console.error(error);});

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 parametersletparams={'speed': {x: 0.5,y: 0.0,z: 0.0},'timeout': 60// seconds};// Supposed to move the camera for 60 secondsdevice.ptzMove(params).then(()=>{console.log('Succeeded to move.');// Stop to the PTZ in 2 secondssetTimeout(()=>{device.ptzStop().then(()=>{console.log('Succeeded to stop.');}).catch((error)=>{console.error(error);});},2000);}).catch((error)=>{console.error(error);});

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 objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// The OnvifServicePtz objectletptz=device.services.ptz;if(!ptz){thrownewError('Your ONVIF network camera does not support the PTZ service.');}// The parameters for the gotoHomePosition() methodletprofile=device.getCurrentProfile();letparams={'ProfileToken': profile['token'],'Speed' : 1};// Send the GotoHomePosition command using the gotoHomePosition() methodreturnptz.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:

PropertyTypeDescription
soapStringRaw SOAP response
formattedStringFormatted SOAP response in order to be human readable
convertedObjectJavaScript object converted from SOAP response by xml2js module
dataObjectJavaScript 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:Envelopexmlns: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><GotoHomePositionResponsexmlns="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:Envelopexmlns: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>
<GotoHomePositionResponsexmlns="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.


This object represents the ONVIF Device Management Service.

This method sends a GetCapabilities command.

This method sends a GetWsdlUrl command.

This method sends a GetDiscoveryMode command.

This method sends a GetScopes command.

This method sends a SetScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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:

letparams={'Scopes': []}

This method sends a AddScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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);});

This method sends a RemoveScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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);});

This method sends a GetHostname command.

This method sends a SetHostname command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NameStringrequireda host name

The code below shows how to set some scopes:

letparams={'Name': 'cam001'};device.services.device.setHostname(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetDNS command.

This method sends a SetDNS command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
FromDHCPbooleanrequiredtrue or false
SearchDomainArrayoptionala list of search domains
DNSManualArrayoptionala list of DNS addresses
+-TypeStringrequired"IPv4" or "IPv6"
+-IPv4AddressStringoptionalIPv4 address
+-IPv6AddressStringoptionalIPv6 address
letparams={'FromDHCP' : false,'SearchDomain': ['futomi.gr.jp','hatano.gr.jp'],'DNSManual' : [{'Type': 'IPv4','IPv4Address': '192.168.10.1'},{'Type': 'IPv4','IPv4Address': '192.168.10.3'}]};returndevice.services.device.setDNS(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetNetworkProtocols command.

This method sends a GetNetworkProtocols command.

This method sends a SetNetworkProtocols command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NetworkProtocolsArrayrequired
+-NameStringrequired
+-EnabledBooleanoptional
+-PortIntegeroptional
letparams={'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);});

This method sends a GetNetworkDefaultGateway command.

This method sends a SetNetworkDefaultGateway command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NetworkGatewayArrayrequireda list of IP addresses of gateways
letparams={'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);});

This method sends a GetDeviceInformation command.

This method sends a GetSystemDateAndTime command.

This method sends a Reboot command.

This method sends a GetUsers command.

This method sends a CreateUsers command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
+-PasswordStringrequiredPassword
+-UserLevelStringrequiredEither "Administrator", "Operator", "User", or "Anonymous"
letparams={'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);});

This method sends a DeleteUsers command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
letparams={'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);});

This method sends a SetUser command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
+-PasswordStringrequiredPassword
+-UserLevelStringrequiredEither "Administrator", "Operator", "User", or "Anonymous"
letparams={'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);});

This method sends a RetRelayOutputs command.

This method sends a GetNTP command.

This method sends a SetNTP command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
FromDHCPBooleanrequiredtrue or false
NTPManualObjectoptional
+-TypeStringrequired"IPv4" or "IPv6"
+-IPv4AddressStringoptionalIPv4 address
+-IPv6AddressStringoptionalIPv6 address
letparams={'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);});

This method sends a GetDynamicDNS command.

This method sends a GetZeroConfiguration command.

This method sends a GetServices command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
IncludeCapabilityBooleanrequiredtrue or false
letparams={'IncludeCapability': true};device.services.device.getServices(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetServiceCapabilities command.


This object represents the ONVIF Media Service.

This method sends a GetStreamUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
ProtocolStringrequired"UDP", "HTTP", or "RTSP"
letparams={'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);});

This method sends a GetVideoEncoderConfigurations command.

This method sends a GetVideoEncoderConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configurationToken
letparams={'ConfigurationToken': '2_def_conf6'};device.services.media.getVideoEncoderConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetCompatibleVideoEncoderConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleVideoEncoderConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoEncoderConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'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);});

This method sends a GetGuaranteedNumberOfVideoEncoderInstances command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': '2_def_conf6',};device.services.media.getGuaranteedNumberOfVideoEncoderInstances(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetProfiles command.

This method sends a GetProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a CreateProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NameStringrequireda name of the profile
TokenStringoptionala token of the profile
letparams={'Name': 'TestProfile1','Token': 'TestProfile1'};device.services.media.createProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a DeleteProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
TokenStringrequireda token of the profile
letparams={'ProfileToken': 'TestProfile1'};device.services.media.deleteProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSources command.

This method sends a GetVideoSourceConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': '2_def_conf6'};device.services.media.getVideoSourceConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSourceConfigurations command.

This method sends a GetCompatibleVideoSourceConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
TokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleVideoSourceConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSourceConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': '2_def_conf6'};device.services.media.getVideoSourceConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'metadata1',};device.services.media.getMetadataConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfigurations command.

This method sends a GetCompatibleMetadataConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleMetadataConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': 'Conf001'};device.services.media.getMetadataConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSources command.

This method sends a GetAudioSourceConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig',};device.services.media.getAudioSourceConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSourceConfigurations command.

This method sends a GetCompatibleAudioSourceConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleAudioSourceConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSourceConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioSourceConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioEncoderConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfigurations command.

This method sends a GetCompatibleAudioEncoderConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleAudioEncoderConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioEncoderConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a getSnapshotUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getSnapshotUri(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF PTZ Service.

This method sends a getNodes command.

This method sends a GetNode command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NodeTokenStringrequireda token of the node
letparams={'NodeToken': 'PtzNode'};device.services.ptz.getNode(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetConfigurations command.

This method sends a GetConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the targeted PTZ configuration
letparams={'ConfigurationToken': 'PtzConf1'};device.services.ptz.getConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the targeted PTZ node
letparams={'ConfigurationToken': 'PtzConf1'};device.services.ptz.getConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetStatus command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the targeted PTZ node
letparams={'ProfileToken': 'PtzConf1'};device.services.ptz.getStatus(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a ContinuousMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
VelocityObjectrequired
+-xFloatrequiredSpeed of pan (in the range of -1.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of -1.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of -1.0 to 1.0)
TimeoutIntengeroptionalTimeout (seconds)
letparams={'ProfileToken': '2_def_profile6','Velocity' : {'x': -1,'y': 0,'z': 0},'Timeout' : 1};device.services.ptz.continuousMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a AbsoluteMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PositionObjectrequired
+-xFloatrequiredPosition of pan (The range depends on the profile)
+-yFloatrequiredPosition of tilt (The range depends on the profile)
+-zFloatrequiredPosition of zoom (The range depends on the profile)
SpeedObjectrequired
+-xFloatrequiredSpeed of pan (in the range of -1.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of -1.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of -1.0 to 1.0)
letparams={'ProfileToken': cam['ProfileToken'],'Position' : {'x': 0,'y': 0,'z': 0.003},'Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.absoluteMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a RelativeMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
TranslationObjectrequired
 | `x` | Float | required | Translation of pan (in the range of -1.0 to 1.0)
| `y` | Float | required | Translation of tilt (in the range of -1.0 to 1.0)
| `z` | Float | required | Translation of zoom (in the range of -1.0 to 1.0)

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)

letparams={'ProfileToken': '2_def_profile6','Translation' : {'x': 0.1,'y': 0.1,'z': 0},'Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.relativeMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a stop command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PanTiltBooleanoptionaltrue or false
ZoomBooleanoptionaltrue or false
letparams={'ProfileToken': '2_def_profile6','PanTilt': true,'Zoom': true};device.services.ptz.stop(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GotoHomePosition command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
SpeedFloatoptionalSpeed in the range of 0.0 to 1.0
letparams={'ProfileToken': '2_def_profile6','Speed': 0.5};device.services.ptz.gotoHomePosition(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a SetHomePosition command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.ptz.setHomePosition(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a SetPreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringoptionala token of the preset
PresetNameStringoptionala name of the preset
letparams={'ProfileToken': '2_def_profile6','PresetName' : 'PresetTest1'};device.services.ptz.setPreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetPresets command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.ptz.getPresets(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GotoPreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringrequireda token of the preset
SpeedObjectrequired
+-xFloatrequiredSpeed of pan (in the range of 0.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of 0.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of 0.0 to 1.0)
letparams={'ProfileToken': '2_def_profile6','PresetToken' : '12','Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.gotoPreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a RemovePreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringrequireda token of the preset
letparams={'ProfileToken': '2_def_profile6','PresetToken' : '12'};device.services.ptz.removePreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF Search Service.

This method sends a GetServiceCapabilities command.

This method sends a GetRecordingSummary command.

This method sends a FindRecordings command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopeObjectrequiredscope defines the dataset to consider for this search
+-IncludedSourcesArrayoptionala list of sources that are included in the scope
+-+-TypeStringoptional
+-+-TokenStringrequired
+-IncludedRecordingsArrayoptionala list of recordings that are included in the scope
+-RecordingInformationFilterStringoptionalan xpath expression used to specify what recordings to search
+-ExtensionStringoptionalextension point
MaxMatchesIntegeroptionalthe search will be completed after this many matches
KeepAliveTimeIntegerrequiredthe time the search session will be kept alive after responding to this and subsequent requests
letparams={'Scope': {'IncludedSources': [{'Type': 'sourceType','Token': 'sourceToken'}],'IncludedRecordings': ['recording1'],'RecordingInformationFilter': 'filter','Extension': 'extension',},'MaxMatches': 3,'KeepAliveTime': 100};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetRecordingSearchResults command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
SearchTokenStringrequiredthe search session to get results from
MinResultsIntegeroptionalthe minimum number of results to return in one response
MaxResultsIntegeroptionalthe maximum number of results to return in one response
WaitTimeIntegeroptionalthe maximum time before responding to the request
letparams={'SearchToken': 'token','MinResults': 3,'MaxResults': 14,'WaitTime': 50};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF Replay Service.

This method sends a GetServiceCapabilities command.

This method sends a GetReplayUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
StreamSetupObjectrequiredthe connection parameters to be used for the stream
+-StreamStringrequiredeither RTP-Unicast, RTP-Multicast
+-TransportObjectrequired
+-+-ProtocolStringrequiredeither UDP, TCP, RTSP, HTTP
+-+-TunnelObjectoptionalTODO not implemented
RecordingTokenStringrequiredidentifier of the recording to be streamed
letparams={'StreamSetup': {'Stream': 'RTP-Unicast','Transport': {'Protocol': 'TCP'},},'RecordingToken': 'token'};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This module is based on the ONVIF specifications:


  • v0.1.7 (2018-08-14)
    • Newly added the lastResponse property to the OnvifDevice object for debug. This property is used to investigate SOAP parse error.
  • v0.1.6 (2018-08-13)
    • Fixed the bug of SOAP name space handling. (Issue #38)
  • v0.1.5 (2018-08-13)
  • v0.1.4 (2018-03-25)
    • Clarified the instruction of the installation in the README.md and Added the engines section to the package.json. (Pull Request #24)
    • Fixed the bug of the loop of SearchDomain. (Pull Request #23)
  • v0.1.3 (2018-02-11)
  • v0.1.0 (2017-08-30)
    • Rewrote all scripts to be modern coding style such as let, const, and Promise. All of the asynchronous methods now return a Promise object.
    • Dramatically improved the discovery processs.
    • Supported the devices which do not support the GetSystemDateAndTime command. In the earlier versions, the init method failed if the targeted device did not support the command. Now the init() method will work well with such devices.
    • The startDiscovery() and stopDiscovery() mehtods became deprecated.
    • Newly added the startProbe() and stopProbe() methods.
    • Appended a failure reason text to an Error.message parsing a SOAP message from a device.
    • Fixed bugs of the OnvifServicePtz.getNode(), OnvifServicePtz.getConfiguration(), and OnvifServicePtz.getConfigurationOptions() methods. The methods sent a wrong SOAP message.
    • Implemented the Speed parameter in the OnvifServicePtz.relativeMove() method.

The MIT License (MIT)

Copyright (c) 2016 - 2018 Futomi Hatano

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

The node-onvif is a Node.js module which allows you to communicate with the network camera which supports the ONVIF specifications.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Latest commit

History

55 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

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
    • Search Service
    • Replay 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.

ONVIF Network Camera Manager


Table of Contents


This section shows how to discover ONVIF network cameras, how to get the device information, and how to control the PTZ of the device.

This sample code shows how to discover ONVIF network cameras.

constonvif=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.

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.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.10:80/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.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"
}

This sample code shows how to get the UDP stream URL.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Get the UDP stream URLleturl=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

This sample code shows how to get the data of the snapshot and save it to a file.

constonvif=require('node-onvif');constfs=require('fs');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Get the data of the snapshotconsole.log('fetching the data of the snapshot...');returndevice.fetchSnapshot();}).then((res)=>{// Save the data to a filefs.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.

This sample code shows how to pan, tilt, and zoom the ONVIF network camera.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Move the camerareturndevice.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 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.


In order to use the node-onvif module, you have to load the node-onvif module as follows:

constonvif=require('node-onvif');

The variable onvif in the code above is the Onvif object.

This section describes the methods implemented in the Onvif object.

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:

PropertyTypeDescription
urnStringThe URN (Uniform Resource Name) assigned to the device (e.g., "urn:uuid:6b2be733-6ad1-4467-8bd0-747bd8efd206")
nameStringThe product name of the device (e.g., "Panasonic BB-SC384B").
hardwareStringThe description of the hardware of the device (e.g., "BB-SC384B").
locationStringThe physical location of the device (e.g., "China", "shenzhen", "office").
typesArrayThe list of types supported by the device (e.g., "dn:NetworkVideoTransmitter", "tds:Device"). Basically, this module is for "dn:NetworkVideoTransmitter".
xaddrsArrayThe 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").
scopesArrayThe 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.

constonvif=require('node-onvif');// Find the ONVIF network camerasonvif.startProbe().then((device_list)=>{// Show the information of the found devicesconsole.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"]}]

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.

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:

PropertyTypeDescription
urnStringThe URN (Uniform Resource Name) assigned to the device (e.g., "urn:uuid:6b2be733-6ad1-4467-8bd0-747bd8efd206")
nameStringThe product name of the device (e.g., "Panasonic BB-SC384B").
hardwareStringThe description of the hardware of the device (e.g., "BB-SC384B").
locationStringThe physical location of the device (e.g., "China", "shenzhen", "office").
typesArrayThe list of types supported by the device (e.g., "dn:NetworkVideoTransmitter", "tds:Device"). Basically, this module is for "dn:NetworkVideoTransmitter".
xaddrsArrayThe 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").
scopesArrayThe 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.

constonvif=require('node-onvif');// Find the ONVIF network camerasonvif.startDiscovery((info)=>{// Show the information of the found deviceconsole.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",""]}

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.

constonvif=require('node-onvif');// Start the discovery processonvif.startDiscovery((info)=>{// Do something});// Stop the discovery process in 3 secondssetTimeout(()=>{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();

The OnvifDevice object represents an ONVIF network camera device. You can control the ONVIF network camera through this object.

In order to control an ONVIF network camera, you have to create an OnvifDevice object from the OnvifDevice constructor by yourself as follows:

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.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:

PropertyTypeRequiredDescription
xaddrStringrequiredURL of the end point of the targeted device.
userStringoptionalUser name for the user authentication.
passStringoptionalPassword 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).

The OnvifDevice object provides some properties as follows:

PropertyTypeDescription
servicesObject
+-deviceObjectOnvifServiceDevice object
+-mediaObjectOnvifServiceMedia object
+-ptzObjectOnvifServicePtz object
+-searchObjectOnvifServiceSearch object
+-replayObjectOnvifServiceReplay object

These objects will be set when the initialization process is completed calling the init() method. See the section "ONVIF commands" for details.

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:

PropertyTypeDescription
ManufacturerStringThe manufactor of the device.
ModelStringThe device model.
FirmwareVersionStringThe firmware version in the device.
SerialNumberStringThe serial number of the device.
HardwareIdStringThe hardware ID of the device.
constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '888888'});// Initialize the OnvifDevice objectdevice.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"}

This method returns a hash object consisting of several device information as follow:

PropertyTypeDescription
ManufacturerStringThe manufactor of the device.
ModelStringThe device model.
FirmwareVersionStringThe firmware version in the device.
SerialNumberStringThe serial number of the device.
HardwareIdStringThe 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.

letinfo=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"}

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.

letprofile=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}}}}

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.

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 profileletprofile=device.getCurrentProfile();// Show the video resolution of the current profileletreso=profile['video']['encoder']['resolution'];console.log('- Before: '+reso['width']+' x '+reso['height']);// Get a list of the profiles set in the deviceletprofile_list=device.getProfileList();// Find the profile whose video resolution is the smallestletmin_square=4000*2000;letmin_index=0;for(leti=0;i<profile_list.length;i++){letresolution=profile_list[i]['video']['encoder']['resolution'];letsquare=resolution['width']*resolution['height'];if(square<min_square){min_square=square;min_index=i;}}// Change the current profileprofile=device.changeProfile(min_index);// Show the video resolutionreso=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

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.

leturl=device.getUdpStreamUrl();console.log(url);

The code above will output the result like this:

rtsp://192.168.10.14:10554/tcp/av0_0

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:

PropertyTypeDescription
headersObjectheaders object representing the HTTP response header. This object is of the http module of Node.js.
bodyObjectBuffer 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 extentionletext='bin';letmime_pair=res.headers['content-type'].split('/');if(mime_pair[0]==='image'){ext=mime_pair[1];}// Save the data to a fileletfname='snapshot.'+ext;fs.writeFileSync(fname,res.body,{encoding: 'binary'});console.log('Done!');}).catch((error)=>{console.error(error);});

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:

PropertyTypeRequiredDescription
speedObjectrequired
+-xFloatrequiredSpeed of pan in the range of -1.0 to 1.0.
+-yFloatrequiredSpeed of tilt in the range of -1.0 to 1.0.
+-zFloatrequiredSpeed of zoom in the range of -1.0 to 1.0.
timeoutIntegeroptionalTimeout 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.

letparams={'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 cameradevice.ptzMove(params).then(()=>{console.log('Done!');}).catch((error)=>{console.error(error);});

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 parametersletparams={'speed': {x: 0.5,y: 0.0,z: 0.0},'timeout': 60// seconds};// Supposed to move the camera for 60 secondsdevice.ptzMove(params).then(()=>{console.log('Succeeded to move.');// Stop to the PTZ in 2 secondssetTimeout(()=>{device.ptzStop().then(()=>{console.log('Succeeded to stop.');}).catch((error)=>{console.error(error);});},2000);}).catch((error)=>{console.error(error);});

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 objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// The OnvifServicePtz objectletptz=device.services.ptz;if(!ptz){thrownewError('Your ONVIF network camera does not support the PTZ service.');}// The parameters for the gotoHomePosition() methodletprofile=device.getCurrentProfile();letparams={'ProfileToken': profile['token'],'Speed' : 1};// Send the GotoHomePosition command using the gotoHomePosition() methodreturnptz.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:

PropertyTypeDescription
soapStringRaw SOAP response
formattedStringFormatted SOAP response in order to be human readable
convertedObjectJavaScript object converted from SOAP response by xml2js module
dataObjectJavaScript 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:Envelopexmlns: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><GotoHomePositionResponsexmlns="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:Envelopexmlns: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>
<GotoHomePositionResponsexmlns="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.


This object represents the ONVIF Device Management Service.

This method sends a GetCapabilities command.

This method sends a GetWsdlUrl command.

This method sends a GetDiscoveryMode command.

This method sends a GetScopes command.

This method sends a SetScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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:

letparams={'Scopes': []}

This method sends a AddScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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);});

This method sends a RemoveScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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);});

This method sends a GetHostname command.

This method sends a SetHostname command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NameStringrequireda host name

The code below shows how to set some scopes:

letparams={'Name': 'cam001'};device.services.device.setHostname(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetDNS command.

This method sends a SetDNS command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
FromDHCPbooleanrequiredtrue or false
SearchDomainArrayoptionala list of search domains
DNSManualArrayoptionala list of DNS addresses
+-TypeStringrequired"IPv4" or "IPv6"
+-IPv4AddressStringoptionalIPv4 address
+-IPv6AddressStringoptionalIPv6 address
letparams={'FromDHCP' : false,'SearchDomain': ['futomi.gr.jp','hatano.gr.jp'],'DNSManual' : [{'Type': 'IPv4','IPv4Address': '192.168.10.1'},{'Type': 'IPv4','IPv4Address': '192.168.10.3'}]};returndevice.services.device.setDNS(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetNetworkProtocols command.

This method sends a GetNetworkProtocols command.

This method sends a SetNetworkProtocols command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NetworkProtocolsArrayrequired
+-NameStringrequired
+-EnabledBooleanoptional
+-PortIntegeroptional
letparams={'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);});

This method sends a GetNetworkDefaultGateway command.

This method sends a SetNetworkDefaultGateway command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NetworkGatewayArrayrequireda list of IP addresses of gateways
letparams={'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);});

This method sends a GetDeviceInformation command.

This method sends a GetSystemDateAndTime command.

This method sends a Reboot command.

This method sends a GetUsers command.

This method sends a CreateUsers command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
+-PasswordStringrequiredPassword
+-UserLevelStringrequiredEither "Administrator", "Operator", "User", or "Anonymous"
letparams={'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);});

This method sends a DeleteUsers command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
letparams={'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);});

This method sends a SetUser command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
+-PasswordStringrequiredPassword
+-UserLevelStringrequiredEither "Administrator", "Operator", "User", or "Anonymous"
letparams={'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);});

This method sends a RetRelayOutputs command.

This method sends a GetNTP command.

This method sends a SetNTP command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
FromDHCPBooleanrequiredtrue or false
NTPManualObjectoptional
+-TypeStringrequired"IPv4" or "IPv6"
+-IPv4AddressStringoptionalIPv4 address
+-IPv6AddressStringoptionalIPv6 address
letparams={'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);});

This method sends a GetDynamicDNS command.

This method sends a GetZeroConfiguration command.

This method sends a GetServices command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
IncludeCapabilityBooleanrequiredtrue or false
letparams={'IncludeCapability': true};device.services.device.getServices(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetServiceCapabilities command.


This object represents the ONVIF Media Service.

This method sends a GetStreamUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
ProtocolStringrequired"UDP", "HTTP", or "RTSP"
letparams={'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);});

This method sends a GetVideoEncoderConfigurations command.

This method sends a GetVideoEncoderConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configurationToken
letparams={'ConfigurationToken': '2_def_conf6'};device.services.media.getVideoEncoderConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetCompatibleVideoEncoderConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleVideoEncoderConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoEncoderConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'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);});

This method sends a GetGuaranteedNumberOfVideoEncoderInstances command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': '2_def_conf6',};device.services.media.getGuaranteedNumberOfVideoEncoderInstances(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetProfiles command.

This method sends a GetProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a CreateProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NameStringrequireda name of the profile
TokenStringoptionala token of the profile
letparams={'Name': 'TestProfile1','Token': 'TestProfile1'};device.services.media.createProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a DeleteProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
TokenStringrequireda token of the profile
letparams={'ProfileToken': 'TestProfile1'};device.services.media.deleteProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSources command.

This method sends a GetVideoSourceConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': '2_def_conf6'};device.services.media.getVideoSourceConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSourceConfigurations command.

This method sends a GetCompatibleVideoSourceConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
TokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleVideoSourceConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSourceConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': '2_def_conf6'};device.services.media.getVideoSourceConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'metadata1',};device.services.media.getMetadataConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfigurations command.

This method sends a GetCompatibleMetadataConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleMetadataConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': 'Conf001'};device.services.media.getMetadataConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSources command.

This method sends a GetAudioSourceConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig',};device.services.media.getAudioSourceConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSourceConfigurations command.

This method sends a GetCompatibleAudioSourceConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleAudioSourceConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSourceConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioSourceConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioEncoderConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfigurations command.

This method sends a GetCompatibleAudioEncoderConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleAudioEncoderConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioEncoderConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a getSnapshotUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getSnapshotUri(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF PTZ Service.

This method sends a getNodes command.

This method sends a GetNode command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NodeTokenStringrequireda token of the node
letparams={'NodeToken': 'PtzNode'};device.services.ptz.getNode(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetConfigurations command.

This method sends a GetConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the targeted PTZ configuration
letparams={'ConfigurationToken': 'PtzConf1'};device.services.ptz.getConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the targeted PTZ node
letparams={'ConfigurationToken': 'PtzConf1'};device.services.ptz.getConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetStatus command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the targeted PTZ node
letparams={'ProfileToken': 'PtzConf1'};device.services.ptz.getStatus(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a ContinuousMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
VelocityObjectrequired
+-xFloatrequiredSpeed of pan (in the range of -1.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of -1.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of -1.0 to 1.0)
TimeoutIntengeroptionalTimeout (seconds)
letparams={'ProfileToken': '2_def_profile6','Velocity' : {'x': -1,'y': 0,'z': 0},'Timeout' : 1};device.services.ptz.continuousMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a AbsoluteMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PositionObjectrequired
+-xFloatrequiredPosition of pan (The range depends on the profile)
+-yFloatrequiredPosition of tilt (The range depends on the profile)
+-zFloatrequiredPosition of zoom (The range depends on the profile)
SpeedObjectrequired
+-xFloatrequiredSpeed of pan (in the range of -1.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of -1.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of -1.0 to 1.0)
letparams={'ProfileToken': cam['ProfileToken'],'Position' : {'x': 0,'y': 0,'z': 0.003},'Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.absoluteMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a RelativeMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
TranslationObjectrequired
 | `x` | Float | required | Translation of pan (in the range of -1.0 to 1.0)
| `y` | Float | required | Translation of tilt (in the range of -1.0 to 1.0)
| `z` | Float | required | Translation of zoom (in the range of -1.0 to 1.0)

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)

letparams={'ProfileToken': '2_def_profile6','Translation' : {'x': 0.1,'y': 0.1,'z': 0},'Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.relativeMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a stop command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PanTiltBooleanoptionaltrue or false
ZoomBooleanoptionaltrue or false
letparams={'ProfileToken': '2_def_profile6','PanTilt': true,'Zoom': true};device.services.ptz.stop(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GotoHomePosition command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
SpeedFloatoptionalSpeed in the range of 0.0 to 1.0
letparams={'ProfileToken': '2_def_profile6','Speed': 0.5};device.services.ptz.gotoHomePosition(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a SetHomePosition command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.ptz.setHomePosition(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a SetPreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringoptionala token of the preset
PresetNameStringoptionala name of the preset
letparams={'ProfileToken': '2_def_profile6','PresetName' : 'PresetTest1'};device.services.ptz.setPreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetPresets command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.ptz.getPresets(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GotoPreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringrequireda token of the preset
SpeedObjectrequired
+-xFloatrequiredSpeed of pan (in the range of 0.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of 0.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of 0.0 to 1.0)
letparams={'ProfileToken': '2_def_profile6','PresetToken' : '12','Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.gotoPreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a RemovePreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringrequireda token of the preset
letparams={'ProfileToken': '2_def_profile6','PresetToken' : '12'};device.services.ptz.removePreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF Search Service.

This method sends a GetServiceCapabilities command.

This method sends a GetRecordingSummary command.

This method sends a FindRecordings command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopeObjectrequiredscope defines the dataset to consider for this search
+-IncludedSourcesArrayoptionala list of sources that are included in the scope
+-+-TypeStringoptional
+-+-TokenStringrequired
+-IncludedRecordingsArrayoptionala list of recordings that are included in the scope
+-RecordingInformationFilterStringoptionalan xpath expression used to specify what recordings to search
+-ExtensionStringoptionalextension point
MaxMatchesIntegeroptionalthe search will be completed after this many matches
KeepAliveTimeIntegerrequiredthe time the search session will be kept alive after responding to this and subsequent requests
letparams={'Scope': {'IncludedSources': [{'Type': 'sourceType','Token': 'sourceToken'}],'IncludedRecordings': ['recording1'],'RecordingInformationFilter': 'filter','Extension': 'extension',},'MaxMatches': 3,'KeepAliveTime': 100};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetRecordingSearchResults command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
SearchTokenStringrequiredthe search session to get results from
MinResultsIntegeroptionalthe minimum number of results to return in one response
MaxResultsIntegeroptionalthe maximum number of results to return in one response
WaitTimeIntegeroptionalthe maximum time before responding to the request
letparams={'SearchToken': 'token','MinResults': 3,'MaxResults': 14,'WaitTime': 50};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF Replay Service.

This method sends a GetServiceCapabilities command.

This method sends a GetReplayUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
StreamSetupObjectrequiredthe connection parameters to be used for the stream
+-StreamStringrequiredeither RTP-Unicast, RTP-Multicast
+-TransportObjectrequired
+-+-ProtocolStringrequiredeither UDP, TCP, RTSP, HTTP
+-+-TunnelObjectoptionalTODO not implemented
RecordingTokenStringrequiredidentifier of the recording to be streamed
letparams={'StreamSetup': {'Stream': 'RTP-Unicast','Transport': {'Protocol': 'TCP'},},'RecordingToken': 'token'};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This module is based on the ONVIF specifications:


  • v0.1.7 (2018-08-14)
    • Newly added the lastResponse property to the OnvifDevice object for debug. This property is used to investigate SOAP parse error.
  • v0.1.6 (2018-08-13)
    • Fixed the bug of SOAP name space handling. (Issue #38)
  • v0.1.5 (2018-08-13)
  • v0.1.4 (2018-03-25)
    • Clarified the instruction of the installation in the README.md and Added the engines section to the package.json. (Pull Request #24)
    • Fixed the bug of the loop of SearchDomain. (Pull Request #23)
  • v0.1.3 (2018-02-11)
  • v0.1.0 (2017-08-30)
    • Rewrote all scripts to be modern coding style such as let, const, and Promise. All of the asynchronous methods now return a Promise object.
    • Dramatically improved the discovery processs.
    • Supported the devices which do not support the GetSystemDateAndTime command. In the earlier versions, the init method failed if the targeted device did not support the command. Now the init() method will work well with such devices.
    • The startDiscovery() and stopDiscovery() mehtods became deprecated.
    • Newly added the startProbe() and stopProbe() methods.
    • Appended a failure reason text to an Error.message parsing a SOAP message from a device.
    • Fixed bugs of the OnvifServicePtz.getNode(), OnvifServicePtz.getConfiguration(), and OnvifServicePtz.getConfigurationOptions() methods. The methods sent a wrong SOAP message.
    • Implemented the Speed parameter in the OnvifServicePtz.relativeMove() method.

The MIT License (MIT)

Copyright (c) 2016 - 2018 Futomi Hatano

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

The node-onvif is a Node.js module which allows you to communicate with the network camera which supports the ONVIF specifications.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

55 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

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
    • Search Service
    • Replay 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.

ONVIF Network Camera Manager


Table of Contents


This section shows how to discover ONVIF network cameras, how to get the device information, and how to control the PTZ of the device.

This sample code shows how to discover ONVIF network cameras.

constonvif=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.

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.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.10:80/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.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"
}

This sample code shows how to get the UDP stream URL.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Get the UDP stream URLleturl=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

This sample code shows how to get the data of the snapshot and save it to a file.

constonvif=require('node-onvif');constfs=require('fs');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Get the data of the snapshotconsole.log('fetching the data of the snapshot...');returndevice.fetchSnapshot();}).then((res)=>{// Save the data to a filefs.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.

This sample code shows how to pan, tilt, and zoom the ONVIF network camera.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Move the camerareturndevice.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 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.


In order to use the node-onvif module, you have to load the node-onvif module as follows:

constonvif=require('node-onvif');

The variable onvif in the code above is the Onvif object.

This section describes the methods implemented in the Onvif object.

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:

PropertyTypeDescription
urnStringThe URN (Uniform Resource Name) assigned to the device (e.g., "urn:uuid:6b2be733-6ad1-4467-8bd0-747bd8efd206")
nameStringThe product name of the device (e.g., "Panasonic BB-SC384B").
hardwareStringThe description of the hardware of the device (e.g., "BB-SC384B").
locationStringThe physical location of the device (e.g., "China", "shenzhen", "office").
typesArrayThe list of types supported by the device (e.g., "dn:NetworkVideoTransmitter", "tds:Device"). Basically, this module is for "dn:NetworkVideoTransmitter".
xaddrsArrayThe 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").
scopesArrayThe 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.

constonvif=require('node-onvif');// Find the ONVIF network camerasonvif.startProbe().then((device_list)=>{// Show the information of the found devicesconsole.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"]}]

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.

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:

PropertyTypeDescription
urnStringThe URN (Uniform Resource Name) assigned to the device (e.g., "urn:uuid:6b2be733-6ad1-4467-8bd0-747bd8efd206")
nameStringThe product name of the device (e.g., "Panasonic BB-SC384B").
hardwareStringThe description of the hardware of the device (e.g., "BB-SC384B").
locationStringThe physical location of the device (e.g., "China", "shenzhen", "office").
typesArrayThe list of types supported by the device (e.g., "dn:NetworkVideoTransmitter", "tds:Device"). Basically, this module is for "dn:NetworkVideoTransmitter".
xaddrsArrayThe 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").
scopesArrayThe 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.

constonvif=require('node-onvif');// Find the ONVIF network camerasonvif.startDiscovery((info)=>{// Show the information of the found deviceconsole.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",""]}

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.

constonvif=require('node-onvif');// Start the discovery processonvif.startDiscovery((info)=>{// Do something});// Stop the discovery process in 3 secondssetTimeout(()=>{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();

The OnvifDevice object represents an ONVIF network camera device. You can control the ONVIF network camera through this object.

In order to control an ONVIF network camera, you have to create an OnvifDevice object from the OnvifDevice constructor by yourself as follows:

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.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:

PropertyTypeRequiredDescription
xaddrStringrequiredURL of the end point of the targeted device.
userStringoptionalUser name for the user authentication.
passStringoptionalPassword 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).

The OnvifDevice object provides some properties as follows:

PropertyTypeDescription
servicesObject
+-deviceObjectOnvifServiceDevice object
+-mediaObjectOnvifServiceMedia object
+-ptzObjectOnvifServicePtz object
+-searchObjectOnvifServiceSearch object
+-replayObjectOnvifServiceReplay object

These objects will be set when the initialization process is completed calling the init() method. See the section "ONVIF commands" for details.

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:

PropertyTypeDescription
ManufacturerStringThe manufactor of the device.
ModelStringThe device model.
FirmwareVersionStringThe firmware version in the device.
SerialNumberStringThe serial number of the device.
HardwareIdStringThe hardware ID of the device.
constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '888888'});// Initialize the OnvifDevice objectdevice.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"}

This method returns a hash object consisting of several device information as follow:

PropertyTypeDescription
ManufacturerStringThe manufactor of the device.
ModelStringThe device model.
FirmwareVersionStringThe firmware version in the device.
SerialNumberStringThe serial number of the device.
HardwareIdStringThe 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.

letinfo=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"}

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.

letprofile=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}}}}

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.

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 profileletprofile=device.getCurrentProfile();// Show the video resolution of the current profileletreso=profile['video']['encoder']['resolution'];console.log('- Before: '+reso['width']+' x '+reso['height']);// Get a list of the profiles set in the deviceletprofile_list=device.getProfileList();// Find the profile whose video resolution is the smallestletmin_square=4000*2000;letmin_index=0;for(leti=0;i<profile_list.length;i++){letresolution=profile_list[i]['video']['encoder']['resolution'];letsquare=resolution['width']*resolution['height'];if(square<min_square){min_square=square;min_index=i;}}// Change the current profileprofile=device.changeProfile(min_index);// Show the video resolutionreso=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

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.

leturl=device.getUdpStreamUrl();console.log(url);

The code above will output the result like this:

rtsp://192.168.10.14:10554/tcp/av0_0

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:

PropertyTypeDescription
headersObjectheaders object representing the HTTP response header. This object is of the http module of Node.js.
bodyObjectBuffer 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 extentionletext='bin';letmime_pair=res.headers['content-type'].split('/');if(mime_pair[0]==='image'){ext=mime_pair[1];}// Save the data to a fileletfname='snapshot.'+ext;fs.writeFileSync(fname,res.body,{encoding: 'binary'});console.log('Done!');}).catch((error)=>{console.error(error);});

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:

PropertyTypeRequiredDescription
speedObjectrequired
+-xFloatrequiredSpeed of pan in the range of -1.0 to 1.0.
+-yFloatrequiredSpeed of tilt in the range of -1.0 to 1.0.
+-zFloatrequiredSpeed of zoom in the range of -1.0 to 1.0.
timeoutIntegeroptionalTimeout 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.

letparams={'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 cameradevice.ptzMove(params).then(()=>{console.log('Done!');}).catch((error)=>{console.error(error);});

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 parametersletparams={'speed': {x: 0.5,y: 0.0,z: 0.0},'timeout': 60// seconds};// Supposed to move the camera for 60 secondsdevice.ptzMove(params).then(()=>{console.log('Succeeded to move.');// Stop to the PTZ in 2 secondssetTimeout(()=>{device.ptzStop().then(()=>{console.log('Succeeded to stop.');}).catch((error)=>{console.error(error);});},2000);}).catch((error)=>{console.error(error);});

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 objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// The OnvifServicePtz objectletptz=device.services.ptz;if(!ptz){thrownewError('Your ONVIF network camera does not support the PTZ service.');}// The parameters for the gotoHomePosition() methodletprofile=device.getCurrentProfile();letparams={'ProfileToken': profile['token'],'Speed' : 1};// Send the GotoHomePosition command using the gotoHomePosition() methodreturnptz.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:

PropertyTypeDescription
soapStringRaw SOAP response
formattedStringFormatted SOAP response in order to be human readable
convertedObjectJavaScript object converted from SOAP response by xml2js module
dataObjectJavaScript 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:Envelopexmlns: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><GotoHomePositionResponsexmlns="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:Envelopexmlns: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>
<GotoHomePositionResponsexmlns="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.


This object represents the ONVIF Device Management Service.

This method sends a GetCapabilities command.

This method sends a GetWsdlUrl command.

This method sends a GetDiscoveryMode command.

This method sends a GetScopes command.

This method sends a SetScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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:

letparams={'Scopes': []}

This method sends a AddScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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);});

This method sends a RemoveScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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);});

This method sends a GetHostname command.

This method sends a SetHostname command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NameStringrequireda host name

The code below shows how to set some scopes:

letparams={'Name': 'cam001'};device.services.device.setHostname(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetDNS command.

This method sends a SetDNS command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
FromDHCPbooleanrequiredtrue or false
SearchDomainArrayoptionala list of search domains
DNSManualArrayoptionala list of DNS addresses
+-TypeStringrequired"IPv4" or "IPv6"
+-IPv4AddressStringoptionalIPv4 address
+-IPv6AddressStringoptionalIPv6 address
letparams={'FromDHCP' : false,'SearchDomain': ['futomi.gr.jp','hatano.gr.jp'],'DNSManual' : [{'Type': 'IPv4','IPv4Address': '192.168.10.1'},{'Type': 'IPv4','IPv4Address': '192.168.10.3'}]};returndevice.services.device.setDNS(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetNetworkProtocols command.

This method sends a GetNetworkProtocols command.

This method sends a SetNetworkProtocols command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NetworkProtocolsArrayrequired
+-NameStringrequired
+-EnabledBooleanoptional
+-PortIntegeroptional
letparams={'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);});

This method sends a GetNetworkDefaultGateway command.

This method sends a SetNetworkDefaultGateway command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NetworkGatewayArrayrequireda list of IP addresses of gateways
letparams={'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);});

This method sends a GetDeviceInformation command.

This method sends a GetSystemDateAndTime command.

This method sends a Reboot command.

This method sends a GetUsers command.

This method sends a CreateUsers command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
+-PasswordStringrequiredPassword
+-UserLevelStringrequiredEither "Administrator", "Operator", "User", or "Anonymous"
letparams={'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);});

This method sends a DeleteUsers command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
letparams={'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);});

This method sends a SetUser command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
+-PasswordStringrequiredPassword
+-UserLevelStringrequiredEither "Administrator", "Operator", "User", or "Anonymous"
letparams={'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);});

This method sends a RetRelayOutputs command.

This method sends a GetNTP command.

This method sends a SetNTP command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
FromDHCPBooleanrequiredtrue or false
NTPManualObjectoptional
+-TypeStringrequired"IPv4" or "IPv6"
+-IPv4AddressStringoptionalIPv4 address
+-IPv6AddressStringoptionalIPv6 address
letparams={'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);});

This method sends a GetDynamicDNS command.

This method sends a GetZeroConfiguration command.

This method sends a GetServices command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
IncludeCapabilityBooleanrequiredtrue or false
letparams={'IncludeCapability': true};device.services.device.getServices(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetServiceCapabilities command.


This object represents the ONVIF Media Service.

This method sends a GetStreamUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
ProtocolStringrequired"UDP", "HTTP", or "RTSP"
letparams={'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);});

This method sends a GetVideoEncoderConfigurations command.

This method sends a GetVideoEncoderConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configurationToken
letparams={'ConfigurationToken': '2_def_conf6'};device.services.media.getVideoEncoderConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetCompatibleVideoEncoderConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleVideoEncoderConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoEncoderConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'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);});

This method sends a GetGuaranteedNumberOfVideoEncoderInstances command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': '2_def_conf6',};device.services.media.getGuaranteedNumberOfVideoEncoderInstances(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetProfiles command.

This method sends a GetProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a CreateProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NameStringrequireda name of the profile
TokenStringoptionala token of the profile
letparams={'Name': 'TestProfile1','Token': 'TestProfile1'};device.services.media.createProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a DeleteProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
TokenStringrequireda token of the profile
letparams={'ProfileToken': 'TestProfile1'};device.services.media.deleteProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSources command.

This method sends a GetVideoSourceConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': '2_def_conf6'};device.services.media.getVideoSourceConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSourceConfigurations command.

This method sends a GetCompatibleVideoSourceConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
TokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleVideoSourceConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSourceConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': '2_def_conf6'};device.services.media.getVideoSourceConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'metadata1',};device.services.media.getMetadataConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfigurations command.

This method sends a GetCompatibleMetadataConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleMetadataConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': 'Conf001'};device.services.media.getMetadataConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSources command.

This method sends a GetAudioSourceConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig',};device.services.media.getAudioSourceConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSourceConfigurations command.

This method sends a GetCompatibleAudioSourceConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleAudioSourceConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSourceConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioSourceConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioEncoderConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfigurations command.

This method sends a GetCompatibleAudioEncoderConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleAudioEncoderConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioEncoderConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a getSnapshotUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getSnapshotUri(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF PTZ Service.

This method sends a getNodes command.

This method sends a GetNode command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NodeTokenStringrequireda token of the node
letparams={'NodeToken': 'PtzNode'};device.services.ptz.getNode(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetConfigurations command.

This method sends a GetConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the targeted PTZ configuration
letparams={'ConfigurationToken': 'PtzConf1'};device.services.ptz.getConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the targeted PTZ node
letparams={'ConfigurationToken': 'PtzConf1'};device.services.ptz.getConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetStatus command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the targeted PTZ node
letparams={'ProfileToken': 'PtzConf1'};device.services.ptz.getStatus(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a ContinuousMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
VelocityObjectrequired
+-xFloatrequiredSpeed of pan (in the range of -1.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of -1.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of -1.0 to 1.0)
TimeoutIntengeroptionalTimeout (seconds)
letparams={'ProfileToken': '2_def_profile6','Velocity' : {'x': -1,'y': 0,'z': 0},'Timeout' : 1};device.services.ptz.continuousMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a AbsoluteMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PositionObjectrequired
+-xFloatrequiredPosition of pan (The range depends on the profile)
+-yFloatrequiredPosition of tilt (The range depends on the profile)
+-zFloatrequiredPosition of zoom (The range depends on the profile)
SpeedObjectrequired
+-xFloatrequiredSpeed of pan (in the range of -1.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of -1.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of -1.0 to 1.0)
letparams={'ProfileToken': cam['ProfileToken'],'Position' : {'x': 0,'y': 0,'z': 0.003},'Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.absoluteMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a RelativeMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
TranslationObjectrequired
 | `x` | Float | required | Translation of pan (in the range of -1.0 to 1.0)
| `y` | Float | required | Translation of tilt (in the range of -1.0 to 1.0)
| `z` | Float | required | Translation of zoom (in the range of -1.0 to 1.0)

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)

letparams={'ProfileToken': '2_def_profile6','Translation' : {'x': 0.1,'y': 0.1,'z': 0},'Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.relativeMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a stop command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PanTiltBooleanoptionaltrue or false
ZoomBooleanoptionaltrue or false
letparams={'ProfileToken': '2_def_profile6','PanTilt': true,'Zoom': true};device.services.ptz.stop(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GotoHomePosition command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
SpeedFloatoptionalSpeed in the range of 0.0 to 1.0
letparams={'ProfileToken': '2_def_profile6','Speed': 0.5};device.services.ptz.gotoHomePosition(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a SetHomePosition command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.ptz.setHomePosition(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a SetPreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringoptionala token of the preset
PresetNameStringoptionala name of the preset
letparams={'ProfileToken': '2_def_profile6','PresetName' : 'PresetTest1'};device.services.ptz.setPreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetPresets command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.ptz.getPresets(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GotoPreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringrequireda token of the preset
SpeedObjectrequired
+-xFloatrequiredSpeed of pan (in the range of 0.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of 0.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of 0.0 to 1.0)
letparams={'ProfileToken': '2_def_profile6','PresetToken' : '12','Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.gotoPreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a RemovePreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringrequireda token of the preset
letparams={'ProfileToken': '2_def_profile6','PresetToken' : '12'};device.services.ptz.removePreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF Search Service.

This method sends a GetServiceCapabilities command.

This method sends a GetRecordingSummary command.

This method sends a FindRecordings command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopeObjectrequiredscope defines the dataset to consider for this search
+-IncludedSourcesArrayoptionala list of sources that are included in the scope
+-+-TypeStringoptional
+-+-TokenStringrequired
+-IncludedRecordingsArrayoptionala list of recordings that are included in the scope
+-RecordingInformationFilterStringoptionalan xpath expression used to specify what recordings to search
+-ExtensionStringoptionalextension point
MaxMatchesIntegeroptionalthe search will be completed after this many matches
KeepAliveTimeIntegerrequiredthe time the search session will be kept alive after responding to this and subsequent requests
letparams={'Scope': {'IncludedSources': [{'Type': 'sourceType','Token': 'sourceToken'}],'IncludedRecordings': ['recording1'],'RecordingInformationFilter': 'filter','Extension': 'extension',},'MaxMatches': 3,'KeepAliveTime': 100};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetRecordingSearchResults command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
SearchTokenStringrequiredthe search session to get results from
MinResultsIntegeroptionalthe minimum number of results to return in one response
MaxResultsIntegeroptionalthe maximum number of results to return in one response
WaitTimeIntegeroptionalthe maximum time before responding to the request
letparams={'SearchToken': 'token','MinResults': 3,'MaxResults': 14,'WaitTime': 50};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF Replay Service.

This method sends a GetServiceCapabilities command.

This method sends a GetReplayUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
StreamSetupObjectrequiredthe connection parameters to be used for the stream
+-StreamStringrequiredeither RTP-Unicast, RTP-Multicast
+-TransportObjectrequired
+-+-ProtocolStringrequiredeither UDP, TCP, RTSP, HTTP
+-+-TunnelObjectoptionalTODO not implemented
RecordingTokenStringrequiredidentifier of the recording to be streamed
letparams={'StreamSetup': {'Stream': 'RTP-Unicast','Transport': {'Protocol': 'TCP'},},'RecordingToken': 'token'};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This module is based on the ONVIF specifications:


  • v0.1.7 (2018-08-14)
    • Newly added the lastResponse property to the OnvifDevice object for debug. This property is used to investigate SOAP parse error.
  • v0.1.6 (2018-08-13)
    • Fixed the bug of SOAP name space handling. (Issue #38)
  • v0.1.5 (2018-08-13)
  • v0.1.4 (2018-03-25)
    • Clarified the instruction of the installation in the README.md and Added the engines section to the package.json. (Pull Request #24)
    • Fixed the bug of the loop of SearchDomain. (Pull Request #23)
  • v0.1.3 (2018-02-11)
  • v0.1.0 (2017-08-30)
    • Rewrote all scripts to be modern coding style such as let, const, and Promise. All of the asynchronous methods now return a Promise object.
    • Dramatically improved the discovery processs.
    • Supported the devices which do not support the GetSystemDateAndTime command. In the earlier versions, the init method failed if the targeted device did not support the command. Now the init() method will work well with such devices.
    • The startDiscovery() and stopDiscovery() mehtods became deprecated.
    • Newly added the startProbe() and stopProbe() methods.
    • Appended a failure reason text to an Error.message parsing a SOAP message from a device.
    • Fixed bugs of the OnvifServicePtz.getNode(), OnvifServicePtz.getConfiguration(), and OnvifServicePtz.getConfigurationOptions() methods. The methods sent a wrong SOAP message.
    • Implemented the Speed parameter in the OnvifServicePtz.relativeMove() method.

The MIT License (MIT)

Copyright (c) 2016 - 2018 Futomi Hatano

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

The node-onvif is a Node.js module which allows you to communicate with the network camera which supports the ONVIF specifications.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

55 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

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
    • Search Service
    • Replay 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.

ONVIF Network Camera Manager


Table of Contents


This section shows how to discover ONVIF network cameras, how to get the device information, and how to control the PTZ of the device.

This sample code shows how to discover ONVIF network cameras.

constonvif=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.

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.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.10:80/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.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"
}

This sample code shows how to get the UDP stream URL.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Get the UDP stream URLleturl=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

This sample code shows how to get the data of the snapshot and save it to a file.

constonvif=require('node-onvif');constfs=require('fs');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Get the data of the snapshotconsole.log('fetching the data of the snapshot...');returndevice.fetchSnapshot();}).then((res)=>{// Save the data to a filefs.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.

This sample code shows how to pan, tilt, and zoom the ONVIF network camera.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Move the camerareturndevice.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 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.


In order to use the node-onvif module, you have to load the node-onvif module as follows:

constonvif=require('node-onvif');

The variable onvif in the code above is the Onvif object.

This section describes the methods implemented in the Onvif object.

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:

PropertyTypeDescription
urnStringThe URN (Uniform Resource Name) assigned to the device (e.g., "urn:uuid:6b2be733-6ad1-4467-8bd0-747bd8efd206")
nameStringThe product name of the device (e.g., "Panasonic BB-SC384B").
hardwareStringThe description of the hardware of the device (e.g., "BB-SC384B").
locationStringThe physical location of the device (e.g., "China", "shenzhen", "office").
typesArrayThe list of types supported by the device (e.g., "dn:NetworkVideoTransmitter", "tds:Device"). Basically, this module is for "dn:NetworkVideoTransmitter".
xaddrsArrayThe 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").
scopesArrayThe 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.

constonvif=require('node-onvif');// Find the ONVIF network camerasonvif.startProbe().then((device_list)=>{// Show the information of the found devicesconsole.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"]}]

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.

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:

PropertyTypeDescription
urnStringThe URN (Uniform Resource Name) assigned to the device (e.g., "urn:uuid:6b2be733-6ad1-4467-8bd0-747bd8efd206")
nameStringThe product name of the device (e.g., "Panasonic BB-SC384B").
hardwareStringThe description of the hardware of the device (e.g., "BB-SC384B").
locationStringThe physical location of the device (e.g., "China", "shenzhen", "office").
typesArrayThe list of types supported by the device (e.g., "dn:NetworkVideoTransmitter", "tds:Device"). Basically, this module is for "dn:NetworkVideoTransmitter".
xaddrsArrayThe 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").
scopesArrayThe 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.

constonvif=require('node-onvif');// Find the ONVIF network camerasonvif.startDiscovery((info)=>{// Show the information of the found deviceconsole.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",""]}

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.

constonvif=require('node-onvif');// Start the discovery processonvif.startDiscovery((info)=>{// Do something});// Stop the discovery process in 3 secondssetTimeout(()=>{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();

The OnvifDevice object represents an ONVIF network camera device. You can control the ONVIF network camera through this object.

In order to control an ONVIF network camera, you have to create an OnvifDevice object from the OnvifDevice constructor by yourself as follows:

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.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:

PropertyTypeRequiredDescription
xaddrStringrequiredURL of the end point of the targeted device.
userStringoptionalUser name for the user authentication.
passStringoptionalPassword 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).

The OnvifDevice object provides some properties as follows:

PropertyTypeDescription
servicesObject
+-deviceObjectOnvifServiceDevice object
+-mediaObjectOnvifServiceMedia object
+-ptzObjectOnvifServicePtz object
+-searchObjectOnvifServiceSearch object
+-replayObjectOnvifServiceReplay object

These objects will be set when the initialization process is completed calling the init() method. See the section "ONVIF commands" for details.

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:

PropertyTypeDescription
ManufacturerStringThe manufactor of the device.
ModelStringThe device model.
FirmwareVersionStringThe firmware version in the device.
SerialNumberStringThe serial number of the device.
HardwareIdStringThe hardware ID of the device.
constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '888888'});// Initialize the OnvifDevice objectdevice.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"}

This method returns a hash object consisting of several device information as follow:

PropertyTypeDescription
ManufacturerStringThe manufactor of the device.
ModelStringThe device model.
FirmwareVersionStringThe firmware version in the device.
SerialNumberStringThe serial number of the device.
HardwareIdStringThe 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.

letinfo=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"}

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.

letprofile=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}}}}

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.

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 profileletprofile=device.getCurrentProfile();// Show the video resolution of the current profileletreso=profile['video']['encoder']['resolution'];console.log('- Before: '+reso['width']+' x '+reso['height']);// Get a list of the profiles set in the deviceletprofile_list=device.getProfileList();// Find the profile whose video resolution is the smallestletmin_square=4000*2000;letmin_index=0;for(leti=0;i<profile_list.length;i++){letresolution=profile_list[i]['video']['encoder']['resolution'];letsquare=resolution['width']*resolution['height'];if(square<min_square){min_square=square;min_index=i;}}// Change the current profileprofile=device.changeProfile(min_index);// Show the video resolutionreso=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

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.

leturl=device.getUdpStreamUrl();console.log(url);

The code above will output the result like this:

rtsp://192.168.10.14:10554/tcp/av0_0

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:

PropertyTypeDescription
headersObjectheaders object representing the HTTP response header. This object is of the http module of Node.js.
bodyObjectBuffer 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 extentionletext='bin';letmime_pair=res.headers['content-type'].split('/');if(mime_pair[0]==='image'){ext=mime_pair[1];}// Save the data to a fileletfname='snapshot.'+ext;fs.writeFileSync(fname,res.body,{encoding: 'binary'});console.log('Done!');}).catch((error)=>{console.error(error);});

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:

PropertyTypeRequiredDescription
speedObjectrequired
+-xFloatrequiredSpeed of pan in the range of -1.0 to 1.0.
+-yFloatrequiredSpeed of tilt in the range of -1.0 to 1.0.
+-zFloatrequiredSpeed of zoom in the range of -1.0 to 1.0.
timeoutIntegeroptionalTimeout 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.

letparams={'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 cameradevice.ptzMove(params).then(()=>{console.log('Done!');}).catch((error)=>{console.error(error);});

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 parametersletparams={'speed': {x: 0.5,y: 0.0,z: 0.0},'timeout': 60// seconds};// Supposed to move the camera for 60 secondsdevice.ptzMove(params).then(()=>{console.log('Succeeded to move.');// Stop to the PTZ in 2 secondssetTimeout(()=>{device.ptzStop().then(()=>{console.log('Succeeded to stop.');}).catch((error)=>{console.error(error);});},2000);}).catch((error)=>{console.error(error);});

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 objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// The OnvifServicePtz objectletptz=device.services.ptz;if(!ptz){thrownewError('Your ONVIF network camera does not support the PTZ service.');}// The parameters for the gotoHomePosition() methodletprofile=device.getCurrentProfile();letparams={'ProfileToken': profile['token'],'Speed' : 1};// Send the GotoHomePosition command using the gotoHomePosition() methodreturnptz.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:

PropertyTypeDescription
soapStringRaw SOAP response
formattedStringFormatted SOAP response in order to be human readable
convertedObjectJavaScript object converted from SOAP response by xml2js module
dataObjectJavaScript 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:Envelopexmlns: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><GotoHomePositionResponsexmlns="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:Envelopexmlns: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>
<GotoHomePositionResponsexmlns="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.


This object represents the ONVIF Device Management Service.

This method sends a GetCapabilities command.

This method sends a GetWsdlUrl command.

This method sends a GetDiscoveryMode command.

This method sends a GetScopes command.

This method sends a SetScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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:

letparams={'Scopes': []}

This method sends a AddScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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);});

This method sends a RemoveScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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);});

This method sends a GetHostname command.

This method sends a SetHostname command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NameStringrequireda host name

The code below shows how to set some scopes:

letparams={'Name': 'cam001'};device.services.device.setHostname(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetDNS command.

This method sends a SetDNS command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
FromDHCPbooleanrequiredtrue or false
SearchDomainArrayoptionala list of search domains
DNSManualArrayoptionala list of DNS addresses
+-TypeStringrequired"IPv4" or "IPv6"
+-IPv4AddressStringoptionalIPv4 address
+-IPv6AddressStringoptionalIPv6 address
letparams={'FromDHCP' : false,'SearchDomain': ['futomi.gr.jp','hatano.gr.jp'],'DNSManual' : [{'Type': 'IPv4','IPv4Address': '192.168.10.1'},{'Type': 'IPv4','IPv4Address': '192.168.10.3'}]};returndevice.services.device.setDNS(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetNetworkProtocols command.

This method sends a GetNetworkProtocols command.

This method sends a SetNetworkProtocols command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NetworkProtocolsArrayrequired
+-NameStringrequired
+-EnabledBooleanoptional
+-PortIntegeroptional
letparams={'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);});

This method sends a GetNetworkDefaultGateway command.

This method sends a SetNetworkDefaultGateway command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NetworkGatewayArrayrequireda list of IP addresses of gateways
letparams={'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);});

This method sends a GetDeviceInformation command.

This method sends a GetSystemDateAndTime command.

This method sends a Reboot command.

This method sends a GetUsers command.

This method sends a CreateUsers command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
+-PasswordStringrequiredPassword
+-UserLevelStringrequiredEither "Administrator", "Operator", "User", or "Anonymous"
letparams={'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);});

This method sends a DeleteUsers command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
letparams={'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);});

This method sends a SetUser command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
+-PasswordStringrequiredPassword
+-UserLevelStringrequiredEither "Administrator", "Operator", "User", or "Anonymous"
letparams={'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);});

This method sends a RetRelayOutputs command.

This method sends a GetNTP command.

This method sends a SetNTP command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
FromDHCPBooleanrequiredtrue or false
NTPManualObjectoptional
+-TypeStringrequired"IPv4" or "IPv6"
+-IPv4AddressStringoptionalIPv4 address
+-IPv6AddressStringoptionalIPv6 address
letparams={'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);});

This method sends a GetDynamicDNS command.

This method sends a GetZeroConfiguration command.

This method sends a GetServices command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
IncludeCapabilityBooleanrequiredtrue or false
letparams={'IncludeCapability': true};device.services.device.getServices(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetServiceCapabilities command.


This object represents the ONVIF Media Service.

This method sends a GetStreamUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
ProtocolStringrequired"UDP", "HTTP", or "RTSP"
letparams={'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);});

This method sends a GetVideoEncoderConfigurations command.

This method sends a GetVideoEncoderConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configurationToken
letparams={'ConfigurationToken': '2_def_conf6'};device.services.media.getVideoEncoderConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetCompatibleVideoEncoderConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleVideoEncoderConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoEncoderConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'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);});

This method sends a GetGuaranteedNumberOfVideoEncoderInstances command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': '2_def_conf6',};device.services.media.getGuaranteedNumberOfVideoEncoderInstances(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetProfiles command.

This method sends a GetProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a CreateProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NameStringrequireda name of the profile
TokenStringoptionala token of the profile
letparams={'Name': 'TestProfile1','Token': 'TestProfile1'};device.services.media.createProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a DeleteProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
TokenStringrequireda token of the profile
letparams={'ProfileToken': 'TestProfile1'};device.services.media.deleteProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSources command.

This method sends a GetVideoSourceConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': '2_def_conf6'};device.services.media.getVideoSourceConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSourceConfigurations command.

This method sends a GetCompatibleVideoSourceConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
TokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleVideoSourceConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSourceConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': '2_def_conf6'};device.services.media.getVideoSourceConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'metadata1',};device.services.media.getMetadataConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfigurations command.

This method sends a GetCompatibleMetadataConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleMetadataConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': 'Conf001'};device.services.media.getMetadataConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSources command.

This method sends a GetAudioSourceConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig',};device.services.media.getAudioSourceConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSourceConfigurations command.

This method sends a GetCompatibleAudioSourceConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleAudioSourceConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSourceConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioSourceConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioEncoderConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfigurations command.

This method sends a GetCompatibleAudioEncoderConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleAudioEncoderConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioEncoderConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a getSnapshotUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getSnapshotUri(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF PTZ Service.

This method sends a getNodes command.

This method sends a GetNode command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NodeTokenStringrequireda token of the node
letparams={'NodeToken': 'PtzNode'};device.services.ptz.getNode(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetConfigurations command.

This method sends a GetConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the targeted PTZ configuration
letparams={'ConfigurationToken': 'PtzConf1'};device.services.ptz.getConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the targeted PTZ node
letparams={'ConfigurationToken': 'PtzConf1'};device.services.ptz.getConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetStatus command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the targeted PTZ node
letparams={'ProfileToken': 'PtzConf1'};device.services.ptz.getStatus(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a ContinuousMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
VelocityObjectrequired
+-xFloatrequiredSpeed of pan (in the range of -1.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of -1.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of -1.0 to 1.0)
TimeoutIntengeroptionalTimeout (seconds)
letparams={'ProfileToken': '2_def_profile6','Velocity' : {'x': -1,'y': 0,'z': 0},'Timeout' : 1};device.services.ptz.continuousMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a AbsoluteMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PositionObjectrequired
+-xFloatrequiredPosition of pan (The range depends on the profile)
+-yFloatrequiredPosition of tilt (The range depends on the profile)
+-zFloatrequiredPosition of zoom (The range depends on the profile)
SpeedObjectrequired
+-xFloatrequiredSpeed of pan (in the range of -1.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of -1.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of -1.0 to 1.0)
letparams={'ProfileToken': cam['ProfileToken'],'Position' : {'x': 0,'y': 0,'z': 0.003},'Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.absoluteMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a RelativeMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
TranslationObjectrequired
 | `x` | Float | required | Translation of pan (in the range of -1.0 to 1.0)
| `y` | Float | required | Translation of tilt (in the range of -1.0 to 1.0)
| `z` | Float | required | Translation of zoom (in the range of -1.0 to 1.0)

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)

letparams={'ProfileToken': '2_def_profile6','Translation' : {'x': 0.1,'y': 0.1,'z': 0},'Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.relativeMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a stop command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PanTiltBooleanoptionaltrue or false
ZoomBooleanoptionaltrue or false
letparams={'ProfileToken': '2_def_profile6','PanTilt': true,'Zoom': true};device.services.ptz.stop(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GotoHomePosition command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
SpeedFloatoptionalSpeed in the range of 0.0 to 1.0
letparams={'ProfileToken': '2_def_profile6','Speed': 0.5};device.services.ptz.gotoHomePosition(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a SetHomePosition command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.ptz.setHomePosition(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a SetPreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringoptionala token of the preset
PresetNameStringoptionala name of the preset
letparams={'ProfileToken': '2_def_profile6','PresetName' : 'PresetTest1'};device.services.ptz.setPreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetPresets command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.ptz.getPresets(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GotoPreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringrequireda token of the preset
SpeedObjectrequired
+-xFloatrequiredSpeed of pan (in the range of 0.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of 0.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of 0.0 to 1.0)
letparams={'ProfileToken': '2_def_profile6','PresetToken' : '12','Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.gotoPreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a RemovePreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringrequireda token of the preset
letparams={'ProfileToken': '2_def_profile6','PresetToken' : '12'};device.services.ptz.removePreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF Search Service.

This method sends a GetServiceCapabilities command.

This method sends a GetRecordingSummary command.

This method sends a FindRecordings command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopeObjectrequiredscope defines the dataset to consider for this search
+-IncludedSourcesArrayoptionala list of sources that are included in the scope
+-+-TypeStringoptional
+-+-TokenStringrequired
+-IncludedRecordingsArrayoptionala list of recordings that are included in the scope
+-RecordingInformationFilterStringoptionalan xpath expression used to specify what recordings to search
+-ExtensionStringoptionalextension point
MaxMatchesIntegeroptionalthe search will be completed after this many matches
KeepAliveTimeIntegerrequiredthe time the search session will be kept alive after responding to this and subsequent requests
letparams={'Scope': {'IncludedSources': [{'Type': 'sourceType','Token': 'sourceToken'}],'IncludedRecordings': ['recording1'],'RecordingInformationFilter': 'filter','Extension': 'extension',},'MaxMatches': 3,'KeepAliveTime': 100};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetRecordingSearchResults command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
SearchTokenStringrequiredthe search session to get results from
MinResultsIntegeroptionalthe minimum number of results to return in one response
MaxResultsIntegeroptionalthe maximum number of results to return in one response
WaitTimeIntegeroptionalthe maximum time before responding to the request
letparams={'SearchToken': 'token','MinResults': 3,'MaxResults': 14,'WaitTime': 50};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF Replay Service.

This method sends a GetServiceCapabilities command.

This method sends a GetReplayUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
StreamSetupObjectrequiredthe connection parameters to be used for the stream
+-StreamStringrequiredeither RTP-Unicast, RTP-Multicast
+-TransportObjectrequired
+-+-ProtocolStringrequiredeither UDP, TCP, RTSP, HTTP
+-+-TunnelObjectoptionalTODO not implemented
RecordingTokenStringrequiredidentifier of the recording to be streamed
letparams={'StreamSetup': {'Stream': 'RTP-Unicast','Transport': {'Protocol': 'TCP'},},'RecordingToken': 'token'};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This module is based on the ONVIF specifications:


  • v0.1.7 (2018-08-14)
    • Newly added the lastResponse property to the OnvifDevice object for debug. This property is used to investigate SOAP parse error.
  • v0.1.6 (2018-08-13)
    • Fixed the bug of SOAP name space handling. (Issue #38)
  • v0.1.5 (2018-08-13)
  • v0.1.4 (2018-03-25)
    • Clarified the instruction of the installation in the README.md and Added the engines section to the package.json. (Pull Request #24)
    • Fixed the bug of the loop of SearchDomain. (Pull Request #23)
  • v0.1.3 (2018-02-11)
  • v0.1.0 (2017-08-30)
    • Rewrote all scripts to be modern coding style such as let, const, and Promise. All of the asynchronous methods now return a Promise object.
    • Dramatically improved the discovery processs.
    • Supported the devices which do not support the GetSystemDateAndTime command. In the earlier versions, the init method failed if the targeted device did not support the command. Now the init() method will work well with such devices.
    • The startDiscovery() and stopDiscovery() mehtods became deprecated.
    • Newly added the startProbe() and stopProbe() methods.
    • Appended a failure reason text to an Error.message parsing a SOAP message from a device.
    • Fixed bugs of the OnvifServicePtz.getNode(), OnvifServicePtz.getConfiguration(), and OnvifServicePtz.getConfigurationOptions() methods. The methods sent a wrong SOAP message.
    • Implemented the Speed parameter in the OnvifServicePtz.relativeMove() method.

The MIT License (MIT)

Copyright (c) 2016 - 2018 Futomi Hatano

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

The node-onvif is a Node.js module which allows you to communicate with the network camera which supports the ONVIF specifications.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Latest commit

History

55 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

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
    • Search Service
    • Replay 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.

ONVIF Network Camera Manager


Table of Contents


This section shows how to discover ONVIF network cameras, how to get the device information, and how to control the PTZ of the device.

This sample code shows how to discover ONVIF network cameras.

constonvif=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.

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.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.10:80/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.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"
}

This sample code shows how to get the UDP stream URL.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Get the UDP stream URLleturl=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

This sample code shows how to get the data of the snapshot and save it to a file.

constonvif=require('node-onvif');constfs=require('fs');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Get the data of the snapshotconsole.log('fetching the data of the snapshot...');returndevice.fetchSnapshot();}).then((res)=>{// Save the data to a filefs.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.

This sample code shows how to pan, tilt, and zoom the ONVIF network camera.

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// Move the camerareturndevice.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 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.


In order to use the node-onvif module, you have to load the node-onvif module as follows:

constonvif=require('node-onvif');

The variable onvif in the code above is the Onvif object.

This section describes the methods implemented in the Onvif object.

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:

PropertyTypeDescription
urnStringThe URN (Uniform Resource Name) assigned to the device (e.g., "urn:uuid:6b2be733-6ad1-4467-8bd0-747bd8efd206")
nameStringThe product name of the device (e.g., "Panasonic BB-SC384B").
hardwareStringThe description of the hardware of the device (e.g., "BB-SC384B").
locationStringThe physical location of the device (e.g., "China", "shenzhen", "office").
typesArrayThe list of types supported by the device (e.g., "dn:NetworkVideoTransmitter", "tds:Device"). Basically, this module is for "dn:NetworkVideoTransmitter".
xaddrsArrayThe 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").
scopesArrayThe 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.

constonvif=require('node-onvif');// Find the ONVIF network camerasonvif.startProbe().then((device_list)=>{// Show the information of the found devicesconsole.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"]}]

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.

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:

PropertyTypeDescription
urnStringThe URN (Uniform Resource Name) assigned to the device (e.g., "urn:uuid:6b2be733-6ad1-4467-8bd0-747bd8efd206")
nameStringThe product name of the device (e.g., "Panasonic BB-SC384B").
hardwareStringThe description of the hardware of the device (e.g., "BB-SC384B").
locationStringThe physical location of the device (e.g., "China", "shenzhen", "office").
typesArrayThe list of types supported by the device (e.g., "dn:NetworkVideoTransmitter", "tds:Device"). Basically, this module is for "dn:NetworkVideoTransmitter".
xaddrsArrayThe 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").
scopesArrayThe 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.

constonvif=require('node-onvif');// Find the ONVIF network camerasonvif.startDiscovery((info)=>{// Show the information of the found deviceconsole.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",""]}

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.

constonvif=require('node-onvif');// Start the discovery processonvif.startDiscovery((info)=>{// Do something});// Stop the discovery process in 3 secondssetTimeout(()=>{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();

The OnvifDevice object represents an ONVIF network camera device. You can control the ONVIF network camera through this object.

In order to control an ONVIF network camera, you have to create an OnvifDevice object from the OnvifDevice constructor by yourself as follows:

constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.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:

PropertyTypeRequiredDescription
xaddrStringrequiredURL of the end point of the targeted device.
userStringoptionalUser name for the user authentication.
passStringoptionalPassword 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).

The OnvifDevice object provides some properties as follows:

PropertyTypeDescription
servicesObject
+-deviceObjectOnvifServiceDevice object
+-mediaObjectOnvifServiceMedia object
+-ptzObjectOnvifServicePtz object
+-searchObjectOnvifServiceSearch object
+-replayObjectOnvifServiceReplay object

These objects will be set when the initialization process is completed calling the init() method. See the section "ONVIF commands" for details.

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:

PropertyTypeDescription
ManufacturerStringThe manufactor of the device.
ModelStringThe device model.
FirmwareVersionStringThe firmware version in the device.
SerialNumberStringThe serial number of the device.
HardwareIdStringThe hardware ID of the device.
constonvif=require('node-onvif');// Create an OnvifDevice objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '888888'});// Initialize the OnvifDevice objectdevice.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"}

This method returns a hash object consisting of several device information as follow:

PropertyTypeDescription
ManufacturerStringThe manufactor of the device.
ModelStringThe device model.
FirmwareVersionStringThe firmware version in the device.
SerialNumberStringThe serial number of the device.
HardwareIdStringThe 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.

letinfo=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"}

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.

letprofile=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}}}}

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.

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 profileletprofile=device.getCurrentProfile();// Show the video resolution of the current profileletreso=profile['video']['encoder']['resolution'];console.log('- Before: '+reso['width']+' x '+reso['height']);// Get a list of the profiles set in the deviceletprofile_list=device.getProfileList();// Find the profile whose video resolution is the smallestletmin_square=4000*2000;letmin_index=0;for(leti=0;i<profile_list.length;i++){letresolution=profile_list[i]['video']['encoder']['resolution'];letsquare=resolution['width']*resolution['height'];if(square<min_square){min_square=square;min_index=i;}}// Change the current profileprofile=device.changeProfile(min_index);// Show the video resolutionreso=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

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.

leturl=device.getUdpStreamUrl();console.log(url);

The code above will output the result like this:

rtsp://192.168.10.14:10554/tcp/av0_0

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:

PropertyTypeDescription
headersObjectheaders object representing the HTTP response header. This object is of the http module of Node.js.
bodyObjectBuffer 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 extentionletext='bin';letmime_pair=res.headers['content-type'].split('/');if(mime_pair[0]==='image'){ext=mime_pair[1];}// Save the data to a fileletfname='snapshot.'+ext;fs.writeFileSync(fname,res.body,{encoding: 'binary'});console.log('Done!');}).catch((error)=>{console.error(error);});

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:

PropertyTypeRequiredDescription
speedObjectrequired
+-xFloatrequiredSpeed of pan in the range of -1.0 to 1.0.
+-yFloatrequiredSpeed of tilt in the range of -1.0 to 1.0.
+-zFloatrequiredSpeed of zoom in the range of -1.0 to 1.0.
timeoutIntegeroptionalTimeout 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.

letparams={'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 cameradevice.ptzMove(params).then(()=>{console.log('Done!');}).catch((error)=>{console.error(error);});

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 parametersletparams={'speed': {x: 0.5,y: 0.0,z: 0.0},'timeout': 60// seconds};// Supposed to move the camera for 60 secondsdevice.ptzMove(params).then(()=>{console.log('Succeeded to move.');// Stop to the PTZ in 2 secondssetTimeout(()=>{device.ptzStop().then(()=>{console.log('Succeeded to stop.');}).catch((error)=>{console.error(error);});},2000);}).catch((error)=>{console.error(error);});

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 objectletdevice=newonvif.OnvifDevice({xaddr: 'http://192.168.10.14:10080/onvif/device_service',user : 'admin',pass : '123456'});// Initialize the OnvifDevice objectdevice.init().then(()=>{// The OnvifServicePtz objectletptz=device.services.ptz;if(!ptz){thrownewError('Your ONVIF network camera does not support the PTZ service.');}// The parameters for the gotoHomePosition() methodletprofile=device.getCurrentProfile();letparams={'ProfileToken': profile['token'],'Speed' : 1};// Send the GotoHomePosition command using the gotoHomePosition() methodreturnptz.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:

PropertyTypeDescription
soapStringRaw SOAP response
formattedStringFormatted SOAP response in order to be human readable
convertedObjectJavaScript object converted from SOAP response by xml2js module
dataObjectJavaScript 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:Envelopexmlns: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><GotoHomePositionResponsexmlns="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:Envelopexmlns: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>
<GotoHomePositionResponsexmlns="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.


This object represents the ONVIF Device Management Service.

This method sends a GetCapabilities command.

This method sends a GetWsdlUrl command.

This method sends a GetDiscoveryMode command.

This method sends a GetScopes command.

This method sends a SetScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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:

letparams={'Scopes': []}

This method sends a AddScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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);});

This method sends a RemoveScopes command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopesArrayrequireda list of URI

The code below shows how to set some scopes:

letparams={'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);});

This method sends a GetHostname command.

This method sends a SetHostname command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NameStringrequireda host name

The code below shows how to set some scopes:

letparams={'Name': 'cam001'};device.services.device.setHostname(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetDNS command.

This method sends a SetDNS command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
FromDHCPbooleanrequiredtrue or false
SearchDomainArrayoptionala list of search domains
DNSManualArrayoptionala list of DNS addresses
+-TypeStringrequired"IPv4" or "IPv6"
+-IPv4AddressStringoptionalIPv4 address
+-IPv6AddressStringoptionalIPv6 address
letparams={'FromDHCP' : false,'SearchDomain': ['futomi.gr.jp','hatano.gr.jp'],'DNSManual' : [{'Type': 'IPv4','IPv4Address': '192.168.10.1'},{'Type': 'IPv4','IPv4Address': '192.168.10.3'}]};returndevice.services.device.setDNS(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetNetworkProtocols command.

This method sends a GetNetworkProtocols command.

This method sends a SetNetworkProtocols command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NetworkProtocolsArrayrequired
+-NameStringrequired
+-EnabledBooleanoptional
+-PortIntegeroptional
letparams={'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);});

This method sends a GetNetworkDefaultGateway command.

This method sends a SetNetworkDefaultGateway command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NetworkGatewayArrayrequireda list of IP addresses of gateways
letparams={'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);});

This method sends a GetDeviceInformation command.

This method sends a GetSystemDateAndTime command.

This method sends a Reboot command.

This method sends a GetUsers command.

This method sends a CreateUsers command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
+-PasswordStringrequiredPassword
+-UserLevelStringrequiredEither "Administrator", "Operator", "User", or "Anonymous"
letparams={'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);});

This method sends a DeleteUsers command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
letparams={'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);});

This method sends a SetUser command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
UserArrayrequireda list of users
+-UsernameStringrequiredUsername
+-PasswordStringrequiredPassword
+-UserLevelStringrequiredEither "Administrator", "Operator", "User", or "Anonymous"
letparams={'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);});

This method sends a RetRelayOutputs command.

This method sends a GetNTP command.

This method sends a SetNTP command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
FromDHCPBooleanrequiredtrue or false
NTPManualObjectoptional
+-TypeStringrequired"IPv4" or "IPv6"
+-IPv4AddressStringoptionalIPv4 address
+-IPv6AddressStringoptionalIPv6 address
letparams={'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);});

This method sends a GetDynamicDNS command.

This method sends a GetZeroConfiguration command.

This method sends a GetServices command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
IncludeCapabilityBooleanrequiredtrue or false
letparams={'IncludeCapability': true};device.services.device.getServices(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetServiceCapabilities command.


This object represents the ONVIF Media Service.

This method sends a GetStreamUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
ProtocolStringrequired"UDP", "HTTP", or "RTSP"
letparams={'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);});

This method sends a GetVideoEncoderConfigurations command.

This method sends a GetVideoEncoderConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configurationToken
letparams={'ConfigurationToken': '2_def_conf6'};device.services.media.getVideoEncoderConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetCompatibleVideoEncoderConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleVideoEncoderConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoEncoderConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'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);});

This method sends a GetGuaranteedNumberOfVideoEncoderInstances command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': '2_def_conf6',};device.services.media.getGuaranteedNumberOfVideoEncoderInstances(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetProfiles command.

This method sends a GetProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a CreateProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NameStringrequireda name of the profile
TokenStringoptionala token of the profile
letparams={'Name': 'TestProfile1','Token': 'TestProfile1'};device.services.media.createProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a DeleteProfile command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
TokenStringrequireda token of the profile
letparams={'ProfileToken': 'TestProfile1'};device.services.media.deleteProfile(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSources command.

This method sends a GetVideoSourceConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': '2_def_conf6'};device.services.media.getVideoSourceConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSourceConfigurations command.

This method sends a GetCompatibleVideoSourceConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
TokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleVideoSourceConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetVideoSourceConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': '2_def_conf6'};device.services.media.getVideoSourceConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'metadata1',};device.services.media.getMetadataConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfigurations command.

This method sends a GetCompatibleMetadataConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleMetadataConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetMetadataConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': 'Conf001'};device.services.media.getMetadataConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSources command.

This method sends a GetAudioSourceConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig',};device.services.media.getAudioSourceConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSourceConfigurations command.

This method sends a GetCompatibleAudioSourceConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleAudioSourceConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioSourceConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioSourceConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the configuration
letparams={'ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioEncoderConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfigurations command.

This method sends a GetCompatibleAudioEncoderConfigurations command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getCompatibleAudioEncoderConfigurations(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetAudioEncoderConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringoptionala token of the profile
ConfigurationTokenStringoptionala token of the configuration
letparams={'ProfileToken': '2_def_profile6','ConfigurationToken': 'AudioSourceConfig'};device.services.media.getAudioEncoderConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a getSnapshotUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.media.getSnapshotUri(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF PTZ Service.

This method sends a getNodes command.

This method sends a GetNode command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
NodeTokenStringrequireda token of the node
letparams={'NodeToken': 'PtzNode'};device.services.ptz.getNode(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetConfigurations command.

This method sends a GetConfiguration command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the targeted PTZ configuration
letparams={'ConfigurationToken': 'PtzConf1'};device.services.ptz.getConfiguration(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetConfigurationOptions command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ConfigurationTokenStringrequireda token of the targeted PTZ node
letparams={'ConfigurationToken': 'PtzConf1'};device.services.ptz.getConfigurationOptions(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetStatus command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the targeted PTZ node
letparams={'ProfileToken': 'PtzConf1'};device.services.ptz.getStatus(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a ContinuousMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
VelocityObjectrequired
+-xFloatrequiredSpeed of pan (in the range of -1.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of -1.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of -1.0 to 1.0)
TimeoutIntengeroptionalTimeout (seconds)
letparams={'ProfileToken': '2_def_profile6','Velocity' : {'x': -1,'y': 0,'z': 0},'Timeout' : 1};device.services.ptz.continuousMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a AbsoluteMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PositionObjectrequired
+-xFloatrequiredPosition of pan (The range depends on the profile)
+-yFloatrequiredPosition of tilt (The range depends on the profile)
+-zFloatrequiredPosition of zoom (The range depends on the profile)
SpeedObjectrequired
+-xFloatrequiredSpeed of pan (in the range of -1.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of -1.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of -1.0 to 1.0)
letparams={'ProfileToken': cam['ProfileToken'],'Position' : {'x': 0,'y': 0,'z': 0.003},'Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.absoluteMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a RelativeMove command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
TranslationObjectrequired
 | `x` | Float | required | Translation of pan (in the range of -1.0 to 1.0)
| `y` | Float | required | Translation of tilt (in the range of -1.0 to 1.0)
| `z` | Float | required | Translation of zoom (in the range of -1.0 to 1.0)

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)

letparams={'ProfileToken': '2_def_profile6','Translation' : {'x': 0.1,'y': 0.1,'z': 0},'Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.relativeMove(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a stop command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PanTiltBooleanoptionaltrue or false
ZoomBooleanoptionaltrue or false
letparams={'ProfileToken': '2_def_profile6','PanTilt': true,'Zoom': true};device.services.ptz.stop(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GotoHomePosition command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
SpeedFloatoptionalSpeed in the range of 0.0 to 1.0
letparams={'ProfileToken': '2_def_profile6','Speed': 0.5};device.services.ptz.gotoHomePosition(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a SetHomePosition command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.ptz.setHomePosition(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a SetPreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringoptionala token of the preset
PresetNameStringoptionala name of the preset
letparams={'ProfileToken': '2_def_profile6','PresetName' : 'PresetTest1'};device.services.ptz.setPreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetPresets command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
letparams={'ProfileToken': '2_def_profile6'};device.services.ptz.getPresets(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GotoPreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringrequireda token of the preset
SpeedObjectrequired
+-xFloatrequiredSpeed of pan (in the range of 0.0 to 1.0)
+-yFloatrequiredSpeed of tilt (in the range of 0.0 to 1.0)
+-zFloatrequiredSpeed of zoom (in the range of 0.0 to 1.0)
letparams={'ProfileToken': '2_def_profile6','PresetToken' : '12','Speed' : {'x': 1,'y': 1,'z': 1}};device.services.ptz.gotoPreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a RemovePreset command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ProfileTokenStringrequireda token of the profile
PresetTokenStringrequireda token of the preset
letparams={'ProfileToken': '2_def_profile6','PresetToken' : '12'};device.services.ptz.removePreset(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF Search Service.

This method sends a GetServiceCapabilities command.

This method sends a GetRecordingSummary command.

This method sends a FindRecordings command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
ScopeObjectrequiredscope defines the dataset to consider for this search
+-IncludedSourcesArrayoptionala list of sources that are included in the scope
+-+-TypeStringoptional
+-+-TokenStringrequired
+-IncludedRecordingsArrayoptionala list of recordings that are included in the scope
+-RecordingInformationFilterStringoptionalan xpath expression used to specify what recordings to search
+-ExtensionStringoptionalextension point
MaxMatchesIntegeroptionalthe search will be completed after this many matches
KeepAliveTimeIntegerrequiredthe time the search session will be kept alive after responding to this and subsequent requests
letparams={'Scope': {'IncludedSources': [{'Type': 'sourceType','Token': 'sourceToken'}],'IncludedRecordings': ['recording1'],'RecordingInformationFilter': 'filter','Extension': 'extension',},'MaxMatches': 3,'KeepAliveTime': 100};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This method sends a GetRecordingSearchResults command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
SearchTokenStringrequiredthe search session to get results from
MinResultsIntegeroptionalthe minimum number of results to return in one response
MaxResultsIntegeroptionalthe maximum number of results to return in one response
WaitTimeIntegeroptionalthe maximum time before responding to the request
letparams={'SearchToken': 'token','MinResults': 3,'MaxResults': 14,'WaitTime': 50};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This object represents the ONVIF Replay Service.

This method sends a GetServiceCapabilities command.

This method sends a GetReplayUri command. The 1st argument params must be a hash object consisting of the properties as follows:

PropertyTypeRequiredDescription
StreamSetupObjectrequiredthe connection parameters to be used for the stream
+-StreamStringrequiredeither RTP-Unicast, RTP-Multicast
+-TransportObjectrequired
+-+-ProtocolStringrequiredeither UDP, TCP, RTSP, HTTP
+-+-TunnelObjectoptionalTODO not implemented
RecordingTokenStringrequiredidentifier of the recording to be streamed
letparams={'StreamSetup': {'Stream': 'RTP-Unicast','Transport': {'Protocol': 'TCP'},},'RecordingToken': 'token'};device.services.ptz.findRecordings(params).then((result)=>{console.log(JSON.stringify(result['data'],null,' '));}).catch((error)=>{console.error(error);});

This module is based on the ONVIF specifications:


  • v0.1.7 (2018-08-14)
    • Newly added the lastResponse property to the OnvifDevice object for debug. This property is used to investigate SOAP parse error.
  • v0.1.6 (2018-08-13)
    • Fixed the bug of SOAP name space handling. (Issue #38)
  • v0.1.5 (2018-08-13)
  • v0.1.4 (2018-03-25)
    • Clarified the instruction of the installation in the README.md and Added the engines section to the package.json. (Pull Request #24)
    • Fixed the bug of the loop of SearchDomain. (Pull Request #23)
  • v0.1.3 (2018-02-11)
  • v0.1.0 (2017-08-30)
    • Rewrote all scripts to be modern coding style such as let, const, and Promise. All of the asynchronous methods now return a Promise object.
    • Dramatically improved the discovery processs.
    • Supported the devices which do not support the GetSystemDateAndTime command. In the earlier versions, the init method failed if the targeted device did not support the command. Now the init() method will work well with such devices.
    • The startDiscovery() and stopDiscovery() mehtods became deprecated.
    • Newly added the startProbe() and stopProbe() methods.
    • Appended a failure reason text to an Error.message parsing a SOAP message from a device.
    • Fixed bugs of the OnvifServicePtz.getNode(), OnvifServicePtz.getConfiguration(), and OnvifServicePtz.getConfigurationOptions() methods. The methods sent a wrong SOAP message.
    • Implemented the Speed parameter in the OnvifServicePtz.relativeMove() method.

The MIT License (MIT)

Copyright (c) 2016 - 2018 Futomi Hatano

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

The node-onvif is a Node.js module which allows you to communicate with the network camera which supports the ONVIF specifications.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages