outbox.Outbox
Queue a room connection's outbound messages and send them from one task.
Queue a room connection's outbound messages and send them from one task.
The drain task starts on the first queued message, so an outbox can be built before the event loop that serves the connection is known.
Attributes
attribute_websocket= websocketattributelabel= labelThe member's display name, for log lines only.
attribute_on_video_gap= on_video_gapattribute_jsoncollections.deque[dict[str, Any]]= collections.deque()attribute_audiocollections.deque[_Queued]= collections.deque()attribute_videocollections.deque[_Queued]= collections.deque()attribute_media_bytes= 0attribute_gapsset[bytes]= set()attribute_wake= asyncio.Event()attribute_idle= asyncio.Event()attribute_taskOptional[asyncio.Task[None]]= Noneattribute_closerOptional[asyncio.Task[None]]= Noneattribute_closed= Falseattributeabandoned= asyncio.Event()Set once the recipient is given up on as stuck.
attributedropped_video= 0Video frames discarded for this recipient.
attributedropped_audio= 0Audio frames discarded for this recipient.
Functions
func__init__(self, websocket, label, on_video_gap=None) -> NoneWrap a room connection's socket.
paramselfparamwebsocketWebSocketThe accepted room socket the messages go out on.
paramlabelstrThe member's display name, for log lines only.
paramon_video_gapOptional[Callable[[bytes], None]]= NoneCalled with a sender's media id each time this recipient drops one of its video frames, until a keyframe gets through.
Returns
Nonefuncsend_json(self, payload) -> NoneQueue a JSON message; it is never dropped while the connection lives.
paramselfparampayloaddict[str, Any]The JSON-serializable message, normally carrying a type key.
Returns
Nonefuncsend_media(self, frame) -> NoneQueue a media frame in its lane; it goes out unless it grows stale first.
paramselfparamframebytesThe stamped frame in the room's binary wire format.
Returns
Nonefuncflush(self, timeout) -> boolWait for everything queued so far to be sent or dropped.
paramselfparamtimeoutfloatSeconds to wait at most.
Returns
boolTrue if the queue emptied in time, False if it did not or the
funcaclose(self) -> NoneStop the drain task and discard anything still queued.
Called once the connection is over. It does not close the socket itself, and abandons a laggard close still under way, since the handler returning drops the connection anyway. Logs how many frames this recipient lost, if any.
paramselfReturns
Nonefunc_clear(self) -> NoneDrop everything queued and mark the outbox idle.
paramselfReturns
Nonefunc_kick(self) -> NoneMark the outbox busy and make sure its drain task is running.
paramselfReturns
Nonefunc_shut(self) -> NoneGive up on a stuck recipient: drop its queue, stop its drain, and close it in the background.
paramselfReturns
Nonefunc_close_socket(self) -> NoneClose the socket with LAGGARD_CLOSE_CODE, giving up after CLOSE_WAIT.
paramselfReturns
Nonefunc_drop_video(self, frame) -> NoneCount a dropped video frame and wait for its sender's next keyframe.
Asks for that keyframe on every drop, not just the first: the request is rate-limited upstream, and a keyframe that arrives stale is lost too.
paramselfparamframebytesThe video frame being dropped.
Returns
Nonefunc_evict_oldest(self) -> boolDrop the oldest droppable frame to get back under the byte backstop.
Video goes first, since audio is the smaller and the more useful to keep; a video config message is never evicted.
paramselfReturns
boolTrue if a frame was dropped, False if nothing droppable was queued.
func_next_media(self) -> Optional[bytes]Take the next media frame worth sending, dropping stale and undecodable ones.
paramselfReturns
typing.OptionalThe frame to send, or None once both media lanes are empty.
func_drain(self) -> NoneSend queued messages, JSON then audio then video, until the outbox is closed.
paramselfReturns
None