feat(live): one port, a router, and a phrase per session (stage 1)
The session-stream web app: a single HTTP listener (9988) that serves a page
per enabled session, keyed by a spoken phrase.
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. Tests: tests/live (51), all green with the full suite
(958). Not yet wired to the broker -- that is stage 2.
This commit is contained in:
1 parent
edbf15f259
commit
d770bcd298
17 files changed
+9330
-18
No files matched your search
@@ -0,0 +1,86 @@
|
||||
"""Fixtures for the session-stream web app suite.
|
||||
|
||||
Everything is standard library and everything is in-process: a real
|
||||
`LiveServer` on a loopback ephemeral port, fed by a stub capture, with plain
|
||||
`http.client` for the requests. No compositor, no `grim`, no broker.
|
||||
|
||||
The doubles (`StubCapture`, `read_parts`, `PHRASE`) live in `live_helpers.py`, not
|
||||
here, so the tests import them by a plain module name -- the same shape as
|
||||
`tests/unit`.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import http.client
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
_HERE = pathlib.Path(__file__).resolve().parent
|
||||
_SRC = _HERE.parents[1] / "src"
|
||||
for _path in (str(_HERE), str(_SRC)):
|
||||
if _path not in sys.path:
|
||||
sys.path.insert(0, _path)
|
||||
|
||||
from fake_jpeg import jpeg_bytes # noqa: E402
|
||||
from live_helpers import PHRASE, StubCapture # noqa: E402
|
||||
from hhstream_live.publisher import StreamRegistry, StreamSpec # noqa: E402
|
||||
from hhstream_live.server import LiveServer, RateLimiter # noqa: E402
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def jpg():
|
||||
return jpeg_bytes
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def registry():
|
||||
reg = StreamRegistry()
|
||||
yield reg
|
||||
reg.stop_all()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def serve(registry):
|
||||
"""`with serve(phrase=..., capture=..., fps=...) as (server, capture)`."""
|
||||
servers: list[LiveServer] = []
|
||||
|
||||
@contextlib.contextmanager
|
||||
def _serve(*, phrase: str = PHRASE, capture: StubCapture | None = None,
|
||||
fps: int = 5, label: str = "demo", limit: int = 30):
|
||||
capture = capture or StubCapture()
|
||||
spec = StreamSpec(phrase=phrase, output="hh-demo", fps=fps, session="demo",
|
||||
label=label)
|
||||
registry.add(spec, capture)
|
||||
server = LiveServer(registry, host="127.0.0.1", port=0,
|
||||
limiter=RateLimiter(limit=limit))
|
||||
servers.append(server)
|
||||
server.start()
|
||||
assert server.ready.wait(5)
|
||||
try:
|
||||
yield server, capture
|
||||
finally:
|
||||
server.stop()
|
||||
|
||||
yield _serve
|
||||
for server in servers:
|
||||
with contextlib.suppress(Exception):
|
||||
server.stop()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def http_conn():
|
||||
"""Open an HTTP connection to a running server; closed at teardown."""
|
||||
connections: list[http.client.HTTPConnection] = []
|
||||
|
||||
def _connect(server: LiveServer, timeout: float = 10.0) -> http.client.HTTPConnection:
|
||||
conn = http.client.HTTPConnection("127.0.0.1", server.port, timeout=timeout)
|
||||
connections.append(conn)
|
||||
return conn
|
||||
|
||||
yield _connect
|
||||
for conn in connections:
|
||||
with contextlib.suppress(Exception):
|
||||
conn.close()
|
||||
Reference in new issue
Block a user