forked from sallar/mac-local-rtmp-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.js
59 lines (53 loc) · 1.54 KB
/
renderer.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
const { ipcRenderer, remote, clipboard } = require('electron');
const template = require('lodash/template');
const fs = require('fs');
const path = require('path');
const filesize = require('filesize');
const shortid = require('shortid');
const randomStreamKey = shortid.generate();
const streamsTemplate = template(
fs.readFileSync(
path.join(remote.app.getAppPath(), 'assets/streams.ejs'),
'utf8'
)
);
const streamsContainer = document.getElementById('streams');
function fetchStreamInfo(port = 8000) {
fetch(`http://localhost:${port}/api/streams`)
.then(res => res.json())
.then(res => {
console.log(
Object.assign({}, res, {
rtmpUri: 'rtmp://127.0.0.1/live',
randomStreamKey,
tools: {
filesize
}
})
);
streamsContainer.innerHTML = streamsTemplate(
Object.assign({}, res, {
rtmpUri: 'rtmp://127.0.0.1/live',
randomStreamKey,
tools: {
filesize
}
})
);
[...streamsContainer.querySelectorAll('.copy')].forEach(el => {
el.addEventListener('click', e => {
e.preventDefault();
const text = el.parentElement.querySelector('code').innerText;
clipboard.writeText(text);
});
});
});
}
document.querySelector('.quit').addEventListener('click', () => {
remote.app.quit();
});
ipcRenderer.on('port-ready', (e, port) => {
fetchStreamInfo(port);
setInterval(() => fetchStreamInfo(port), 5000);
});
ipcRenderer.send('app-ready');