diff --git a/lib/surveillance-station.js b/lib/surveillance-station.js index 3646dc6..998dbd4 100644 --- a/lib/surveillance-station.js +++ b/lib/surveillance-station.js @@ -1,4 +1,44 @@ +'use strict'; + +var util = require('util'); + + +function Camera(syno) { + this.syno = syno; + return this; +} + +Camera.prototype.getSnapshot = function() { + /*jshint validthis:true */ + var + userParams = + typeof arguments[0] === 'object' ? arguments[0] : + {}, + callback = + typeof arguments[1] === 'function' ? arguments[1] : + typeof arguments[0] === 'function' ? arguments[0] : + null + ; + var params = { + api : 'SYNO.SurveillanceStation.Camera', + version: 9, + method : 'GetSnapshot' + }; + util._extend(params, userParams); + + var query = this.syno.query({ + path: '/webapi/entry.cgi', + params: params, + headers: { + 'Accept': 'image/jpeg', + } + }, callback || null); + + return query; +} + module.exports = function(syno) { return { + camera: new Camera(syno), }; }; diff --git a/lib/synology.js b/lib/synology.js index 87673c0..e703039 100644 --- a/lib/synology.js +++ b/lib/synology.js @@ -86,7 +86,8 @@ var Synology = function(options) { body : options.body, method : options.method, headers: options.headers, - timeout: 30 * 1e3 + timeout: 30 * 1e3, + encoding: null, }, callback ? _apiCallback : null); }, @@ -95,13 +96,11 @@ var Synology = function(options) { syno.emit('error', err); return callback && callback(err, data); } - - // Parse the JSON response + + // Try to parse the JSON response try { data = JSON.parse(data); } catch(e) { - syno.emit('error', err); - return callback && callback(err, data); } if (!data.success && data.error) {