mirror of
https://github.com/vegu-ai/talemate.git
synced 2026-09-02 20:20:40 +02:00
141 lines
4.8 KiB
Markdown
141 lines
4.8 KiB
Markdown
|
|
# Websocket Nodes
|
||
|
|
|
||
|
|
Plumbing for module-defined websocket handlers: route requests, queue responses and signal operation success or failure to the frontend.
|
||
|
|
|
||
|
|
<!-- glossary:generated - everything below this line is generated by `python -m talemate.game.engine.nodes.tools glossary --write` - do not edit -->
|
||
|
|
|
||
|
|
|
||
|
|
_4 nodes._
|
||
|
|
|
||
|
|
| Node | Registry path |
|
||
|
|
| --- | --- |
|
||
|
|
| [Get Websocket Router](#get-websocket-router) | `websocket/GetWebsocketRouter` |
|
||
|
|
| [Websocket Operation Done](#websocket-operation-done) | `websocket/signals/OperationDone` |
|
||
|
|
| [Websocket Operation Failed](#websocket-operation-failed) | `websocket/signals/OperationFailed` |
|
||
|
|
| [Websocket Response](#websocket-response) | `websocket/WebsocketResponse` |
|
||
|
|
|
||
|
|
## Get Websocket Router
|
||
|
|
|
||
|
|
`websocket/GetWebsocketRouter`
|
||
|
|
|
||
|
|
Get a websocket router (plugin) by its route name from the active
|
||
|
|
websocket handler.
|
||
|
|
|
||
|
|
Raises an error if no plugin is registered for the given route.
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `router` | `str` | The route name, passed through |
|
||
|
|
| `websocket_router` | `websocket_router` | The websocket router (plugin) instance |
|
||
|
|
| `websocket_handler` | `websocket_handler` | The active websocket handler |
|
||
|
|
|
||
|
|
**Properties**
|
||
|
|
|
||
|
|
| Property | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| `router` | `str` | `""` | The router to get the websocket plugin for. Choices are generated at runtime. |
|
||
|
|
|
||
|
|
## Websocket Operation Done
|
||
|
|
|
||
|
|
`websocket/signals/OperationDone`
|
||
|
|
|
||
|
|
Signal to the frontend that a websocket operation has completed successfully.
|
||
|
|
|
||
|
|
Sends an `operation_done` message through the websocket router, optionally
|
||
|
|
emits a status message and - unless `signal_only` is set - triggers an auto
|
||
|
|
save of the scene (or marks the scene as unsaved when auto save is off or
|
||
|
|
disallowed).
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `state` | `any` | The graph state |
|
||
|
|
| `websocket_router` | `websocket_router` | The websocket router (plugin) to signal through |
|
||
|
|
| `signal_only` | `bool` | If true, only send the signal and skip the save handling (optional) |
|
||
|
|
| `allow_auto_save` | `bool` | Whether to allow the scene to auto save after the operation (optional) |
|
||
|
|
| `emit_status_message` | `str` | Status message to display in the frontend (optional) |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `state` | `any` | The state input, passed through |
|
||
|
|
| `websocket_router` | `websocket_router` | The websocket router, passed through |
|
||
|
|
|
||
|
|
**Properties**
|
||
|
|
|
||
|
|
| Property | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| `signal_only` | `bool` | `False` | Whether to signal only or emit a status |
|
||
|
|
| `allow_auto_save` | `bool` | `True` | Whether to allow auto save |
|
||
|
|
| `emit_status_message` | `str` | `""` | The status message to emit |
|
||
|
|
|
||
|
|
## Websocket Operation Failed
|
||
|
|
|
||
|
|
`websocket/signals/OperationFailed`
|
||
|
|
|
||
|
|
Signal to the frontend that a websocket operation has failed.
|
||
|
|
|
||
|
|
Sends an `operation_done` message carrying the error through the websocket
|
||
|
|
router and optionally emits an error status message in the frontend.
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `state` | `any` | The graph state |
|
||
|
|
| `websocket_router` | `websocket_router` | The websocket router (plugin) to signal through |
|
||
|
|
| `message` | `str` | The error message (optional) |
|
||
|
|
| `emit_status` | `bool` | Whether to also emit an error status message (optional) |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `state` | `any` | The state input, passed through |
|
||
|
|
| `websocket_router` | `websocket_router` | The websocket router, passed through |
|
||
|
|
|
||
|
|
**Properties**
|
||
|
|
|
||
|
|
| Property | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| `message` | `str` | `""` | The message to emit |
|
||
|
|
| `emit_status` | `bool` | `True` | Whether to emit a status |
|
||
|
|
|
||
|
|
## Websocket Response
|
||
|
|
|
||
|
|
`websocket/WebsocketResponse`
|
||
|
|
|
||
|
|
Queue a message to be sent to the frontend through the websocket.
|
||
|
|
|
||
|
|
The message is sent with the router's name as its type, the given action
|
||
|
|
name, and the data dict merged into the message payload.
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `state` | `any` | The graph state |
|
||
|
|
| `websocket_router` | `websocket_router` | The websocket router (plugin) to send the message through |
|
||
|
|
| `action` | `str` | The action name of the message |
|
||
|
|
| `data` | `dict` | Dict of additional payload fields merged into the message |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `state` | `any` | The state input, passed through |
|
||
|
|
| `websocket_router` | `websocket_router` | The websocket router, passed through |
|
||
|
|
| `action` | `str` | The action input, passed through |
|
||
|
|
| `data` | `dict` | The data input, passed through |
|
||
|
|
|
||
|
|
**Properties**
|
||
|
|
|
||
|
|
| Property | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| `action` | `str` | `""` | The action to send to the websocket |
|
||
|
|
| `data` | `dict` | `{}` | The data to send to the websocket |
|