Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions lib/surveillance-station.js
Original file line number Diff line number Diff line change
@@ -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),
};
};
9 changes: 4 additions & 5 deletions lib/synology.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},

Expand All @@ -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) {
Expand Down