The session-stream web app: a single HTTP listener (9988) that serves a page
per enabled session, keyed by a spoken phrase. Off by default, so a stream
exists only for the sessions it was enabled on.
src/hhstream_live/phrase.py four EFF-large words + a 5-char base-36 tail
(~77.5 bits); the phrase is the password
src/hhstream_live/publisher.py one capture thread + one frame slot per
output; one slot/no queue; capture paused at
zero viewers
src/hhstream_live/server.py the router: /, /<phrase>/, /stream.mjpg,
/frame.jpg, /status.json; unknown phrase is
an empty 404, rate-limited
src/hhstream_live/pages.py the built-in dark pages (no CDN, no build)
src/hhstream_live/__main__.py hhstream-live serve|phrase, standalone
The root page is a form, never a list: the phrase is known only by whoever
enabled the stream. Transport is MJPEG (multipart/x-mixed-replace), reusing
the JPEG grim already produces. Not yet wired to the broker -- that is
stage 2. Tests: tests/live (51).
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
"""The command line: it aims a capture at an output, and it can mint a phrase."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import io
|
|
from contextlib import redirect_stdout
|
|
|
|
import pytest
|
|
from hhstream_live.__main__ import DEFAULT_CAPTURE, capture_argv, main, parse_stream
|
|
|
|
|
|
def test_capture_command_is_aimed_by_inserting_the_output_before_stdout():
|
|
assert capture_argv(DEFAULT_CAPTURE, "hh-demo") == [
|
|
"grim", "-c", "-t", "jpeg", "-q", "80", "-o", "hh-demo", "-",
|
|
]
|
|
|
|
|
|
def test_capture_command_without_a_trailing_dash_gets_the_output_appended():
|
|
assert capture_argv(["grim", "-t", "jpeg"], "hh-x") == [
|
|
"grim", "-t", "jpeg", "-o", "hh-x",
|
|
]
|
|
|
|
|
|
def test_parse_stream_reads_a_pair_and_normalizes_the_phrase():
|
|
assert parse_stream("Amber-Otter-Lantern-Harbor-7K2QP=hh-demo") == (
|
|
"amber-otter-lantern-harbor-7k2qp", "hh-demo",
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("bad", ["no-equals-sign", "=hh-demo", "phrase=", "ab=hh"])
|
|
def test_parse_stream_rejects_a_bad_pair(bad):
|
|
import argparse
|
|
|
|
with pytest.raises(argparse.ArgumentTypeError):
|
|
parse_stream(bad)
|
|
|
|
|
|
def test_the_phrase_subcommand_prints_a_phrase():
|
|
out = io.StringIO()
|
|
with redirect_stdout(out):
|
|
assert main(["phrase"]) == 0
|
|
printed = out.getvalue().strip()
|
|
assert printed.count("-") == 4 # four words + tail
|
|
|
|
|
|
def test_the_phrase_subcommand_can_print_several():
|
|
out = io.StringIO()
|
|
with redirect_stdout(out):
|
|
main(["phrase", "--count", "3"])
|
|
assert len(out.getvalue().split()) == 3
|