domotz-remote-pawn
Version:
Domotz Agent
92 lines (87 loc) • 3.81 kB
JavaScript
/**
* This file is part of Domotz Agent.
* Copyright (C) 2016 Domotz Ltd
*
* Domotz Agent is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Domotz Agent is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Domotz Agent. If not, see <http://www.gnu.org/licenses/>.
*
* Created by Georgi Tsatsev <gtsatsev@domotz.com> on 26/03/2018.
*/
var utils = require('./utils');
var onvifGet = function (message, resourceLocator) {
var onvif = resourceLocator.onvif,
async = resourceLocator.async,
username = message.payload.username,
password = message.payload.password,
port = message.payload.port || utils.defaultPort,
hostname = message.payload.host;
var createOnvifCamera = function (callback) {
var myConsole = resourceLocator.log.decorateLogs().decorate(hostname);
return new onvif.Cam(
{
username: username,
password: password,
hostname: hostname,
port: port,
},
function (err) {
if (err) {
myConsole.info('Cannot connect to camera');
myConsole.debug(JSON.stringify(err));
callback({ outcome: null, error: err.message });
} else {
myConsole.info('Successfully connected to camera ');
this.streamingUris = {};
var profiles = this.profiles;
this.getDeviceInformation(function () {
this.getServices(function () {
var that = this;
var stillExpecting = profiles.length;
async.each(
profiles,
function (profile, callbackAsync) {
var token = profile.$.token;
var options = { profileToken: token };
that.getStreamUri(options, function (error, response) {
myConsole.debug('Obtained stream URI for profile: ' + token);
that.streamingUris[token] = response;
stillExpecting--;
callbackAsync();
});
},
function (err) {
if (!stillExpecting) {
myConsole.debug('Calling back');
callback({ outcome: that, error: null });
}
if (err) {
callback({ outcome: that, error: err.message });
}
}
);
});
});
}
}
);
};
return {
execute: function (callback) {
return createOnvifCamera(callback);
},
describe: function () {
return utils.logCommand(message, 'getOnvifCameraDevice');
},
};
};
module.exports.command = onvifGet;