forked from gaelmotte/scan-me
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscancamera.js
More file actions
executable file
·141 lines (90 loc) · 3.37 KB
/
scancamera.js
File metadata and controls
executable file
·141 lines (90 loc) · 3.37 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
132
133
134
135
136
137
138
139
140
141
var express = require('express');
var fs = require('fs');
var cameralogic = require('./cameralogic');
var http = require('http');
var app = express()
var server = app.listen(3000, function () {
var host = server.address().address
var port = server.address().port
console.log('Example app listening at http://%s:%s', host, port)
});
var io = require('socket.io').listen(server);
app.use(express.static('public'));
app.use(express.static('pictures'));
app.use(express.static('raw'));
// respond with "Hello World!" on the homepage
app.get('/', function (req, res) {
res.send('Hello World!');
})
app.get('/preview/', function (req, res) {
if(cameralogic.snap(cameralogic.definitions.uld)){
res.send('starting scan at preview definition!');
}else{
res.send('cannot scan yet, the camera is already in use !');
}
})
app.get('/snap/', function (req, res) {
console.log('snap called');
if(cameralogic.snap(cameralogic.definitions.sd, res)){
console.log('starting scan at standard definition!');
}else{
res.send('cannot scan yet, the camera is already in use !');
}
})
app.get('/snap/:definition', function (req, res) {
console.log('snap called with definition');
if(cameralogic.definitions[req.params.definition]){
if( cameralogic.snap(cameralogic.definitions[req.params.definition], res) ) {
console.log('starting scan at specific definition!');
}else{
res.send('cannot scan yet, the camera is already in use !');
}
}else{
res.send('cannot scan, definition is unknown');
}
})
io.sockets.on('connection', function (socket) {
console.log('client attempting to connect');
socket.emit('status', { status: 'connected', message: 'connection established' });
socket.on('snap', function ( data ) {
//data should contain the requiered definition .
var definition = cameralogic.definitions.sd;
if(data && data.definition && cameralogic.definitions[data.definition]){
definition = cameralogic.definitions[data.definition];
}
if(cameralogic.snap(
cameralogic.definitions.sd
, function(progress, preview){
console.log('progress : '+ progress);
socket.emit('status', { status : "progress", progress : progress, imagedata : (preview ? preview.toString('base64') : null )} );
}
, function(imagename, preview){
console.log('done : '+ imagename);
socket.emit('status', { status : "done", imagname : imagename , imagedata : "image data for the whole image !"} );
}
)
){
console.log('starting scan at definition : ' + definition);
socket.emit('status' , { status : "initializing"});
}else{
socket.emit('status', { status: 'fail', message: 'Cannot scan yet, the camera is already in use !'});
}
});
});
app.get('/collection', function (req, res) {
res.send('list of images!');
//TODO : return here the list of the pictures already taken
})
app.get('/last.jpg', function (req, res, next) {
console.log('acessing last picture');
res.redirect(cameralogic.getLastPictureFilename());
;
})
app.get('/picture/:id', function (req, res) {
res.send('the picture!');
//TODO : return here the considered image
})
app.get('/raw/:id', function (req, res) {
res.send('the raw picture!');
//TODO : return here the considered image
})