Repository navigation
Add raw MJPEG frames and caller-owned stream WebSockets - #54
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Home Assistant integration reads MJPEG frames and opens the WebRTC signaling WebSocket by reaching into the client's private session, HTTP session and SSL config, and by building the session cookie itself. This adds the two public methods it needs to stop doing that.
Changes
mjpeg_stream_bytes()yields each MJPEG frame as raw JPEG bytes.mjpeg_stream()is now this generator plus the decoding it already did.open_ws(path, **kwargs)opens a new WebSocket onpath, relative to the API base, such asstream/h264/webrtc. Each call returns its own connection and the caller closes it.kwargsgo to aiohttp'sws_connect, for exampleheartbeatandtimeout.get_ws()shares the connection code. Building the ws/wss URL, the isolated cookie jar, the session cookie and the SSL config moved into one helper used by both, as did the handling of 401 and 403 on the handshake.Notes
open_wsrejectsheadersandsslwithTypeError. The client owns both.open_wsis not closed bylogout()or by leaving the client'sasync with. The caller must close it before the client exits.NanoKVMNotAuthenticatedError; a 403 raisesNanoKVMPermissionErrorwith the requested path.mjpeg_stream_bytes()should wrap it incontextlib.aclosingso the HTTP connection closes right away.Behaviour changes
None. Both methods are additions, and
mjpeg_stream()and the HID WebSocket behave as before.Testing
404 unit tests pass, 2 of them new. Also run against a NanoKVM PCIe:
mjpeg_stream_bytes()returned a JPEG frame andopen_ws("stream/h264")connected while the HID WebSocket stayed open. On a NanoKVM Pro,open_ws("stream/h264/webrtc")opened two separate connections over HTTPS, again without affecting the HID WebSocket. MJPEG was not opened on the Pro, because that switches its video mode.