-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
132 lines (102 loc) · 2.95 KB
/
server.js
File metadata and controls
132 lines (102 loc) · 2.95 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
var express = require('express');
var app = express();
const path = require('path');
var http = require('http').Server(app);
var io = require('socket.io')(http);
var fs = require('fs');
app.set('views', __dirname + '/views')
app.set('view engine', 'jade')
app.use(express.static('public'));
var photos = fs.readdirSync(__dirname + '/public/photos/').filter(function(e) {
return e.indexOf('.jpg') != -1;
});
var takingPhoto = false;
app.get('/', function (req, res) {
res.render('index',
{ pics : fs.readdirSync(__dirname + '/public/photos/').filter(function(e) {
return e.indexOf('.jpg') != -1;
}) }
);
});
app.use('/gallery', require('node-gallery')({
staticFiles : 'public/photos',
urlRoot : 'gallery',
title : 'Hochzeitsgallerie',
render : false //
}), function(req, res, next){
return res.render('gallery', { galleryHtml : req.html });
});
io.on('connection', function(socket){
console.log('a user connected');
socket.on('take photo', function() {
console.log('taki photo!!');
takePicture();
});
});
http.listen(3000, function(){
console.log('listening on *:3000');
var open = require('open');
open('http://localhost:3000');
});
var gphoto2 = require('gphoto2');
var GPhoto = new gphoto2.GPhoto2();
var camera;
// List cameras / assign list item to variable to use below options
GPhoto.list(function (list) {
if (list.length === 0) return;
camera = list[0];
console.log('Found', camera.model);
});
function takePicture() {
if (takingPhoto) {
return;
}
takingPhoto = true;
deactivateSlideshow();
io.emit('taking photo');
setTimeout(function() {
camera.takePicture({download: true}, function (er, data) {
io.emit('loading');
var fileName = new Date();
var path = __dirname + '/public/photos/';
fs.writeFileSync('archive/' + fileName + '.jpg', data);
var epeg = require("epeg");
var image = new epeg.Image({data: data});
buffer = image.downsize(1280, 900).process();
fs.writeFileSync(path + fileName + '.jpg', buffer);
photos.push(fileName + '.jpg');
io.emit('new photo', fileName + '.jpg');
activateSlideshow();
takingPhoto = false;
});
}, 5000);
}
var slideshowInterval = null;
var slideshowTimer = null;
activateSlideshow();
function activateSlideshow() {
slideshowTimer = setTimeout(function() {
slideshowInterval = setInterval(function() {
io.emit('show photo', photos[Math.floor(Math.random() * photos.length)]);
}, 6000);
}, 30000);
}
function deactivateSlideshow() {
if (slideshowTimer) {
clearTimeout(slideshowTimer);
slideshowTimer = null;
}
if (slideshowInterval) {
clearInterval(slideshowInterval);
slideshowInterval = null;
}
}
// var Gpio = require('pigpio').Gpio;
// var button = new Gpio(4, {
// mode: Gpio.INPUT,
// pullUpDown: Gpio.PUD_DOWN,
// edge: Gpio.EITHER_EDGE
// });
// button.on('interrupt', function (level) {
// console.log('button pressed');
// });