Get WebSocket interface if running in WebSocket context. Returns the DashWebsocketCallback instance if the callback is being executed via WebSocket, otherwise returns None. Raises: RuntimeError: If websocket_callbacks is requested but the backend
(self)
| 331 | @property |
| 332 | @has_context |
| 333 | def websocket(self) -> typing.Optional[DashWebsocketCallback]: |
| 334 | """Get WebSocket interface if running in WebSocket context. |
| 335 | |
| 336 | Returns the DashWebsocketCallback instance if the callback is being |
| 337 | executed via WebSocket, otherwise returns None. |
| 338 | |
| 339 | Raises: |
| 340 | RuntimeError: If websocket_callbacks is requested but the backend |
| 341 | doesn't support WebSocket. |
| 342 | """ |
| 343 | ws = _get_from_context("dash_websocket", None) |
| 344 | if ws is None: |
| 345 | app = get_app() |
| 346 | if ( |
| 347 | hasattr(app, "_websocket_callbacks") |
| 348 | and app._websocket_callbacks # pylint: disable=protected-access |
| 349 | and not app.backend.websocket_capability |
| 350 | ): |
| 351 | raise RuntimeError( |
| 352 | f"WebSocket callbacks requested but backend " |
| 353 | f"'{app.backend.server_type}' doesn't support them." |
| 354 | ) |
| 355 | return ws |
| 356 | |
| 357 | |
| 358 | callback_context = CallbackContext() |
nothing calls this directly
no test coverage detected