labthings_fastapi.websockets
Handle notification of events, property, and action status changes
There are several kinds of “event” in the WoT vocabulary, not all of which
are called Event, which is why this module is called notifications.
In all cases, these are events that happen on an exposed Thing, and
may need to be relayed to one or more listeners (currently via a
WebSocket connection, though long polling may also be an option in the
future).
The aim at this stage (July 2023) is for a minimal working example that enables property changes to be fed via a websocket. Events proper should not be a big step thereafter.
The W3C standard does not define a way for one websocket to handle multiple Things, so for now the websocket endpoint will be associated with a single Thing instance. This may change in the future.
(c) Richard Bowman July 2023, released under GNU-LGPL-3.0
Module Contents
Functions
Relay objects from a stream to a websocket as JSON |
|
Process messages received from a websocket |
|
Handle communication to a client via websocket |
API
- async labthings_fastapi.websockets.relay_notifications_to_websocket(websocket: fastapi.WebSocket, receive_stream: anyio.abc.ObjectReceiveStream) None
Relay objects from a stream to a websocket as JSON
Interaction affordances (events, actions) that we’ve registered with will post messages to the queue: this function takes those messages from the queue and passes them to the websocket.
- async labthings_fastapi.websockets.process_messages_from_websocket(websocket: fastapi.WebSocket, send_stream: anyio.abc.ObjectSendStream, thing: labthings_fastapi.thing.Thing) None
Process messages received from a websocket
Currently, this will allow us to observe properties, by registering (or de-registering) for those properties.
- async labthings_fastapi.websockets.websocket_endpoint(thing: labthings_fastapi.thing.Thing, websocket: fastapi.WebSocket) None
Handle communication to a client via websocket