-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpull_jpg.js
42 lines (35 loc) · 1.03 KB
/
pull_jpg.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
const { app, BrowserWindow } = require('electron')
const Koa = require('koa');
const kapp = new Koa();
const cors = require('@koa/cors');
kapp.use(cors());
app.disableHardwareAcceleration()
app.commandLine.appendSwitch('force-device-scale-factor', '1');
let win
app.once('ready', () => {
win = new BrowserWindow({
show: false,
frame: false,
width: 1920,
height: 1080,
webPreferences: {
offscreen: true,
transparent: true
}
})
let counter = 0;
let lastBuf = Buffer.alloc(8294400);
win.loadURL('https://app.singular.live/output/3KTkvd53TvQHZ95Q4Bg0Ld/Default?aspect=16:9')
// win.webContents.enableDeviceEmulation({ screenSize: { width: 1920, height: 1080 }, viewSize: { width: 1920, height: 1080 }});
win.webContents.on('paint', (event, dirty, image) => {
console.log(counter++, dirty);
lastBuf = image.toJPEG(50);
})
win.webContents.setFrameRate(25)
kapp.use(async ctx => {
ctx.type = 'image/jpeg';
ctx.body = lastBuf;
})
let server = kapp.listen(3000);
process.on('SIGHUP', server.close)
})