Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@samcorky
Copy link
Contributor

Summary

This pull request introduces WebSocket support and integrates real-time space state notifications and updates. Key changes include:

  • Added /ws/space/state WebSocket endpoint for broadcasting space state changes.
  • Implemented inform_websocket_clients_of_space_state_change helper for real-time updates.
  • Introduced WebsocketEventInterface and WebsocketEventHandler for WebSocket event management.

…xt and remove duplicate function definition

- Updated logger naming to include interface class name for better traceability.
- Relocated `get_reserved_parameter_names` function
- Introduced `WebsocketEventInterface` and `WebsocketEventHandler` for managing WebSocket events.
- Added `websockets` dependency in `pyproject.toml` and `uv.lock` for WebSocket functionality.
- Created `WebsocketPluginIntegration` for plugin lifecycle management of WebSocket routers.
- Updated Bolt request handling to include WebSocket event type.
- Enhanced plugin lifecycle to initialize and finalize WebSocket routes seamlessly.
- Introduced `/ws/space/state` WebSocket endpoint to broadcast space state changes to clients.
- Enabled real-time space state updates via new `inform_websocket_clients_of_space_state_change` helper.
- Updated space state open/close logic to notify connected WebSocket clients.
- Deleted `space state ws.py` as it is no longer used or required in the project.
@samcorky
Copy link
Contributor Author

This small script allows a connection to the /ws/space/state websocket.
On connection, you will receive the current state, and then when the state changes, you will receive the new state.

import asyncio
import json
from asyncio import CancelledError

import websockets

HOST = "smib-pi:80"

async def listen():
    uri = f"ws://{HOST}/ws/space/state"
    async with websockets.connect(uri) as websocket:
        print("Connected to WebSocket")
        while True:
            try:
                message = await websocket.recv()
                data = json.loads(message)
                print("Received:", data)
            except websockets.ConnectionClosed:
                print("Connection closed")
                break

try:
    asyncio.run(listen())
except (CancelledError, KeyboardInterrupt):
    print("WebSocket listener stopped")

samcorky and others added 3 commits October 18, 2025 09:30
…pport

- Added WebSocket details, including real-time updates and endpoint usage.
- Clarified Traefik reverse proxy routes with examples for all SMIB services.
@sjefferson99 sjefferson99 requested a review from Copilot October 19, 2025 15:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds first-class WebSocket support and real-time space state notifications. Key updates integrate a WebSocket event interface/handler, expose a new /ws endpoint, and unify event typing across HTTP/Scheduled/WebSocket flows.

  • Introduces WebsocketEventInterface and WebsocketEventHandler to register and dispatch WebSocket events via Bolt.
  • Adds /ws/space/state to push real-time space state to connected clients and a helper to broadcast updates.
  • Aligns event types via BoltEventType and standardizes router finalization naming.

Reviewed Changes

Copilot reviewed 17 out of 20 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/smib/plugins/integrations/websocket_plugin_integration.py New plugin integration to register and remove WebSocket routes and include routers into FastAPI.
src/smib/plugins/integrations/http_plugin_integration.py Logger improvement and method rename to finalise_router_setup for consistency.
src/smib/events/interfaces/websocket_event_interface.py Adds decorator and routing for WebSocket endpoints with Bolt dispatch wiring.
src/smib/events/interfaces/scheduled_event_interface.py Switches scheduled events to use BoltEventType/BoltRequestMode constants.
src/smib/events/interfaces/http/init.py Refactors to shared parameter extraction, type fixes, and unified event typing.
src/smib/events/interfaces/init.py New shared helpers for reserved names and parameter extraction.
src/smib/events/handlers/websocket_event_handler.py New handler to transform WebSocket connections into Bolt requests.
src/smib/events/handlers/scheduled_event_handler.py Uses BoltEventType for scheduled event payloads.
src/smib/events/handlers/http_event_handler.py Minor typing/cleanup and unified event typing.
src/smib/events/handlers/init.py Adds WEBSOCKET mode and removes unused Clock import.
src/smib/events/init.py Centralizes BoltEventType definitions.
src/smib/main.py Wires WebSocket interface/handler/integration into the app and plugin lifecycle.
src/plugins/space/spacestate/listeners/websocket.py New WebSocket listener and broadcast helper for space state.
src/plugins/space/spacestate/common.py Notifies WebSocket clients when the space state changes.
pyproject.toml Adds websockets dependency.
README.md Documents WebSocket capability and routing layout.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

samcorky and others added 9 commits October 19, 2025 17:05
… inclusion logic

- Enhanced `extract_parameter_and_value` and `find_annotation_in_signature` for better type handling and annotations.
- Modified `APIRouter` initialization to exclude schema for individual routers.
- Adjusted router finalization to include schema in FastAPI app.
@samcorky
Copy link
Contributor Author

I will update the README once the websocket PR is merged. Format changes a bit and can't be bothered with the merge conflicts

Copy link
Member

@sjefferson99 sjefferson99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Container builds, examples script correctly provides state changes in real time as expected.

@samcorky samcorky merged commit 1675fd2 into master Oct 20, 2025
@samcorky samcorky deleted the 373-add-support-for-websocket-endpoints-in-the-httpevent-interfacehandlerservice branch October 20, 2025 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for websocket endpoints in the HTTPEvent Interface/Handler/Service

3 participants