diff --git a/api.go b/api.go
index d107dc6..8b96def 100644
--- a/api.go
+++ b/api.go
@@ -13,6 +13,7 @@ import (
"net/http/httputil"
"net/url"
"os"
+ "path/filepath"
"strings"
"time"
)
@@ -27,9 +28,19 @@ func (s *Server) handleCameras(w http.ResponseWriter, r *http.Request) {
statuses := make([]CameraStatus, 0, len(s.appConfig.Cameras))
for _, cam := range s.appConfig.Cameras {
+ online := false
+ // Check if latest.jpg was recently updated.
+ camDir := cam.Name
+ if camDir == "" {
+ camDir = cam.ID
+ }
+ snapFile := filepath.Join(s.appConfig.Storage.RecordingsPath, camDir, "latest.jpg")
+ if info, err := os.Stat(snapFile); err == nil {
+ online = time.Since(info.ModTime()) < 10*time.Second
+ }
statuses = append(statuses, CameraStatus{
CameraConfig: cam,
- Online: false, // TODO: real stream health check in M2
+ Online: online,
Uptime: "n/a",
Streams: 0,
})
@@ -56,9 +67,16 @@ func (s *Server) handleCameraByID(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
+ online := false
+ camDir := cam.Name
+ if camDir == "" { camDir = cam.ID }
+ snapFile := filepath.Join(s.appConfig.Storage.RecordingsPath, camDir, "latest.jpg")
+ if info, err := os.Stat(snapFile); err == nil {
+ online = time.Since(info.ModTime()) < 10*time.Second
+ }
status := CameraStatus{
CameraConfig: *cam,
- Online: false,
+ Online: online,
Uptime: "n/a",
Streams: 0,
}
diff --git a/public/app.js b/public/app.js
index 97b5203..1512aa3 100644
--- a/public/app.js
+++ b/public/app.js
@@ -104,7 +104,7 @@ function renderLiveGrid() {
-
+
${cam.name}
`;
tile.addEventListener('click', () => openFocus(cam));