vuer.server
At
Proxy Object for using the @ notation. Also supports being called direction, which supports more complex arguments.
At.init
VuerSession
VuerSession.init
VuerSession.socket
Getter for the websocket object.
this is useful for closing the socket session from the client side.
Example Usage::
@app.spawn(start=True): async def main(session: VuerSession): print("doing something...") await sleep(1.0)
print("I am done! closing the socket.") session.socket.close()
VuerSession.grab_render
Grab a render from the client.
:param quality: The quality of the render. 0.0 - 1.0 :param subsample: The subsample of the render. :param ttl: The time to live for the handler. If the handler is not called within the time it gets removed from the handler list.
VuerSession.set
Used exclusively to set the scene.
the @SET operator is responsible for setting the root node of the scene.
Examples: proxy @ Set(Scene(children=[...]))
or
app.set @ Scene(children=[...])
VuerSession.update
Used to update existing elements. NOOP if an element does not exist.
Supports passing in a list of elements. (Thank God I implemented this... so handy! - Ge)
Example Usage::
app.update @ [element1, element2, ...]
VuerSession.add
Used to add elements to a specific parent.
Requires a parentKey, or treats the Scene root node as the default parent.
Example Usage::
app.add(element1, element2, ..., to=parentKey.)
or using the Scene root node as the default parent: ::
app.add @ element1
VuerSession.upsert
Upsert elements to a specific parent.
Requires a parentKey, or treats the Scene root node as the default parent.
Example Usage::
app.upsert(element1, element2, ..., to=parentKey.)
or using the Scene root node as the default parent: ::
app.upsert @ element1
VuerSession.remove
Remove elements by keys.
Example Usage::
app.remove @ ["key1", "key2", ...]
or a single key: ::
app.remove @ "key1"
VuerSession.popleft
VuerSession.pop
VuerSession.clear
clears all client messages
VuerSession.stream
VuerSession.spawn_task
Spawn a task in the running asyncio event loop
Useful for background tasks. Returns an asyncio task that can be canceled.
.. code-block:: python :linenos:
async background_task(): print('\rthis ran once')
async long_running_bg_task(): while True: await asyncio.sleep(1.0) print("\rlong running background task is still running")
@app.spawn_task async def main_fn(sess: VuerSession):
Prepare background tasks here:
task = sess.spawn_task(background_task) long_running_task = sess.spawn_task(long_running_bg_task)
Now to cancel a running task, simply
.. code-block:: python :linenos:
task.cancel()
Todos
▫️ Add a way to automatically clean up when exiting the main_fn.
Vuer
Vuer Server
This is the server for the Vuer client.
Usage::
app = Vuer()
@app.spawn async def main(session: VuerSession): session.set @ Scene(children=[...])
app.run()
.. automethod:: bind .. automethod:: spawn .. automethod:: relay .. automethod:: bound_fn .. automethod:: spawn_task .. automethod:: get_url .. automethod:: send .. automethod:: rpc .. automethod:: rpc_stream .. automethod:: close_ws .. automethod:: uplink .. automethod:: downlink .. automethod:: add_handler .. automethod:: _ttl_handler .. automethod:: run
Vuer.relay
This is the relay object for sending events to the server.
Todo: add API for specifying the websocket ID. Or just broadcast to all. Todo: add type hint
Interface: <uri>/relay?sid=<websocket_id>
:return:
- Status 200
- Status 400
Vuer.bound_fn
This is the default generator function in the socket connection handler
Vuer.spawn
bind the socket handler function fn to vuer, and start
the event loop if start is True.
Note: this is really a misnomer.
:param fn: The function to spawn. :param start: Start server after binding :return: None
Vuer.bind
Bind an asynchronous generator function for use in socket connection handler. The function should be a generator that yields Page objects.
:param fn: The function to bind. :return: None
Vuer.get_url
Get the URL for the Tassa. :return: The URL for the Tassa.
Vuer.send
Vuer.rpc
RPC only takes a single response. For multi-response streaming, we need to build a new one
Question is whether we want to make this RPC an awaitable funciton.
:param ttl: The time to live for the handler. If the handler is not called within the time it gets removed from the handler list.
Vuer.rpc_stream
This RPC offers multiple responses.
Vuer.close_ws
Vuer.uplink
Vuer.downlink
The websocket handler for receiving messages from the client.
:param ws: The websocket. :param request: The request (unused). :return: None
Vuer.add_handler
Adding event handlers to the vuer server.
:param event_type: The event type to handle.
:param fn: The function to handle the event.
:param once: Whether to remove the handler after the first call.
This is useful for RPC, which cleans up after itself.
The issue is for RPC, the key also needs to match. So we hack it here to use
a call specific event_type to enforce the cleanup.
Usage:
As a decorator::
app = Vuer() @app.add_handler("CAMERA_MOVE") def on_camera(event: ClientEvent, session: VuerSession): print("camera event", event.etype, event.value)
As a function::
app = Vuer() def on_camera(event: ClientEvent, session: VuerSession): print("camera event", event.etype, event.value)
app.add_handler("CAMERA_MOVE", on_camera) app.run()
Vuer.socket_index
This is the relay object for sending events to the server.
Todo: add API for specifying the websocket ID. Or just broadcast to all. Todo: add type hint
Interface: <uri>/relay?sid=<websocket_id>
:return:
- Status 200
- Status 400
Vuer.add_route
Vuer.run
Inherited members
WEBSOCKET_MAX_SIZE— fromvuer.base.ServerREQUEST_MAX_SIZE— fromvuer.base.Server
Public imports
These symbols are available from this module. Their definitions are documented in the linked modules.
Server—vuer.base.Serverhandle_file_request—vuer.base.handle_file_requestwebsocket_handler—vuer.base.websocket_handlerAdd—vuer.events.AddClientEvent—vuer.events.ClientEventFrame—vuer.events.FrameGrabRender—vuer.events.GrabRenderNullEvent—vuer.events.NullEventRemove—vuer.events.RemoveServerEvent—vuer.events.ServerEventServerRPC—vuer.events.ServerRPCSet—vuer.events.SetUpdate—vuer.events.UpdateUpsert—vuer.events.UpsertPage—vuer.schemas.html_components.Page