123456789101112131415161718192021222324252627282930313233 |
- from flask_socketio import Namespace, join_room, leave_room, emit
- from utils import sio, rand_str, CAMERAS
- class CameraServer(Namespace):
- def __init__(self, namespace: "str"):
- super().__init__(namespace)
- self.cid = rand_str()
- while self.cid in CAMERAS.keys():
- self.cid = rand_str()
- def on_connect(self):
- emit("set id", self.cid)
- def on_disconnect(self):
- CAMERAS[self.cid]["online"] = False
- CAMERAS[self.cid]["data"] = None
- def on_real_id(self, cid: "str"):
- self.cid = cid
- if cid not in CAMERAS.keys():
- CAMERAS[cid] = {"name": "Untitled", "online": True, "data": None}
- else:
- CAMERAS[cid]["online"] = True
- join_room("all")
- join_room(cid)
- def on_req(self, msg: "str"):
- print(msg)
- emit("resp")
- sio.on_namespace(CameraServer("/camera"))
|