From 594ab2bf8bbb6fc5db91acc99adc0cdc3e75bb3e Mon Sep 17 00:00:00 2001 From: Vinta Chen Date: Sun, 8 Nov 2026 22:13:31 +0800 Subject: [PATCH] docs: add aiortc to WebSocket intro Co-Authored-By: Claude --- website/data/category_intros/websocket.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/website/data/category_intros/websocket.md b/website/data/category_intros/websocket.md index ed95128c..43c14df8 100644 --- a/website/data/category_intros/websocket.md +++ b/website/data/category_intros/websocket.md @@ -7,6 +7,7 @@ How to choose: - Plain WebSocket servers and clients: websockets - A few real-time features next to a Django project: websockets as a separate server - RPC and pub/sub over WAMP, or a Twisted app: Autobahn|Python +- Real-time audio, video, and data channels over WebRTC: aiortc Channels [extends Django beyond HTTP](https://channels.readthedocs.io/en/latest/) to handle WebSockets, and it [integrates with Django's auth and sessions](https://channels.readthedocs.io/en/latest/introduction.html). Write [sync consumers by default](https://channels.readthedocs.io/en/latest/topics/consumers.html#basic-layout). Switch to async ones only when async handling helps and every library you call is async-native. Serve everything with Daphne, or [keep HTTP on your WSGI server](https://channels.readthedocs.io/en/latest/deploying.html#http-and-websocket) and send only WebSockets to Daphne. @@ -16,6 +17,8 @@ websockets runs on asyncio by default, which is [ideal for servers with many con Autobahn|Python implements [both WebSocket and WAMP, on Twisted or asyncio](https://autobahn.readthedocs.io/en/latest/). WAMP adds [RPC and pub/sub over WebSocket](https://github.com/crossbario/autobahn-python), and every WAMP client [needs a WAMP router to talk to](https://autobahn.readthedocs.io/en/latest/wamp/programming.html#wamp-programming-1). Write components with functions and decorators, [the recommended approach](https://autobahn.readthedocs.io/en/latest/wamp/programming.html#creating-components-1). +aiortc implements [WebRTC and ORTC on asyncio](https://aiortc.readthedocs.io/en/latest/), with an API that closely follows the JavaScript one: promises become coroutines. Since it's plain Python, one server can [handle both signaling and data channels](https://aiortc.readthedocs.io/en/latest/#why-should-i-use-aiortc), or run computer vision on incoming video frames. + Always [secure WebSocket connections with TLS](https://websockets.readthedocs.io/en/stable/topics/security.html#encryption) in production. Any site can open a WebSocket to yours, with your users' cookies attached. If you serve private data, [restrict the allowed origins](https://channels.readthedocs.io/en/latest/topics/security.html#websockets): Channels has `AllowedHostsOriginValidator`, websockets has the [`origins` argument](https://websockets.readthedocs.io/en/stable/reference/asyncio/server.html#websockets.asyncio.server.serve), and Flask-SocketIO [allows only the same origin by default](https://flask-socketio.readthedocs.io/en/latest/deployment.html#cross-origin-controls). Broadcasting across processes needs a message broker such as Redis. Channels' [production channel layer](https://channels.readthedocs.io/en/latest/topics/channel_layers.html#redis-channel-layer) runs on it, Flask-SocketIO [takes it as a message queue](https://flask-socketio.readthedocs.io/en/latest/deployment.html#using-multiple-workers), with sticky sessions at the load balancer, and websockets' docs [suggest it for pub/sub](https://websockets.readthedocs.io/en/stable/faq/server.html#how-do-i-send-a-message-to-a-channel-a-topic-or-some-users).