From b5b56e4c1854314fb519d13af9dda80a10ee0b8a Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Tue, 10 Nov 2026 10:46:04 +0100 Subject: feat(k1c): live camera stream instead of snapshots The camera was a snapshot reloaded on every poll. It is now the webcam's MJPEG stream_url, which an plays by itself at the camera's own rate (15 fps on the K1C). The stream connects only while the K1C tab is on screen and the page visible, and disconnects otherwise, so a hidden tab does not keep the printer streaming. A dropped stream hides the image and reconnects on the next poll. The image is shown as soon as its source is set, since a never-ending stream may never fire load. Co-Authored-By: Claude Opus 5.5 --- tests/test_k1c.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/test_k1c.py b/tests/test_k1c.py index 47c25ec..300a56a 100644 --- a/tests/test_k1c.py +++ b/tests/test_k1c.py @@ -35,7 +35,7 @@ STATUS = { "toolhead": {"position": [10.0, 20.0, 3.2, 100.0]}, "gcode_move": {"speed_factor": 1.0}, } -CAMS = {"result": {"webcams": [{"enabled": True, "snapshot_url": "http://printer.example.org:8080/?action=snapshot"}]}} +CAMS = {"result": {"webcams": [{"enabled": True, "stream_url": "http://printer.example.org:8080/?action=stream"}]}} class Fake: @@ -65,7 +65,7 @@ class K1C(unittest.TestCase): self.assertEqual((st["layer"], st["layers"]), (12, 80)) self.assertEqual(st["extruder"]["target"], 220.0) self.assertEqual(st["position"], [10.0, 20.0, 3.2]) - self.assertTrue(st["snapshot"].endswith("action=snapshot")) + self.assertTrue(st["camera"].endswith("action=stream")) self.assertEqual(st["thumbnail"], URL + "/server/files/gcodes/.thumbs/part-300x300.png") def test_thumbnail_is_relative_to_the_file_and_quoted(self): @@ -107,8 +107,8 @@ class K1C(unittest.TestCase): with self.assertRaises(k1c.ModuleError): m.actions["emergency_stop"]({}) - def test_snapshot_needs_http(self): - self.assertIsNone(k1c._snapshot([{"snapshot_url": "javascript:alert(1)"}])) + def test_camera_needs_http(self): + self.assertIsNone(k1c._camera([{"stream_url": "javascript:alert(1)"}])) if __name__ == "__main__": -- cgit v1.2.3