26 lines
789 B
Python
26 lines
789 B
Python
from __future__ import annotations
|
|
|
|
import structlog
|
|
|
|
from app.communication.socketio.server import sio
|
|
|
|
logger = structlog.get_logger("socketio.notification")
|
|
|
|
|
|
@sio.on("connect", namespace="/notification")
|
|
async def notification_connect(sid: str, environ: dict) -> None:
|
|
logger.info("notification_connected", sid=sid)
|
|
|
|
|
|
@sio.on("disconnect", namespace="/notification")
|
|
async def notification_disconnect(sid: str) -> None:
|
|
logger.info("notification_disconnected", sid=sid)
|
|
|
|
|
|
@sio.on("join_user_room", namespace="/notification")
|
|
async def join_user_room(sid: str, data: dict) -> None:
|
|
user_id = data.get("user_id")
|
|
if user_id:
|
|
await sio.enter_room(sid, f"user:{user_id}", namespace="/notification")
|
|
logger.info("joined_user_room", sid=sid, user_id=user_id)
|