Selkies
Developer Reference

rtc

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), and the ordered "input" data channel that carries input, clipboard, cursor, stats, and control messages.

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.
attributelogger
= logging.getLogger('rtc')
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_FALLBACK_CHUNK_SIZE
= (262144 - 512) * 3 // 4
attributeDATA_CHANNEL_BULK_HIGH_WATER
= 1024 * 1024

On this page

No Headings
Edit on GitHub