-
Notifications
You must be signed in to change notification settings - Fork 53
/
record.js
145 lines (113 loc) · 4.05 KB
/
record.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
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
142
143
144
145
const electron = require('electron');
const spawn = require('child_process').spawn;
const path = require('path')
const url = require('url')
const BrowserWindow = electron.BrowserWindow;
const ipcMain = electron.ipcMain;
/*
* Start the recording process
*/
const separatedProcess = spawn(process.execPath, ['./recordings.js', 10000, 'sp'], {stdio: [0, 1, 2, 'ipc']});
const postfilteredProcess = spawn(process.execPath, ['./recordings.js', 10010, 'pf'], {stdio: [0, 1, 2, 'ipc']});
exports.quit = function quit() {
separatedProcess.kill();
postfilteredProcess.kill();
}
/*
* Manage the recordings window
*/
let recordingsWindow;
function createWindow () {
if(recordingsWindow != null) {
recordingsWindow.show();
}
else {
recordingsWindow = new BrowserWindow({
width: 900, height: 700,
webPreferences: {
nodeIntegration : true
},
show:false
});
recordingsWindow.loadURL(url.format({
pathname: path.join(__dirname, 'views/recordings.html'),
protocol: 'file:',
slashes: true
}));
// Emitted when the window is closed.
recordingsWindow.on('closed', function () {
if(separatedProcess.connected)
separatedProcess.send({event:'stop-recording'});
recordingsWindow = null;
});
recordingsWindow.on('ready-to-show', function() {
recordingsWindow.show()
});
}
}
ipcMain.on('open-recordings-window', createWindow);
/*
* Pass commands between main process and recording process
*/
// Receive from live and record window
ipcMain.on('new-recording', (event, index, id) => {
if(separatedProcess.connected)
separatedProcess.send({event:'new-recording', index:index, id:id});
if(postfilteredProcess.connected)
postfilteredProcess.send({event:'new-recording', index:index, id:id});
});
ipcMain.on('end-recording', (event, index) => {
if(separatedProcess.connected)
separatedProcess.send({event:'end-recording', index:index});
if(postfilteredProcess.connected)
postfilteredProcess.send({event:'end-recording', index:index});
});
ipcMain.on('start-recording', (event, workspace) => {
if(separatedProcess.connected)
separatedProcess.send({event:'start-recording', workspace:workspace});
if(postfilteredProcess.connected)
postfilteredProcess.send({event:'start-recording', workspace:workspace});
});
ipcMain.on('stop-recording', (event) => {
if(separatedProcess.connected)
separatedProcess.send({event:'stop-recording'});
if(postfilteredProcess.connected)
postfilteredProcess.send({event:'stop-recording'});
});
// Receive from record process
separatedProcess.on('message', m => {
if(recordingsWindow != null) {
switch(m.event) {
case 'fuzzy-transcript':
recordingsWindow.webContents.send('fuzzy-transcript', m.filename, m.data);
break;
case 'fuzzy-recording':
recordingsWindow.webContents.send('fuzzy-recording', m.filename);
break;
case 'add-recording':
recordingsWindow.webContents.send('add-recording', m.filename);
break;
default:
console.warn(`Unhandled recording process message ${m}`);
break;
}
}
});
postfilteredProcess.on('message', m => {
if(recordingsWindow != null) {
switch(m.event) {
case 'fuzzy-transcript':
recordingsWindow.webContents.send('fuzzy-transcript', m.filename, m.data);
break;
case 'fuzzy-recording':
recordingsWindow.webContents.send('fuzzy-recording', m.filename);
break;
case 'add-recording':
recordingsWindow.webContents.send('add-recording', m.filename);
break;
default:
console.warn(`Unhandled recording process message ${m}`);
break;
}
}
});