Permalink
Browse files

Bump to 0.4: requestImage() can now take an optional options argument…

…; Added more documentation;
  • Loading branch information...
1 parent 20dd8de commit 299588432ce4d57b914f9e7afd1244b482b52b84 @gluxon committed Mar 10, 2013
Showing with 61 additions and 16 deletions.
  1. +40 −2 README.md
  2. +7 −1 examples/requestImage.js
  3. +13 −12 lib/vapix.js
  4. +1 −1 package.json
View
@@ -35,8 +35,9 @@ And to use...
### camera.createVideoSream(options)
-Returns a video stream. Each data event is a full frame. Parameters are
-outlined in the VAPIX® [Video Streaming API](http://www.axis.com/files/manuals/vapix_video_streaming_48700_en_1208.pdf)
+Returns a video stream. Each data event is a full frame. Parameters to
+be set as an object in `options` are outlined in the VAPIX®
+[Video Streaming API](http://www.axis.com/files/manuals/vapix_video_streaming_48700_en_1208.pdf)
document.
var options = {
@@ -56,13 +57,50 @@ document.
console.log('Finished.');
});
+### camera.requestImage([options], callback)
+
+Grab an image. Parameters to be set as an object in `options` are
+outlined in the VAPIX® [Video Streaming API](http://www.axis.com/files/manuals/vapix_video_streaming_48700_en_1208.pdf)
+document.
+
+ var fs = require('fs');
+
+ var options = {
+ resolution: '640x480',
+ compression: 30,
+ rotation: 0
+ }
+
+ camera.requestImage(options, function(err, data) {
+ if (err) throw err;
+
+ fs.writeFile("out.jpg", data, function(err) {
+ if (err) throw err;
+ });
+ });
+
+### camera.getImageResolution()
+
+Returns an object containing the `width` and `height` of the camera's image
+resolution setting.
+
+ camera.getImageResolution(function(err, data) {
+ if (err) throw err;
+
+ console.log(data); // { width: '640', height: '480' }
+ });
## License
node-vapix is written under the [MIT License](http://opensource.org/licenses/MIT)
## Status
+#### 0.4
+- More API documentation
+- requestImage() now supports optional options argument
+- Private method request() now takes 1 path string instead of as an object
+
#### 0.3
- Added createVideoStream()
- Created method for generating HTTP GET queries
View
@@ -10,7 +10,13 @@ var options = {
var camera = new vapix.Camera(options);
-camera.requestImage(function(err, data) {
+var options = {
+ resolution: '640x480',
+ compression: 30,
+ rotation: 0
+}
+
+camera.requestImage(options, function(err, data) {
if (err) throw err;
// Write returned image data to file
View
@@ -52,11 +52,11 @@ Camera.prototype.generateGET = function(options) {
return arguments;
}
-Camera.prototype.request = function(options, callback) {
+Camera.prototype.request = function(path, callback) {
var options = {
hostname: this.address,
port: this.port,
- path: options.path,
+ path: path,
auth: this.username + ':' + this.password
};
@@ -82,20 +82,22 @@ Camera.prototype.request = function(options, callback) {
req.end();
}
-Camera.prototype.requestImage = function(callback) {
- var options = {
- path: '/axis-cgi/jpg/image.cgi'
- };
+Camera.prototype.requestImage = function(options, callback) {
+ if (typeof options === 'object') {
+ var path = '/axis-cgi/jpg/image.cgi' + this.generateGET(options);
+ } else {
+ // Options was never passed, only the callback. Use default.
+ var path = '/axis-cgi/jpg/image.cgi';
+ callback = options;
+ }
- this.request(options, callback);
+ this.request(path, callback);
}
Camera.prototype.getImageResolution = function(callback) {
- var options = {
- path: '/axis-cgi/imagesize.cgi?camera=1'
- };
+ var path = '/axis-cgi/imagesize.cgi?camera=1';
- this.request(options, function(err, data) {
+ this.request(path, function(err, data) {
if (err) {
callback(err, null);
} else {
@@ -111,7 +113,6 @@ Camera.prototype.getImageResolution = function(callback) {
}
Camera.prototype.createVideoStream = function(options) {
-
var soi = new Buffer('ffd8', 'hex'); // JPEG SOI marker (FFD8 hex)
var header_length = 65;
View
@@ -1,6 +1,6 @@
{
"name": "vapix",
- "version": "0.3.0",
+ "version": "0.4.0",
"author": "Brandon Cheng <gluxon@gluxon.com>",
"description": "VAPIX is Axis’ own open API, implemented in Node.js ",
"repository": {

0 comments on commit 2995884

Please sign in to comment.