초기 커밋
This commit is contained in:
0
app/communication/socketio/namespaces/__init__.py
Normal file
0
app/communication/socketio/namespaces/__init__.py
Normal file
28
app/communication/socketio/namespaces/device_ns.py
Normal file
28
app/communication/socketio/namespaces/device_ns.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import structlog
|
||||
|
||||
from app.communication.socketio.server import sio
|
||||
|
||||
logger = structlog.get_logger("socketio.device")
|
||||
|
||||
|
||||
@sio.on("connect", namespace="/device")
|
||||
async def device_connect(sid: str, environ: dict) -> None:
|
||||
logger.info("device_ns_connected", sid=sid)
|
||||
|
||||
|
||||
@sio.on("disconnect", namespace="/device")
|
||||
async def device_disconnect(sid: str) -> None:
|
||||
logger.info("device_ns_disconnected", sid=sid)
|
||||
|
||||
|
||||
@sio.on("send_command", namespace="/device")
|
||||
async def send_command(sid: str, data: dict) -> None:
|
||||
device_uid = data.get("device_uid")
|
||||
command = data.get("command")
|
||||
if device_uid and command:
|
||||
from app.communication.mqtt.publisher import publish_command
|
||||
|
||||
await publish_command(device_uid, command)
|
||||
logger.info("command_sent", device_uid=device_uid)
|
||||
32
app/communication/socketio/namespaces/monitoring_ns.py
Normal file
32
app/communication/socketio/namespaces/monitoring_ns.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import structlog
|
||||
|
||||
from app.communication.socketio.server import sio
|
||||
|
||||
logger = structlog.get_logger("socketio.monitoring")
|
||||
|
||||
|
||||
@sio.on("connect", namespace="/monitoring")
|
||||
async def monitoring_connect(sid: str, environ: dict) -> None:
|
||||
logger.info("monitoring_connected", sid=sid)
|
||||
|
||||
|
||||
@sio.on("disconnect", namespace="/monitoring")
|
||||
async def monitoring_disconnect(sid: str) -> None:
|
||||
logger.info("monitoring_disconnected", sid=sid)
|
||||
|
||||
|
||||
@sio.on("subscribe_device", namespace="/monitoring")
|
||||
async def subscribe_device(sid: str, data: dict) -> None:
|
||||
device_uid = data.get("device_uid")
|
||||
if device_uid:
|
||||
await sio.enter_room(sid, f"device:{device_uid}", namespace="/monitoring")
|
||||
logger.info("subscribed_device", sid=sid, device_uid=device_uid)
|
||||
|
||||
|
||||
@sio.on("unsubscribe_device", namespace="/monitoring")
|
||||
async def unsubscribe_device(sid: str, data: dict) -> None:
|
||||
device_uid = data.get("device_uid")
|
||||
if device_uid:
|
||||
await sio.leave_room(sid, f"device:{device_uid}", namespace="/monitoring")
|
||||
25
app/communication/socketio/namespaces/notification_ns.py
Normal file
25
app/communication/socketio/namespaces/notification_ns.py
Normal file
@@ -0,0 +1,25 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user