Vuer

vuer.webrtc

WebRTC streaming support for Vuer.

Provides BGRArrayVideoStreamTrack, WebRTCStream, and WebRTCStreamManager for hosting WebRTC video streams on Vuer's existing aiohttp server.

Requires: pip install vuer[webrtc]

serve_debug_page

python
async def serve_debug_page(request)

Source

Serve the WebRTC debug page (standalone, no manager required).

WebRTCStream

python
class WebRTCStream

Source

A single WebRTC stream that can serve video to multiple peers.

Two usage modes:

  • High-level: omit track, use push_frame(bgr_numpy) to send frames.
  • Low-level: provide a custom track, frames come from the track itself.

WebRTCStream.init

python
def __init__(self, stream_id, vuer, track=None, codec='H264', max_bitrate=None, max_framerate=None, resolution=None)

Source

Args: stream_id: Unique identifier for the stream. vuer: The Vuer server instance. track: Optional custom MediaStreamTrack. If None, creates an internal track and enables push_frame(). codec: Preferred codec ("H264" or "VP8"). Default "H264". max_bitrate: Maximum bitrate in bps (e.g. 2_000_000 for 2 Mbps). None means encoder default. max_framerate: Maximum frames per second (e.g. 15, 30). None means no limit. resolution: Tuple of (width, height) for the black fallback frame when no frames are being pushed. Default (640, 480).

WebRTCStream.ready

python
def ready(self)

Source

Whether the stream's event loop has been set (server is running).

WebRTCStream.wait_ready_sync

python
def wait_ready_sync(self, timeout=10)

Source

Block the current thread until the stream is ready.

Args: timeout: Maximum seconds to wait. Raises TimeoutError if exceeded.

WebRTCStream.push_frame

python
def push_frame(self, bgr_numpy)

Source

Push a BGR numpy frame to the stream (thread-safe).

Only available when no custom track was provided.

WebRTCStream.endpoint

python
def endpoint(self)

Source

Full URL for this stream's offer endpoint.

WebRTCStream.url

python
def url(self)

Source

Path-only URL for this stream's offer endpoint.

WebRTCStream.handle_offer

python
async def handle_offer(self, request)

Source

Handle an SDP offer and return an SDP answer.

WebRTCStream.set_loop

python
def set_loop(self, loop)

Source

WebRTCStream.cleanup

python
async def cleanup(self)

Source

Close all peer connections for this stream.

WebRTCStreamManager

python
class WebRTCStreamManager

Source

Manages multiple WebRTC streams and dispatches offer requests.

WebRTCStreamManager.init

python
def __init__(self)

Source

WebRTCStreamManager.create_stream

python
def create_stream(self, stream_id, vuer, **kwargs)

Source

Create and register a new WebRTC stream.

WebRTCStreamManager.offer_handler

python
async def offer_handler(self, request)

Source

Route handler for /webrtc/offer/{stream_id}.

WebRTCStreamManager.set_loop

python
def set_loop(self, loop)

Source

Propagate event loop reference to all streams.

WebRTCStreamManager.streams

python
def streams(self)

Source

WebRTCStreamManager.cleanup_all

python
async def cleanup_all(self)

Source

Cleanup all streams.