UNPKG

domotz-remote-pawn

Version:

Domotz Agent

112 lines (102 loc) 4.29 kB
const onvif = require('../src/net/onvif/onvif'); var stringify = require('json-stable-stringify'); var Cam = onvif.Cam; var events = require('events'); var USERNAME = 'admin', PASSWORD = '123456'; var command = process.argv[2] || 'stream'; PASSWORD = process.argv[3] || PASSWORD; onvif.Discovery.on('device', function (cam) { try { cam.password = PASSWORD; cam.username = USERNAME; cam.connect(function (err) { if (err) { console.log('Connection Failed for ' + cam.hostname + ' Port: ' + cam.port + ' Username: ' + USERNAME + ' Password: ' + PASSWORD); console.log(JSON.stringify(err.message)); return; } switch (command) { case 'reboot': cam.systemReboot(function (err, res, xml) { if (err) { console.error('ERROR: ' + err); console.log(xml); } else { console.log(res); console.log(xml); console.log('rebooted'); } }); break; case 'time': this.getSystemDateAndTime(function (err, data) { if (err) { console.error('ERROR: ' + JSON.stringify(err, null, 2)); } console.log(JSON.stringify(data, null, 2)); }); break; case 'info': this.getDeviceInformation(function (err, data) { console.log(data); }); break; case 'snapshot': this.getSnapshotUri({}, function (err, data) { console.log(data); }); break; case 'stream': this.getStreamUri({}, function (err, data) { console.log(data); }); break; case 'status': this.getStatus({}, function (err, data) { console.log(data); }); break; case 'profiles': cam.getProfiles(function (err, data) { console.log('PROFILES'); data.forEach(function (profile) { console.log( JSON.stringify( { name: profile.name, token: profile.$.token, encoding: profile.videoEncoderConfiguration.encoding, quality: profile.videoEncoderConfiguration.quality, bitrate_limit: profile.videoEncoderConfiguration.bitrateLimit, resolution: profile.videoEncoderConfiguration.resolution, multicast: !!profile.videoEncoderConfiguration.multicast, }, null, 2 ) ); }); }); break; case 'capabilities': cam.getCapabilities(function (err, data) { console.log('CAPABILITIES'); console.log(JSON.stringify(data, null, 2)); }); break; case 'services': cam.getServices(function (err, data) { console.log('Services'); console.log(stringify(data, null, 2)); }); break; default: console.log('Unknown command: ' + command); } }); } catch (e) { console.error(e); } }); onvif.Discovery.probe();