-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
81 lines (68 loc) · 1.85 KB
/
main.js
File metadata and controls
81 lines (68 loc) · 1.85 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
const { app, BrowserWindow } = require('electron');
const express = require('express');
const bodyParser = require('body-parser');
const server = express();
const serverPort = 8000; // Define a port for the HTTP server
var NodeWebcam = require("node-webcam");
server.use(bodyParser.json({ limit: '50mb' }));
let mainWindow;
// Default options
var opts = {
width: 1280,
height: 720,
quality: 100,
delay: 0,
saveShots: true,
output: "jpeg",
device: false,
callbackReturn: "location",
verbose: false
};
var Webcam = NodeWebcam.create(opts);
// Capture image
Webcam.capture("test_picture", function(err, data) {
if (err) {
console.error(err);
} else {
console.log("Image saved:", data);
}
});
function createWindow() {
const path = require('path');
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js'), // Make sure this path is correct
contextIsolation: true,
nodeIntegration: false
}
});
mainWindow.loadFile('index.html');
mainWindow.on('closed', () => {
mainWindow = null;
});
// Start the Express server within the Electron app
server.post('/image', (req, res) => {
const imageBase64 = req.body.image;
console.log("Received an image");
if (mainWindow) {
mainWindow.webContents.send('image', imageBase64);
}
res.send('Image received');
});
server.listen(serverPort, () => {
console.log(`Server listening on port ${serverPort}`);
});
}
app.on('ready', createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (mainWindow === null) {
createWindow();
}
});