-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
42 lines (35 loc) · 1.1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var Campi = require('campi'),
app = require('express')(),
http = require('http').Server(app),
io = require('socket.io')(http),
base64 = require('base64-stream');
var campi = new Campi();
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
});
http.listen(3000, function () {
var busy = false;
console.log('listening on port 3000');
setInterval(function () {
if (!busy) {
busy = true;
campi.getImageAsStream({
width: 640,
height: 480,
shutter: 200000,
timeout: 1,
nopreview: true
}, function (err, stream) {
var message = '';
var base64Stream = stream.pipe(base64.encode());
base64Stream.on('data', function (buffer) {
message += buffer.toString();
});
base64Stream.on('end', function () {
io.sockets.emit('image', message);
busy = false;
});
});
}
}, 100);
});