websockets.server
Attributes
Classes
A websocket server connection. |
Functions
|
Deserialize JSON payload and check type. |
|
Sends an error. |
|
Sends an acknowledge. |
|
Handles listening clients. |
|
Handles authentication. |
|
Handles status requests. |
|
Handles broadcasts. |
|
Handles managing clients. |
|
Starts a chat. Handles listening to messages on channel. |
|
Registers staff member and listens to messages. |
|
|
|
Intercept initial HTTP request. |
|
Module Contents
- websockets.server.STAFF_CONNECTIONS: dict[str, set[websockets.asyncio.server.ServerConnection]][source]
- websockets.server.CHANNELS: dict[str, dict[str, set[websockets.asyncio.server.ServerConnection]]][source]
- class websockets.server.WebSocketServer(config: onegov.server.config.Config, session_manager: onegov.core.orm.SessionManager, host: str, *args: Any, **kwargs: Any)[source]
Bases:
websockets.asyncio.server.ServerConnection
A websocket server connection.
This protocol handles multiple websocket applications: - Ticket notifications - Ticker - Chat
Chat behaves differently from the others and will eventually be carved out into a separate service. To not interfere with any existing functionality, we try to refrain from making backwards-incompatible changes. That way, ticker and notifications should continue to work without any modification.
TODO: Move chat to a dedicated service.
- property identity_secret: str[source]
The identity secret, guaranteed to only be valid for the current application id.
- unsign(text: str, salt: str = 'generic-signer') str | None [source]
Unsigns a signed text, returning None if unsuccessful.
- websockets.server.get_payload(message: str | bytes, expected: collections.abc.Collection[str]) onegov.core.types.JSONObject | None [source]
Deserialize JSON payload and check type.
- async websockets.server.error(websocket: websockets.asyncio.server.ServerConnection, message: str, close: bool = True) None [source]
Sends an error.
- async websockets.server.acknowledge(websocket: websockets.asyncio.server.ServerConnection) None [source]
Sends an acknowledge.
- async websockets.server.handle_listen(websocket: websockets.asyncio.server.ServerConnection, payload: onegov.core.types.JSONObject_ro) None [source]
Handles listening clients.
- async websockets.server.handle_authentication(websocket: websockets.asyncio.server.ServerConnection, payload: onegov.core.types.JSONObject_ro) None [source]
Handles authentication.
- async websockets.server.handle_status(websocket: websockets.asyncio.server.ServerConnection, payload: onegov.core.types.JSONObject_ro) None [source]
Handles status requests.
- async websockets.server.handle_broadcast(websocket: websockets.asyncio.server.ServerConnection, payload: onegov.core.types.JSONObject_ro) None [source]
Handles broadcasts.
- async websockets.server.handle_manage(websocket: websockets.asyncio.server.ServerConnection, authentication_payload: onegov.core.types.JSONObject_ro) None [source]
Handles managing clients.
- async websockets.server.handle_customer_chat(websocket: WebSocketServer, payload: onegov.core.types.JSONObject_ro) None [source]
Starts a chat. Handles listening to messages on channel.
- async websockets.server.handle_staff_chat(websocket: WebSocketServer, payload: onegov.core.types.JSONObject_ro) None [source]
Registers staff member and listens to messages.
- async websockets.server.handle_start(websocket: websockets.asyncio.server.ServerConnection) None [source]
- websockets.server.process_request(self: websockets.asyncio.server.ServerConnection, request: websockets.Request) websockets.Response | None [source]
Intercept initial HTTP request.
Before establishing a WebSocket connection, a client sends a HTTP request to “upgrade” the connection to a WebSocket connection.
Chat
We authenticate the user before creating the WebSocket connection. The user is identified based on the session cookie. In addition to the cookie, we require a one-time token that the user must have obtained prior to requesting the WebSocket connection.