-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhost.js
More file actions
68 lines (50 loc) · 1.68 KB
/
Copy pathhost.js
File metadata and controls
68 lines (50 loc) · 1.68 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
const { app, BrowserWindow, ipcMain, ipcRenderer } = require('electron')
const OBSWebSocket = require('obs-websocket-js').OBSWebSocket;
const fs = require('fs')
let config_path = fs.existsSync('data/config.local.json') ? 'data/config.local.json' : 'data/config.json'
let config = JSON.parse(fs.readFileSync(config_path))
async function start_recording(obs) {
await obs.call('StartRecord')
}
async function stop_recording(obs) {
await obs.call('StopRecord')
}
const createWindow = async () => {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
})
const obs = new OBSWebSocket();
const { obsWebSocketVersion, negotiatedRpcVersion } =
await obs.connect(`${config.obs_websocket.ip}:${config.obs_websocket.port}`);
console.log(`Connected to server ${obsWebSocketVersion} (using RPC ${negotiatedRpcVersion})`)
let recording_range = JSON.parse(fs.readFileSync('data/playback_new.json'))
let start = recording_range.startFrame
let end = recording_range.endFrame
let duration = (end - start) + (3 * 60)
loaded = new Promise(resolve => ipcMain.on('[LOADED]', resolve))
await win.loadFile('ddr.html')
await loaded;
win.webContents.send('[START]')
await new Promise(resolve => ipcMain.on('[0]', resolve))
await start_recording(obs)
await new Promise(resolve => ipcMain.on('[STOP]', resolve))
await stop_recording(obs)
await obs.disconnect()
win.close()
}
app.whenReady().then(() => {
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})