Skip to content

Commit 50775b5

Browse files
authored
Merge pull request #111 from CameronRP/add-test-recording
Add test recording
2 parents e33846e + c72cf39 commit 50775b5

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

.goreleaser.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ builds:
1818
- "7"
1919
ldflags: -s -w -X main.version={{.Version}}
2020
hooks:
21-
pre: packr
21+
pre:
22+
- packr
23+
- tsc
2224
post: packr clean
2325
- id: "signal-strength"
2426
binary: "signal-strength"

api/api.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const (
4949
cptvGlob = "*.cptv"
5050
failedUploadsFolder = "failed-uploads"
5151
rebootDelay = time.Second * 5
52-
apiVersion = 7
52+
apiVersion = 8
5353
)
5454

5555
type ManagementAPI struct {
@@ -189,6 +189,21 @@ func (api *ManagementAPI) TakeSnapshot(w http.ResponseWriter, r *http.Request) {
189189
}
190190
}
191191

192+
// TakeSnapshotRecording will request a new snapshot recording to be taken by thermal-recorder
193+
func (api *ManagementAPI) TakeSnapshotRecording(w http.ResponseWriter, r *http.Request) {
194+
conn, err := dbus.SystemBus()
195+
if err != nil {
196+
w.WriteHeader(http.StatusInternalServerError)
197+
return
198+
}
199+
recorder := conn.Object("org.cacophony.thermalrecorder", "/org/cacophony/thermalrecorder")
200+
err = recorder.Call("org.cacophony.thermalrecorder.TakeTestRecording", 0).Err
201+
if err != nil {
202+
w.WriteHeader(http.StatusInternalServerError)
203+
return
204+
}
205+
}
206+
192207
// Reregister can change the devices name and group
193208
func (api *ManagementAPI) Reregister(w http.ResponseWriter, r *http.Request) {
194209
group := r.FormValue("group")

cmd/managementd/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ func main() {
106106
apiRouter.HandleFunc("/recording/{id}", apiObj.GetRecording).Methods("GET")
107107
apiRouter.HandleFunc("/recording/{id}", apiObj.DeleteRecording).Methods("DELETE")
108108
apiRouter.HandleFunc("/camera/snapshot", apiObj.TakeSnapshot).Methods("PUT")
109+
apiRouter.HandleFunc("/camera/snapshot-recording", apiObj.TakeSnapshotRecording).Methods("PUT")
109110
apiRouter.HandleFunc("/signal-strength", apiObj.GetSignalStrength).Methods("GET")
110111
apiRouter.HandleFunc("/reregister", apiObj.Reregister).Methods("POST")
111112
apiRouter.HandleFunc("/reboot", apiObj.Reboot).Methods("POST")

html/camera.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313

1414
<div class="container">
1515
<h2>Camera</h2>
16+
<button id="take-snapshot-recording" style="position: relative" type="button">
17+
Take test recording
18+
</button>
1619
<div id="snapshot-stopped" style="display: none">
20+
1721
<p id="snapshot-stopped-message"></p>
1822
<button id="snapshot-restart" type="button">
1923
Continue viewing camera

static/js/camera.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,32 @@ function restartCameraViewing() {
6868
}
6969
}
7070

71+
async function takeTestRecording() {
72+
document.getElementById("take-snapshot-recording")!.innerText = 'Making a test recording';
73+
document.getElementById("take-snapshot-recording")!.setAttribute("disabled", "true");
74+
console.log("making a test recording");
75+
fetch('/api/camera/snapshot-recording', {
76+
method: 'PUT',
77+
headers: {
78+
'Authorization': 'Basic YWRtaW46ZmVhdGhlcnM='
79+
}})
80+
81+
.then(response => console.log(response))
82+
.then(data => console.log(data))
83+
.catch(error => console.error(error))
84+
//TODO handle errors better and check that recording was made properly instead of just waiting..
85+
await new Promise(r => setTimeout(r, 3000));
86+
document.getElementById("take-snapshot-recording")!.removeAttribute("disabled");
87+
document.getElementById("take-snapshot-recording")!.innerText = 'Take test recording';
88+
}
89+
7190
window.onload = function () {
7291
const urlParams = new URLSearchParams(window.location.search);
7392
if (urlParams.get("timeout") == "off") {
7493
snapshotLimit = Number.MAX_SAFE_INTEGER;
7594
}
7695
document.getElementById("snapshot-restart")!.onclick = restartCameraViewing;
96+
document.getElementById("take-snapshot-recording")!.onclick = takeTestRecording;
7797
cameraConnection = new CameraConnection(
7898
window.location.hostname,
7999
window.location.port,

0 commit comments

Comments
 (0)