-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
64 lines (51 loc) · 1.45 KB
/
app.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const { app, BrowserWindow } = require('electron');
const { v4: uuidv4 } = require('uuid');
const screenshot = require('screenshot-desktop');
const io = require('socket.io-client');
let socket;
function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
},
});
win.loadFile('index.html');
// Establish socket connection when the window is ready
win.webContents.on('did-finish-load', () => {
// Connect to the server
socket = io('http://localhost:5000');
// Generate a unique client ID
const clientId = uuidv4();
// Send the client ID to the server
socket.emit('join-message', clientId);
// Capture and send screenshots every 100 milliseconds
setInterval(() => {
screenshot().then((img) => {
const imgStr = Buffer.from(img).toString('base64');
const obj = {
room: clientId,
image: imgStr,
};
// Send the screenshot data to the server
socket.emit('screen-data', JSON.stringify(obj));
});
}, 100);
// Handle disconnection
socket.on('disconnect', () => {
console.log('Disconnected from the server');
});
});
}
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});