Client Handles¶
- class viser.ClientHandle[source]¶
A handle is created for each client that connects to a server. Handles can be used to communicate with just one client, as well as for reading and writing of camera state.
Similar to
ViserServer, client handles also expose scene and GUI interfaces atClientHandle.sceneandClientHandle.gui. If these are used, for example via a client’sSceneApi.add_point_cloud()method, created elements are local to only one specific client.- camera: CameraHandle¶
Handle for reading from and manipulating the client’s viewport camera.
- flush() None[source]¶
Flush the outgoing message buffer. Any buffered messages will immediately be sent. (by default they are windowed)
- Return type:
None
- atomic() ContextManager[None][source]¶
Returns a context where: all outgoing messages are grouped and applied by clients atomically.
This should be treated as a soft constraint that’s helpful for things like animations, or when we want position and orientation updates to happen synchronously.
- Returns:
Context manager.
- Return type:
ContextManager[None]
- send_file_download(filename: str, content: bytes, chunk_size: int = 1048576, save_immediately: bool = False) None[source]¶
Send a file for a client or clients to download.
- Parameters:
filename (str) – Name of the file to send. Used to infer MIME type.
content (bytes) – Content of the file.
chunk_size (int) – Number of bytes to send at a time.
save_immediately (bool) – Whether to save the file immediately. If False, a link to the file will be shown as a notification. Being able to right click the link and choose “Save as…” can be useful.
- Return type:
None
- add_notification(title: str, body: str, *, loading: bool = False, with_close_button: bool = True, auto_close_seconds: float | None = None, color: Literal['dark', 'gray', 'red', 'pink', 'grape', 'violet', 'indigo', 'blue', 'cyan', 'green', 'lime', 'yellow', 'orange', 'teal'] | tuple[int, int, int] | None = None) NotificationHandle[source]¶
- add_notification(title: str, body: str, *, loading: bool = False, with_close_button: bool = True, auto_close: int | Literal[False] = False, color: Literal['dark', 'gray', 'red', 'pink', 'grape', 'violet', 'indigo', 'blue', 'cyan', 'green', 'lime', 'yellow', 'orange', 'teal'] | tuple[int, int, int] | None = None) NotificationHandle
Add a notification to the client’s interface.
This method creates a new notification that will be displayed at the top left corner of the client’s viewer. Notifications are useful for providing alerts or status updates to users.
Deprecated since version 1.0.0: The auto_close argument is deprecated. Use auto_close_seconds instead.
- Parameters:
title – Title to display on the notification.
body – Message to display on the notification body.
loading – Whether the notification shows loading icon.
with_close_button – Whether the notification can be manually closed.
auto_close_seconds – Time before the notification automatically closes; None if the notification does not close on its own.
- Returns:
A handle that can be used to interact with the GUI element.
- get_render(height: int, width: int, *, wxyz: tuple[float, float, float, float] | ndarray, position: tuple[float, float, float] | ndarray, fov: float, transport_format: Literal['png', 'jpeg'] = 'jpeg') ndarray[source]¶
- get_render(height: int, width: int, *, transport_format: Literal['png', 'jpeg'] = 'jpeg') ndarray
Request a render from a client, block until it’s done and received, then return it as a numpy array. If wxyz, position, and fov are not provided, the current camera state will be used.
- Parameters:
height – Height of rendered image. Should be <= the browser height.
width – Width of rendered image. Should be <= the browser width.
wxyz – Camera orientation as a quaternion. If not provided, the current camera position will be used.
position – Camera position. If not provided, the current camera position will be used.
fov – Vertical field of view of the camera, in radians. If not provided, the current camera position will be used.
transport_format – Image transport format. JPEG will return a lossy (H, W, 3) RGB array. PNG will return a lossless (H, W, 4) RGBA array, but can cause memory issues on the frontend if called too quickly for higher-resolution images.