Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkeye64 committed Oct 25, 2018
2 parents af3fb48 + 4d794e9 commit 53bbc39
Show file tree
Hide file tree
Showing 4 changed files with 2,391 additions and 1,014 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ If all is well, make the PR.

The library is made in such a way that only modules that will work with your device are automatically included. For others, you can choose whether or not to bring in the functionality.

## Proxy Support (added 0.2.9)
Proxy support has been added.

## Example (Discovery)
``` cs
const OnvifManager = require('onvif-nvt')
Expand All @@ -71,6 +74,7 @@ OnvifManager.discovery.startProbe().then(deviceList => {
## Example (Connect and Continuous Move)
``` cs
const OnvifManager = require('onvif-nvt')
// OnvifManager.connect('localhost/my/proxy/path', null, 'username', 'password') <-- proxy path
OnvifManager.connect('10.10.1.60', 80, 'username', 'password')
.then(results => {
let camera = results
Expand All @@ -89,6 +93,7 @@ OnvifManager.connect('10.10.1.60', 80, 'username', 'password')
## Example (Snapshot)
``` cs
const OnvifManager = require('onvif-nvt')
// OnvifManager.connect('localhost/my/proxy/path', null, 'username', 'password') <-- proxy path
OnvifManager.connect('10.10.1.60', 80, 'username', 'password')
.then(results => {
let camera = results
Expand All @@ -113,6 +118,7 @@ OnvifManager.connect('10.10.1.60', 80, 'username', 'password')
PullMessages now works with Hikvision, TrendNET and Pelco. They are not working with Axis.
``` cs
const OnvifManager = require('onvif-nvt')
// OnvifManager.connect('localhost/my/proxy/path', null, 'username', 'password') <-- proxy path
OnvifManager.connect('10.10.1.60', 80, 'username', 'password')
.then(results => {
let camera = results
Expand Down
27 changes: 27 additions & 0 deletions lib/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Camera {
this.thermal = null
this.videoanalytics = null

this.rootPath = null
this.serviceAddress = null
this.timeDiff = 0
this.address = null
Expand Down Expand Up @@ -258,6 +259,7 @@ class Camera {
if (port && port !== 80) {
serviceAddress = serviceAddress + ':' + port
}
this.rootPath = serviceAddress
serviceAddress = serviceAddress + servicePath

this.serviceAddress = Url.parse(serviceAddress)
Expand Down Expand Up @@ -357,11 +359,13 @@ class Camera {
.then(results => {
let response = results.data.GetServicesResponse
let services = response.Service

// the appropriate modules will be automatically added
// to camera based on the onvif device's services.
// if GetServics is not supported, the GetCapabilities
// fallback will be used.
services.forEach(service => {
this.checkForProxy(service)
let namespace = service.Namespace
if (namespace === 'http://www.onvif.org/ver10/device/wsdl') {
this.core.version = service.Version
Expand Down Expand Up @@ -420,6 +424,20 @@ class Camera {
})
}

// make sure the serviceAddress matches
// if not, then we may be behind a proxy and it needs
// do be dealt with
checkForProxy (service) {
let xaddrPath = Url.parse(service.XAddr)
if (xaddrPath.hostname === this.serviceAddress.hostname) {
// no proxy
return
}

// build new path
service.XAddr = this.rootPath + xaddrPath.path
}

coreGetCapabilities () {
return new Promise((resolve, reject) => {
this.core.getCapabilities()
Expand All @@ -432,6 +450,7 @@ class Camera {
// the appropriate modules will be automatically added
// to camera based on the onvif device's capabilities.
let analytics = c['Analytics']
this.checkForProxy(analytics)
if (analytics && analytics['XAddr']) {
if (!this.analytics) {
this.add('analytics')
Expand All @@ -450,6 +469,7 @@ class Camera {
}
}
let events = c['Events']
this.checkForProxy(events)
if (events && events['XAddr']) {
if (!this.events) {
this.add('events')
Expand All @@ -468,6 +488,7 @@ class Camera {
}
}
let imaging = c['Imaging']
this.checkForProxy(imaging)
if (imaging && imaging['XAddr']) {
if (!this.imaging) {
this.add('imaging')
Expand All @@ -478,6 +499,7 @@ class Camera {
}
}
let media = c['Media']
this.checkForProxy(media)
if (media && media['XAddr']) {
if (!this.media) {
this.add('media')
Expand All @@ -488,6 +510,7 @@ class Camera {
}
}
let ptz = c['PTZ']
this.checkForProxy(ptz)
if (ptz && ptz['XAddr']) {
if (!this.ptz) {
this.add('ptz')
Expand Down Expand Up @@ -677,7 +700,11 @@ class Camera {
this.media.getSnapshotUri(profile['$']['token'])
.then(results => {
try {
let service = {}
service.XAddr = results['data']['GetSnapshotUriResponse']['MediaUri']['Uri']
this.checkForProxy(service)
profile.SnapshotUri = results['data']['GetSnapshotUriResponse']['MediaUri']
profile.SnapshotUri['Uri'] = service.XAddr
}
catch (e) {}
++profileIndex
Expand Down
Loading

0 comments on commit 53bbc39

Please sign in to comment.