webstation-broker
DeveloperPython reference

outbox

Per-connection outbound queue for room sockets.

Per-connection outbound queue for room sockets.

A broadcast only queues its message and returns; one drain task per connection does the sends, so a slow recipient delays nobody but itself.

Traffic goes out in three lanes, each in queue order: JSON (chat, presence, control) first, then audio, then video. JSON is never dropped. Media is live, so a recipient that falls behind skips frames instead of building up delay, and video absorbs the lag before audio does.

A frame is dropped only once it has waited MAX_MEDIA_AGE. Webcam deltas each depend on the frame before, so after one of a sender's video frames is dropped for a recipient, that sender's later deltas are skipped for it too until a keyframe, and on_video_gap asks the sender for one with every frame skipped meanwhile. A sender's video config is never dropped.

A recipient that stops draining (one send outlasting SEND_STALL_LIMIT, or more than MAX_JSON_BACKLOG JSON messages queued) is closed and abandoned is set, so its handler stops waiting on it; the client reconnects on the same seat.

attributelog
= logging.getLogger(__name__)
attributeMAX_MEDIA_AGE
= 0.5

Seconds a media frame may wait for its recipient before it is dropped.

attributeMAX_MEDIA_BACKLOG_BYTES
= 4 * 1024 * 1024

Bytes of media queued per recipient before the oldest frames are dropped.

A memory backstop for a recipient whose send is blocked outright, so nothing is dequeued to be aged out.

attributeMAX_JSON_BACKLOG
= 512

JSON messages allowed to queue for one recipient before it is closed.

attributeSEND_STALL_LIMIT
= 10.0

Seconds one send may take before the recipient is treated as gone and closed.

attributeCLOSE_WAIT
= 2.0

Seconds allowed for the close handshake on a recipient already known to be stuck.

attributeLAGGARD_CLOSE_CODE
= 1013

Close code for a recipient that stopped draining: 1013, try again later.

attributeVIDEO_FRAME
= 1

Frame-type byte of an encoded webcam video frame.

attributeAUDIO_FRAME
= 2

Frame-type byte of an encoded mic audio frame.

attributeVIDEO_CONFIG
= 3

Frame-type byte of a sender's video decoder config, which is never dropped.

attributeKEYFRAME_FLAG
= 1

Value of the byte after a video frame's type byte that marks it a keyframe.