Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
agsh committed Dec 25, 2017
2 parents 937d7e7 + 5cfed69 commit a21199c
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 3 deletions.
51 changes: 51 additions & 0 deletions example5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Created by Andrew D.Laptev<[email protected]> on 1/21/15.
* Edited by Lucas Zanella <[email protected]> on 27/08/17.
* Same as example.json but uses SOCKS5 (useful to access cameras securely through SSH)
*/
var ProxyAgent = require('proxy-agent');

var CAMERA_HOST = '192.168.1.164',
USERNAME = 'admin',
PASSWORD = 'admin',
PORT = 1018,
PROXY_URI = 'socks5://localhost:1234';


var http = require('http'),
Cam = require('./onvif').Cam;

new Cam({
hostname: CAMERA_HOST,
username: USERNAME,
password: PASSWORD,
port: PORT,
agent: new ProxyAgent(PROXY_URI)
}, function(err) {
if (err) {
console.log('Connection Failed for ' + CAMERA_HOST + ' Port: ' + PORT + ' Username: ' + USERNAME + ' Password: ' + PASSWORD);
return;
}
console.log('CONNECTED');

this.absoluteMove({
x: 1
, y: 1
, zoom: 1
});

this.getStreamUri({protocol:'RTSP'}, function(err, stream) {
console.log(stream);

http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(
'<html><body>' +
'<embed type="application/x-vlc-plugin" target="' + stream.uri + '"></embed>' +
'</boby></html>');
}).listen(3030);

});

});

5 changes: 3 additions & 2 deletions lib/cam.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ var Cam = function(options, callback) {
this.port = options.port || 80;
this.path = options.path || '/onvif/device_service';
this.timeout = options.timeout || 120000;
this.agent = options.agent || false;
/**
* Force using hostname and port from constructor for the services
* @type {boolean}
Expand Down Expand Up @@ -114,7 +115,6 @@ Cam.prototype.connect = function(callback) {
upstartFunctions.push(this.getProfiles);
upstartFunctions.push(this.getVideoSources);
}

var count = upstartFunctions.length;
var errCall = false;

Expand Down Expand Up @@ -171,13 +171,14 @@ Cam.prototype._request = function(options, callback) {
var reqOptions = options.url || {
hostname: this.hostname
, port: this.port
, agent: this.agent //Supports things like https://www.npmjs.com/package/proxy-agent which provide SOCKS5 and other connections
, path: options.service
? (this.uri[options.service] ? this.uri[options.service].path : options.service)
: this.path
};
reqOptions.headers = {
'Content-Type': 'application/soap+xml'
, 'Content-Length': options.body.length
, 'Content-Length': Buffer.byteLength(options.body, 'utf8')//options.body.length chinese will be wrong here
, charset: 'utf-8'
};

Expand Down
39 changes: 38 additions & 1 deletion lib/ptz.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,44 @@ Cam.prototype.gotoPreset = function(options, callback) {
this._envelopeFooter()
}, callback.bind(this));
};

/**
* /PTZ/ Set preset
* @param {object} options
* @param {string} [options.profileToken]
* @param {string} options.presetName
* @param {string} [options.presetToken]
* @param {function} callback
*/
Cam.prototype.setPreset = function(options, callback) {
this._request({
service: 'ptz'
, body: this._envelopeHeader() +
'<SetPreset xmlns="http://www.onvif.org/ver20/ptz/wsdl">' +
'<ProfileToken>' + (options.profileToken || this.activeSource.profileToken) + '</ProfileToken>' +
'<PresetName>' + options.presetName + '</PresetName>' +
(options.presetToken ? '<PresetToken>' + options.presetToken + '</PresetToken>' : '') +
'</SetPreset>' +
this._envelopeFooter()
}, callback.bind(this));
};
/**
* /PTZ/ Remove preset
* @param {object} options
* @param {string} [options.profileToken]
* @param {string} options.presetToken
* @param {function} callback
*/
Cam.prototype.removePreset = function(options,callback) {
this._request({
service: 'ptz'
, body: this._envelopeHeader() +
'<RemovePreset xmlns="http://www.onvif.org/ver20/ptz/wsdl">' +
'<ProfileToken>' + (options.profileToken || this.activeSource.profileToken) + '</ProfileToken>' +
'<PresetToken>' + options.presetToken + '</PresetToken>' +
'</RemovePreset>' +
this._envelopeFooter()
}, callback.bind(this));
};
/**
* @typedef {object} Cam~PTZStatus
* @property {object} position
Expand Down

0 comments on commit a21199c

Please sign in to comment.