Skip to content

Commit

Permalink
trigger interval snapshots via web API #1030
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlt8 committed Nov 3, 2023
1 parent 8f6767a commit cbc3808
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions app/wyzebridge/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def monitor_streams(self, mtx_health: Callable) -> None:
events = WyzeEvents(self.streams) if MOTION else None
while not self.stop_flag:
event.read(timeout=1)
self.snap_all(self.active_streams())
self.snap_all()
if events:
events.check_motion()
if int(time.time()) % 15 == 0:
Expand Down Expand Up @@ -138,21 +138,21 @@ def active_streams(self) -> list[str]:
"""
return [cam for cam, s in self.streams.items() if s.health_check() > 0]

def snap_all(self, cams: list[str]):
def snap_all(self, force: bool = False):
"""
Take an rtsp snapshot of the streams in the list.
Take an rtsp snapshot of active_streams.
Args:
- force (bool, optional): Ignore interval and force snapshot. Defaults to False.
Parameters:
- cams (list[str]): names of the streams to take a snapshot of.
"""
if SNAPSHOT_TYPE != "rtsp" or not cams:
return
if time.time() - self.last_snap < SNAPSHOT_INT:
return
self.last_snap = time.time()
for cam in cams:
stop_subprocess(self.rtsp_snapshots.get(cam))
self.rtsp_snap_popen(cam, True)
if force or (
SNAPSHOT_TYPE == "rtsp" and time.time() - self.last_snap >= SNAPSHOT_INT
):
self.last_snap = time.time()
for cam in self.active_streams():
stop_subprocess(self.rtsp_snapshots.get(cam))
self.rtsp_snap_popen(cam, True)

def get_sse_status(self) -> dict:
return {
Expand All @@ -176,6 +176,10 @@ def send_cmd(
"""
resp = {"status": "error", "command": cmd, "payload": payload}

if cam_name == "all" and cmd == "update_snapshot":
self.snap_all(True)
return resp | {"status": "success"}

if not (stream := self.get(cam_name)):
return resp | {"response": "Camera not found"}

Expand Down

0 comments on commit cbc3808

Please sign in to comment.