Skip to content

Commit 9b9c193

Browse files
[docs] Document Django Channels WebSocket API endpoints
- add docs/user/websocket-api.rst (endpoint URL, auth, message types, JS example, deployment setup) - register new page in docs/index.rst toctree - add WebSocket cross-references to generating_users.rst and importing_users.rst - add missing label + note to OPENWISP_RADIUS_BATCH_ASYNC_THRESHOLD in settings.rst Closes #682
1 parent 99e0176 commit 9b9c193

File tree

4 files changed

+30
-31
lines changed

4 files changed

+30
-31
lines changed

docs/user/generating_users.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ See API documentation: :ref:`Batch user creation
8686
<radius_batch_user_creation>`.
8787

8888
Real-time batch status via WebSocket
89-
-------------------------------------
89+
------------------------------------
9090

9191
When the number of users to generate meets or exceeds
9292
:ref:`OPENWISP_RADIUS_BATCH_ASYNC_THRESHOLD

docs/user/importing_users.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ See :ref:`API documentation: Batch user creation
118118
<radius_batch_user_creation>`.
119119

120120
Real-time batch status via WebSocket
121-
-------------------------------------
121+
------------------------------------
122122

123123
When the number of users to import meets or exceeds
124124
:ref:`OPENWISP_RADIUS_BATCH_ASYNC_THRESHOLD

docs/user/settings.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,8 @@ For batches smaller than the threshold, users will be created immediately
128128
.. note::
129129

130130
When batch processing runs asynchronously, the final batch status
131-
(``"completed"`` or ``"failed"``) is delivered to connected clients
132-
in real time via the :ref:`WebSocket API
133-
<radius_websocket_api>`.
131+
(``"completed"`` or ``"failed"``) is delivered to connected clients in
132+
real time via the :ref:`WebSocket API <radius_websocket_api>`.
134133

135134
``OPENWISP_RADIUS_BATCH_DEFAULT_PASSWORD_LENGTH``
136135
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

docs/user/websocket-api.rst

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Overview
1313
The WebSocket API provides real-time status updates for batch user
1414
creation operations.
1515

16-
When a batch is processed asynchronously (i.e., the number of users
17-
to generate or import meets or exceeds
16+
When a batch is processed asynchronously (i.e., the number of users to
17+
generate or import meets or exceeds
1818
:ref:`OPENWISP_RADIUS_BATCH_ASYNC_THRESHOLD
1919
<openwisp_radius_batch_async_threshold>`), the Django admin interface
2020
automatically connects to the relevant endpoint to receive live status
@@ -28,7 +28,7 @@ All endpoints:
2828
after the connection is established.
2929

3030
Authentication and Authorization
31-
---------------------------------
31+
--------------------------------
3232

3333
All WebSocket endpoints require an authenticated user.
3434

@@ -57,10 +57,10 @@ If any check fails, the server closes the connection without sending any
5757
message.
5858

5959
Connection Endpoints
60-
---------------------
60+
--------------------
6161

6262
1. Batch User Creation Status
63-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
63+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6464

6565
This endpoint delivers real-time status updates for a single batch user
6666
creation operation.
@@ -88,9 +88,9 @@ A single batch user creation operation identified by its UUID.
8888
Server-Pushed Messages
8989
++++++++++++++++++++++
9090

91-
After the connection is established, the client does not need to send
92-
any messages. The server pushes exactly **one** message when batch
93-
processing finishes (either successfully or with an error).
91+
After the connection is established, the client does not need to send any
92+
messages. The server pushes exactly **one** message when batch processing
93+
finishes (either successfully or with an error).
9494

9595
Message type: ``batch_status_update``
9696

@@ -105,19 +105,19 @@ The ``status`` field contains one of the following values:
105105
.. list-table::
106106
:header-rows: 1
107107

108-
* - Value
108+
- - Value
109109
- Description
110-
* - ``"pending"``
110+
- - ``"pending"``
111111
- The batch has been created but processing has not yet started.
112112
This value is not sent via WebSocket; it is visible only through
113113
the REST API or admin interface.
114-
* - ``"processing"``
115-
- The batch is currently being processed. This value is not sent
116-
via WebSocket; it is the status visible when the admin page is
117-
opened and the WebSocket connection is established.
118-
* - ``"completed"``
114+
- - ``"processing"``
115+
- The batch is currently being processed. This value is not sent via
116+
WebSocket; it is the status visible when the admin page is opened
117+
and the WebSocket connection is established.
118+
- - ``"completed"``
119119
- Batch processing finished successfully. This is a terminal status.
120-
* - ``"failed"``
120+
- - ``"failed"``
121121
- Batch processing encountered an error. This is a terminal status.
122122

123123
.. note::
@@ -130,16 +130,16 @@ Connection Lifecycle
130130
++++++++++++++++++++
131131

132132
1. The client connects to the endpoint with the batch UUID in the URL.
133-
2. If the user is authorized, the connection is accepted and the client
134-
is added to the channel group ``radius_batch_<batch-id>``.
133+
2. If the user is authorized, the connection is accepted and the client is
134+
added to the channel group ``radius_batch_<batch-id>``.
135135
3. When batch processing finishes, the server sends one
136136
``batch_status_update`` message containing the terminal status.
137137
4. The client should close the connection upon receiving ``"completed"``
138138
or ``"failed"``.
139139
5. On disconnect, the client is removed from the channel group.
140140

141141
Example Client (JavaScript)
142-
++++++++++++++++++++++++++++
142+
+++++++++++++++++++++++++++
143143

144144
Example based on the admin interface implementation:
145145

@@ -164,20 +164,20 @@ Example based on the admin interface implementation:
164164
Replace ``<batch-id>`` with the UUID of the batch object.
165165

166166
Deployment Requirements
167-
------------------------
167+
-----------------------
168168

169169
WebSocket support requires server-side configuration beyond the default
170170
Django setup. The following components must be in place.
171171

172172
ASGI Server
173173
~~~~~~~~~~~
174174

175-
Django's default WSGI server does not support WebSockets. You must use
176-
an ASGI-compatible server such as `Daphne
175+
Django's default WSGI server does not support WebSockets. You must use an
176+
ASGI-compatible server such as `Daphne
177177
<https://github.com/django/daphne>`_.
178178

179-
Install Daphne and add it as the **first entry** in ``INSTALLED_APPS``
180-
so that Django uses it as the ASGI server:
179+
Install Daphne and add it as the **first entry** in ``INSTALLED_APPS`` so
180+
that Django uses it as the ASGI server:
181181

182182
.. code-block:: python
183183
@@ -218,8 +218,8 @@ Install ``channels_redis`` and configure it:
218218
WebSocket Routing
219219
~~~~~~~~~~~~~~~~~
220220

221-
Import ``openwisp_radius.routing.websocket_urlpatterns`` and include it
222-
in your project's ``URLRouter``. Example ASGI routing module:
221+
Import ``openwisp_radius.routing.websocket_urlpatterns`` and include it in
222+
your project's ``URLRouter``. Example ASGI routing module:
223223

224224
.. code-block:: python
225225

0 commit comments

Comments
 (0)