Skip to content

Commit

Permalink
Camera: examples
Browse files Browse the repository at this point in the history
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed Dec 16, 2016
1 parent cee65ae commit 03ca47e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
45 changes: 45 additions & 0 deletions eg/camera-capture-still-respond-to-request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"use strict";

const av = require("../");
const ip = require("ip");
const os = require("os");
const path = require("path");
const http = require("http");
const port = 8888;

const camera = new av.Camera({
width: 800,
height: 600,
});

const server = http.createServer((request, response) => {

if (/frame/.test(request.url)) {
console.log("asking for image...");

response.writeHead(200, { "Content-Type": "image/jpeg" });
camera.capture().pipe(response);

fs.writeFile(path.join(__dirname, `${Date.now()}.jpg`), camera.frame, error => {
console.log("image saved.");
});

} else {
console.log("asking for web page...");
response.writeHead(200, { "Content-Type": "text/html" });
response.end(`
<!doctype html>
<html>
<head>
<title>${os.hostname()}</title>
</head>
<body>
<img src="/frame">
</body>
</html>
`);
}
}).listen(port, () => {
console.log(`http://${ip.address()}:${port}`);
console.log(`<img src="${camera.url}">`);
});
14 changes: 14 additions & 0 deletions eg/camera-capture-still-save-locally.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

var av = require('tessel-av');
var fs = require('fs');
var path = require('path');
var camera = new av.Camera();


camera.capture()
.pipe(fs.createWriteStream(path.join(__dirname, 'capture.jpg')))
.on('finish', () => {
console.log('Image Captured.');
process.exit(0);
});

0 comments on commit 03ca47e

Please # to comment.