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. |
|
|
|
Module Contents
- websockets.server.CONNECTIONS: dict[str, set[websockets.legacy.server.WebSocketServerProtocol]][source]
- websockets.server.STAFF_CONNECTIONS: dict[str, set[websockets.legacy.server.WebSocketServerProtocol]][source]
- websockets.server.CHANNELS: dict[str, dict[str, set[websockets.legacy.server.WebSocketServerProtocol]]][source]
- class websockets.server.WebSocketServer(config: onegov.server.config.Config, session_manager: onegov.core.orm.SessionManager, *args: Any, **kwargs: Any)[source]
Bases:
websockets.legacy.server.WebSocketServerProtocol
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.
- async process_request(path: str, headers: websockets.Headers) HTTPResponse | 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.
- property application_id_hash: str[source]
The application_id as hash, use this if the application_id can be read by the user -> this obfuscates things slightly.
- property session_cache: onegov.core.cache.RedisCacheRegion[source]
A cache that is kept for a long-ish time.
- property browser_session: BrowserSession | dict[str, Any][source]
- websockets.server.get_payload(message: str | bytes, expected: Collection[str]) JSONObject | None [source]
Deserialize JSON payload and check type.
- async websockets.server.error(websocket: websockets.legacy.server.WebSocketServerProtocol, message: str, close: bool = True) None [source]
Sends an error.
- async websockets.server.acknowledge(websocket: websockets.legacy.server.WebSocketServerProtocol) None [source]
Sends an acknowledge.
- async websockets.server.handle_listen(websocket: websockets.legacy.server.WebSocketServerProtocol, payload: onegov.core.types.JSONObject_ro) None [source]
Handles listening clients.
- async websockets.server.handle_authentication(websocket: websockets.legacy.server.WebSocketServerProtocol, payload: onegov.core.types.JSONObject_ro) None [source]
Handles authentication.
- async websockets.server.handle_status(websocket: websockets.legacy.server.WebSocketServerProtocol, payload: onegov.core.types.JSONObject_ro) None [source]
Handles status requests.
- async websockets.server.handle_broadcast(websocket: websockets.legacy.server.WebSocketServerProtocol, payload: onegov.core.types.JSONObject_ro) None [source]
Handles broadcasts.
- async websockets.server.handle_manage(websocket: websockets.legacy.server.WebSocketServerProtocol, 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.