This repository was archived by the owner on Jul 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathrenderer.js
More file actions
188 lines (158 loc) · 5.96 KB
/
renderer.js
File metadata and controls
188 lines (158 loc) · 5.96 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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
const { ipcRenderer, shell, remote } = require('electron');
const path = require('path');
function initOBS() {
// Replace with await ipcRenderer.invoke when obs-studio-node will be ready to work on recent versions of Electron.
// See https://github.com/stream-labs/obs-studio-node/issues/605
const result = ipcRenderer.sendSync('recording-init');
if (result) {
ipcRenderer.on("performanceStatistics", (_event, data) => onPerformanceStatistics(data));
}
}
function startRecording() {
const result = ipcRenderer.sendSync('recording-start');
console.debug("启动录制 result:", result);
return result;
}
function stopRecording() {
const result = ipcRenderer.sendSync('recording-stop');
console.debug("停止录制 result:", result);
return result;
}
let recording = false;
let recordingStartedAt = null;
let timer = null;
function getSetting() {
const cate = document.getElementById('OBSSettingsCategories')
const result = ipcRenderer.sendSync('getSetting',{name:cate.options[cate.selectedIndex].text});
console.log(result)
}
function cameraSelectChange() {
const select = document.getElementById('cameraSelect')
//const result = ipcRenderer.sendSync('cameraSelect',{id:select.options[select.selectedIndex].value});
//console.log(result)
}
function displaySelectChange() {
const select = document.getElementById('displaySelect')
const result = ipcRenderer.sendSync('selectDisPlay',{id:select.options[select.selectedIndex].value});
console.log(result)
}
function switchRecording() {
if (recording) {
recording = stopRecording().recording;
} else {
recording = startRecording().recording;
}
updateUI();
}
function updateUI() {
const button = document.getElementById('rec-button');
button.disabled = false;
if (recording) {
button.innerText = '⏹️ 停止录制'
startTimer();
} else {
button.innerText = '⏺️ 启动录制'
stopTimer();
}
const rtmp_server = document.getElementById('rtmp_server');
const rtmp_key = document.getElementById('rtmp_key');
const streamSettings = ipcRenderer.sendSync('getSetting',{name:'Stream'});
streamSettings.forEach(subCate => {
subCate.parameters.forEach(parameter => {
switch (parameter.name) {
case 'service' : {
break;
}
case 'server': {
rtmp_server.value = parameter.currentValue;
break;
}
case 'key': {
rtmp_key.value = parameter.currentValue;
break;
}
}
})
})
const displaySelect = document.getElementById('displaySelect')
remote.screen.getAllDisplays().forEach(function (dispaly,index){
displaySelect.options.add(new Option(dispaly.size.height+"*"+dispaly.size.width,index));
})
//设置主显示器
displaySelect.selectedIndex = 0;
displaySelectChange()
const cameras = ipcRenderer.sendSync('getALlCameras');
const cameraSelect = document.getElementById('cameraSelect')
cameras.forEach(function (camera){
cameraSelect.options.add(new Option(camera.name,camera.value));
})
const allScene = ipcRenderer.sendSync('getAllScene');
console.log(allScene)
const sceneSelect = document.getElementById('sceneSelect')
allScene.forEach(function (scene){
sceneSelect.options.add(new Option(scene.name,scene.name));
})
sceneSelect.selectedIndex = 0;
const sourceSelect = document.getElementById('sourceSelect')
if(allScene.length == 1){
allScene[0].items.forEach(function (item){
sourceSelect.options.add(new Option(item,item));
})
}
}
function showSourceInfo() {
const sourceSelect = document.getElementById('sourceSelect')
const result = ipcRenderer.sendSync('showSourceInfo',{id:sourceSelect.options[sourceSelect.selectedIndex].value});
console.log(result)
document.getElementById('response').innerHTML = JSON.stringify(result)
}
function startTimer() {
recordingStartedAt = Date.now();
timer = setInterval(updateTimer, 100);
}
function stopTimer() {
clearInterval(timer);
}
function updateTimer() {
const diff = Date.now() - recordingStartedAt;
const timerElem = document.getElementById('rec-timer');
const decimals = `${Math.floor(diff % 1000 / 100)}`;
const seconds = `${Math.floor(diff % 60000 / 1000)}`.padStart(2, '0');
const minutes = `${Math.floor(diff % 3600000 / 60000)}`.padStart(2, '0');
const hours = `${Math.floor(diff / 3600000)}`.padStart(2, '0');
timerElem.innerText = `${hours}:${minutes}:${seconds}.${decimals}`;
}
function openFolder() {
shell.openItem(path.join(__dirname, 'videos'));
}
function onPerformanceStatistics(data) {
document.querySelector(".performanceStatistics #cpu").innerText = `${data.CPU} %`;
document.querySelector(".performanceStatistics #cpuMeter").value = data.CPU;
document.querySelector(".performanceStatistics #numberDroppedFrames").innerText = data.numberDroppedFrames;
document.querySelector(".performanceStatistics #percentageDroppedFrames").innerText = `${data.percentageDroppedFrames} %`;
document.querySelector(".performanceStatistics #bandwidth").innerText = data.bandwidth;
document.querySelector(".performanceStatistics #frameRate").innerText = `${Math.round(data.frameRate)} fps`;
}
const previewContainer = document.getElementById('preview');
function setupPreview() {
const { width, height, x, y } = previewContainer.getBoundingClientRect();
const result = ipcRenderer.sendSync('preview-init', { width, height, x, y });
previewContainer.style = `height: ${result.height}px`;
}
function resizePreview() {
const { width, height, x, y } = previewContainer.getBoundingClientRect();
const result = ipcRenderer.sendSync('preview-bounds', { width, height, x, y });
previewContainer.style = `height: ${result.height}px`;
}
const currentWindow = remote.getCurrentWindow();
currentWindow.on('resize', resizePreview);
document.addEventListener("scroll", resizePreview);
var ro = new ResizeObserver(resizePreview);
ro.observe(document.querySelector("#preview"));
try {
initOBS();
setupPreview();
updateUI();
} catch (err) {
console.log(err)
}