Skip to content

Commit 8292d42

Browse files
committed
Adding manual recordings control in the WebUI
1 parent 9c0266c commit 8292d42

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

res/index.html

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
}
139139

140140
function setSource(id, src) {
141-
var frame = document.getElementById(id), ext = ".mp4";
141+
var frame = document.getElementById(id), ext = '.mp4';
142142
if (frame.firstChild) frame.firstChild.src = "#";
143143
if (src.indexOf(ext, src.length - ext.length) > -1)
144144
frame.innerHTML = '<video id="player" width="100%" autoplay controls> \
@@ -151,6 +151,33 @@
151151
while (frame.firstChild) frame.removeChild(frame.firstChild);
152152
}
153153

154+
function toggleRecord(btn) {
155+
if (!btn) return;
156+
157+
var req = new XMLHttpRequest(), act = '';
158+
req.onreadystatechange = function() {
159+
if (this.readyState != 4 || this.status != 200) return;
160+
var dec = JSON.parse(req.responseText);
161+
for (var key in dec) {
162+
if (!dec.hasOwnProperty(key)) continue;
163+
if (key != 'recording') continue;
164+
if (dec[key] == true) {
165+
btn.innerHTML = 'Stop';
166+
btn.className = 'btn error';
167+
} else {
168+
btn.innerHTML = 'Start';
169+
btn.className = 'btn primary';
170+
}
171+
}
172+
}
173+
switch (btn.innerHTML) {
174+
case 'Start': act = '?start'; break;
175+
case 'Stop': act = '?stop'; break;
176+
}
177+
req.open('GET', '/api/record' + act);
178+
req.send();
179+
}
180+
154181
function every5Sec() {
155182
apiRead('status');
156183
}
@@ -162,6 +189,7 @@
162189
apiRead('mjpeg');
163190
apiRead('night');
164191
apiRead('record');
192+
toggleRecord(document.getElementById('record_state'));
165193
apiRead('time');
166194

167195
duplicateRows('osd', 10);
@@ -245,6 +273,7 @@ <h2 class="unl">Media</h2>
245273
<td><input type="number" id="record_segment_size"></td>
246274
</tr>
247275
</table>
276+
<button id="record_state" class="btn" onclick="toggleRecord(this)"></button>
248277
<a href="javascript:apiApply('record')" class="btn right">Apply</a>
249278
</fieldset>
250279
</div>

src/server.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ void respond_request(http_request_t *req) {
13161316
"Content-Type: application/json;charset=UTF-8\r\n"
13171317
"Connection: close\r\n"
13181318
"\r\n"
1319-
"{\"recording\":%s,\"start_time\":\"%s\",\"continuous\":\"%s\",\"path\":\"%s\","
1319+
"{\"recording\":%s,\"start_time\":\"%s\",\"continuous\":%s,\"path\":\"%s\","
13201320
"\"filename\":\"%s\",\"segment_duration\":%d,\"segment_size\":%d}",
13211321
recordOn ? "true" : "false", start_time, app_config.record_continuous ? "true" : "false",
13221322
app_config.record_path, app_config.record_filename,

0 commit comments

Comments
 (0)