Skip to content

Raise NanoKVMInvalidResponseError for empty snapshots, use get_snapshot in examples - #68

Merged
chiconws merged 2 commits into
devfrom
fix/snapshot-error-and-examples
Oct 30, 2026
Merged

chiconws merged 2 commits into
devfrom
fix/snapshot-error-and-examples

Conversation

@chiconws

@chiconws chiconws commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Carries over two ideas from #61 by @antoniovazquezblanco, which was closed as superseded by get_snapshot() from #65. He is credited as co-author on the commit.

Changes

  • get_snapshot() raises NanoKVMInvalidResponseError when the MJPEG stream ends before any frame, instead of the base NanoKVMError. docs/streaming.md says so.
  • Examples. The README and docs/sync.md save a screenshot with get_snapshot() instead of breaking out of an mjpeg_stream() / mjpeg_stream_bytes() loop.
  • get_snapshot(interrupt_webrtc=True) works on the Pro. Opening MJPEG there ends any WebRTC session in progress, so the Pro still refuses by default, and the error names the flag.

Behaviour changes

  • The empty-stream error is now NanoKVMInvalidResponseError. It subclasses NanoKVMError, so existing handlers still catch it.

Testing

520 unit tests pass, 1 of them new. Against a NanoKVM Pro 1.2.15 with an aiortc peer, repeated 3 times: a snapshot during a WebRTC session ends it with NanoKVMVideoModeError; a session started afterwards decodes ~60 fps without changing the stream mode; a snapshot with no session open has no effect on later ones.

chiconws and others added 2 commits October 29, 2026 23:27
…ot in examples

get_snapshot() raised the base NanoKVMError when the MJPEG stream ended
before any frame; it now raises NanoKVMInvalidResponseError, a subclass,
so existing handlers still catch it. The README and blocking-client
examples save a screenshot with get_snapshot() instead of breaking out
of a stream loop.

Both come from #61.

Co-authored-by: Antonio Vázquez Blanco <[email protected]>
get_snapshot() refused the Pro outright, because opening MJPEG there
ends any WebRTC session in progress. Callers that know no session is
open, or accept losing it, can now pass interrupt_webrtc=True. Without
it the Pro still refuses, and the error names the flag.

Measured on a Pro 1.2.15: the interrupted session raises
NanoKVMVideoModeError and does not recover, while a session started
after the snapshot gets video without changing the stream mode.
@chiconws
chiconws merged commit 1b6c317 into dev Oct 30, 2026
2 checks passed
@chiconws
chiconws deleted the fix/snapshot-error-and-examples branch October 30, 2026 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant