-
Notifications
You must be signed in to change notification settings - Fork 88
/
main.js
92 lines (79 loc) · 1.9 KB
/
main.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
const NodeMediaServer = require('node-media-server');
const getPort = require('get-port');
const electron = require('electron');
const path = require('path');
const { menubar: Menubar } = require('menubar');
require('electron-context-menu')();
const { app, BrowserWindow, Tray, Menu, ipcMain } = electron;
const currentStreams = new Set();
const ASSET_PATH = path.join(app.getAppPath(), 'assets');
function changeMenubarState() {
if (currentStreams.size > 0) {
// set recording
menubar.tray.setImage(path.resolve(ASSET_PATH, 'img/recording.png'));
} else {
// set normal
menubar.tray.setImage(path.resolve(ASSET_PATH, 'img/readyTemplate.png'));
}
}
const menubar = Menubar({
dir: ASSET_PATH,
icon: path.resolve(ASSET_PATH, 'img/readyTemplate.png'),
height: 200,
transparent: true,
preloadWindow: true,
browserWindow: {
height: 200,
webPreferences: {
nodeIntegration: true
}
}
});
(async () => {
const port = await getPort();
const nms = new NodeMediaServer({
rtmp: {
port: 1935,
chunk_size: 60000,
gop_cache: true,
ping: 60,
ping_timeout: 30
},
http: {
port,
mediaroot: './media',
allow_origin: '*'
},
trans: {
ffmpeg: '/usr/local/bin/ffmpeg',
tasks: [
{
app: 'live',
ac: 'aac',
hls: true,
hlsFlags: '[hls_time=2:hls_list_size=3:hls_flags=delete_segments]'
}
]
}
});
nms.on('prePublish', id => {
if (!currentStreams.has(id)) {
currentStreams.add(id);
}
changeMenubarState();
});
nms.on('donePublish', id => {
currentStreams.delete(id);
changeMenubarState();
});
nms.run();
menubar.on('ready', () => {
changeMenubarState();
});
ipcMain.on('app-ready', event => {
event.sender.send('port-ready', port);
});
ipcMain.on('error', event => {
console.error(event);
});
})();