I want to write a non-typical android app -- a server app, in fact. When the server receives a request, it needs to capture an image from a camera, do some custom processing, and send a response to the client.
The nodejs service I wrote (see below) uses dory for the nodejs install. The service works on my desktop PC. But the node-webcam package does not support mobile phones. I haven't been able to find a package that support cameras on android.
Is there a way to access the camera on android?
const http = require('http');
const NodeWebcam = require( "node-webcam" );
const app = http.createServer((req, res) => {
if( req.url === "/image" ) {
var opts = {
callbackReturn: "base64"
};
NodeWebcam.capture( "test_picture", opts, function( err, data ) {
let imageHTML = "<div>Error: " + JSON.stringify(err) + "</div>";
if( data ) {
imageHTML = "<img src='" + data + "'>";
}
// Set a response type of plain text for the response
res.writeHead(200, {'Content-Type': 'text/html'});
// Send back a response and end the connection
res.end(`<html><body>${imageHTML}</body></html>`);
});
}
else {
// Set a response type of plain text for the response
res.writeHead(200, {'Content-Type': 'text/plain'});
// Send back a response and end the connection
res.end('NodeJS Server Online!\n\nContent is king!');
}
});
// Start the server on port 3000
app.listen(3000, '0.0.0.0');