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.5Seconds a media frame may wait for its recipient before it is dropped.
attributeMAX_MEDIA_BACKLOG_BYTES= 4 * 1024 * 1024Bytes 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= 512JSON messages allowed to queue for one recipient before it is closed.
attributeSEND_STALL_LIMIT= 10.0Seconds one send may take before the recipient is treated as gone and closed.
attributeCLOSE_WAIT= 2.0Seconds allowed for the close handshake on a recipient already known to be stuck.
attributeLAGGARD_CLOSE_CODE= 1013Close code for a recipient that stopped draining: 1013, try again later.
attributeVIDEO_FRAME= 1Frame-type byte of an encoded webcam video frame.
attributeAUDIO_FRAME= 2Frame-type byte of an encoded mic audio frame.
attributeVIDEO_CONFIG= 3Frame-type byte of a sender's video decoder config, which is never dropped.
attributeKEYFRAME_FLAG= 1Value of the byte after a video frame's type byte that marks it a keyframe.