Selkies
Developer Reference

webrtc_engine

WebRTC transport engine for Selkies.

Owns the server side of every WebRTC session: peer-connection lifecycle (offer building, SDP/ICE plumbing, teardown), per-display media graphs (a MediaRelay fanning one encoded video/audio source out to every peer of that display), the ordered "input" data channel that carries input, clipboard, cursor, stats, and control messages, and the unordered "pointer" channel that carries coalesced pointer motion.

Structural notes:

  • Everything runs on one asyncio loop. Capture threads never touch the loop directly; encoded frames arrive via loop.call_soon_threadsafe into PipelineBridge queues that the media tracks drain.
  • Data-channel dispatch is serialized per channel through a bounded queue with a single consumer task so input events keep strict arrival order.
  • Behavior deliberately mirrors the websockets transport (broadcast semantics, viewer/collaborator input gates, MK_ACCESS/AUTH_SUCCESS verdicts); parity between the two transports is a project invariant. The input gates share their prefix allow-lists with the websockets gate (input_handler), and secure-mode checks read the live /api/tokens table (current_session_tokens) per message so re-provisioning is honored.
  • Data-channel compression is negotiated per channel by the _gz,1 handshake: a peer that sends it can gunzip, is echoed the capability, and may from then on receive gzip'd payloads; every display page and viewer handshakes independently.
attributeFULLCOLOR_CODECS
= {'h264enc': 'h264', 'h264enc-striped': 'h264', 'h265enc': 'h265', 'vp9enc': 'vp9'}
attributelogger
= logging.getLogger('webrtc')
attributehandler
= logging.StreamHandler()
attributeformatter
= ConditionalExtraFormatter(fmt='%(levelname)s:%(name)s:%(message)s', datefmt='%Y-%m-%d %H:%M:%S', extra_fields=['client_peer_id', 'client_type'])
attributeDATA_CHANNEL_BULK_CHUNK_SIZE
= 16 * 1024 // 3 * 3
attributeDATA_CHANNEL_BULK_HIGH_WATER
= 64 * 1024
attributeIDR_REQUEST_FLOOR_S
= 0.25
attributeGATE_TIMEOUT_S
= 1.0

On this page

No Headings
Edit on GitHub