Created
December 16, 2013 22:16
-
-
Save bmoore/7995441 to your computer and use it in GitHub Desktop.
Lazy solution... like pseudoprototype.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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