Skip to content

Instantly share code, notes, and snippets.

@bmoore
Created December 16, 2013 22:16
Show Gist options
  • Save bmoore/7995441 to your computer and use it in GitHub Desktop.
Save bmoore/7995441 to your computer and use it in GitHub Desktop.
Lazy solution... like pseudoprototype.
var WebCam = {
capturing: false,
callbacks: [],
capture: function(cb) {
addCallback(cb);
_takePic();
},
addCallback(cb) {
this.callbacks.push(cb);
},
_takePic: function() {
if (this.capturing) {
return;
}
//ugly but I don't want to think
that=this;
this.capturing = true;
filename = new Date().getTime() + ".jpg";
cameraConfig.output = cameraFilePath + name;
var camera = new RaspiCam(cameraConfig);
camera.on("change", debounce(camera.stop, debounceTime));
camera.on("exit", function(){
while (cb = that.callbacks.shift()) {
cb(err, filename);
}
that.capturing = false;
});
camera.start();
},
};
exports.photo = function(request, response){
WebCam.capture(function(err, filename) {
if (err) {
response.send({message: err, name: filename});
} else {
response.send({message: "Successfully captured image", name: name});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment