Event-driven WebSocket server
The server expects a JWT token in the URL path. The token should contain the user's ID and username, signed with swecc-server's secret key.
Add to events.py:
class EventType(str, Enum):
# Existing types...
NEW_FEATURE = "new_feature"Create handlers/new_feature_handler.py:
from ..events import Event, EventType
from ..event_emitter import EventEmitter
class NewFeatureHandler:
def __init__(self):
self.emitter = EventEmitter()
# Subscribe to relevant events
self.emitter.on(EventType.CONNECTION, self.handle_connect)
self.emitter.on(EventType.NEW_FEATURE, self.handle_new_feature)
async def handle_connect(self, event: Event) -> None:
# Handle new connections
pass
async def handle_new_feature(self, event: Event) -> None:
# Implement feature logic
passIn main.py:
from .handlers.new_feature_handler import NewFeatureHandler
# Add to existing registrations
service_registry.register("new_feature", NewFeatureHandler)await event_emitter.emit(Event(
type=EventType.NEW_FEATURE,
user_id=user_id,
username=username,
data={"key": "value"}
))Start the SWECC server:
cd /path/to/swecc-server
source your_venv_with_env_vars/bin/activate
docker-compose up --build -dRun the server:
cd /path/to/swecc-sockets
source your_venv_with_env_vars/bin/activate
docker-compose up --buildStart the server:
cd /path/to/swecc-sockets
source your_venv_with_env_vars/bin/activate
pip install -r requirements.txt
uvicorn app.main:app --host 0.0.0.0 --port 8004