Skip to content

beacon

BeaconNamespace #

Bases: AsyncNamespace

Handle all SocketIO events related to beacon server.

Source code in cogip/tools/server/namespaces/beacon.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class BeaconNamespace(socketio.AsyncNamespace):
    """
    Handle all SocketIO events related to beacon server.
    """

    def __init__(self, cogip_server: "server.Server"):
        super().__init__("/beacon")
        self.cogip_server = cogip_server
        self.context = Context()
        self.recorder = GameRecorder()

    async def on_connect(self, sid, environ):
        if self.context.beacon_sid:
            message = "A beacon server is already connected"
            logger.error(f"Beacon verser connection refused: {message}")
            raise ConnectionRefusedError(message)
        self.context.beacon_sid = sid

    async def on_connected(self, sid):
        logger.info("Beacon connected.")

    def on_disconnect(self, sid):
        self.context.beacon_sid = None
        logger.info("Beacon disconnected.")

    async def on_reset(self, sid):
        """
        Callback on reset message.
        """
        await self.emit("reset", namespace="/planner")

    async def on_command(self, sid, cmd):
        """
        Callback on command.
        """
        await self.emit("command", cmd, namespace="/planner")

    async def on_wizard(self, sid, message):
        """
        Callback on wizard message.
        """
        await self.emit("wizard", message, namespace="/planner")

on_command(sid, cmd) async #

Callback on command.

Source code in cogip/tools/server/namespaces/beacon.py
39
40
41
42
43
async def on_command(self, sid, cmd):
    """
    Callback on command.
    """
    await self.emit("command", cmd, namespace="/planner")

on_reset(sid) async #

Callback on reset message.

Source code in cogip/tools/server/namespaces/beacon.py
33
34
35
36
37
async def on_reset(self, sid):
    """
    Callback on reset message.
    """
    await self.emit("reset", namespace="/planner")

on_wizard(sid, message) async #

Callback on wizard message.

Source code in cogip/tools/server/namespaces/beacon.py
45
46
47
48
49
async def on_wizard(self, sid, message):
    """
    Callback on wizard message.
    """
    await self.emit("wizard", message, namespace="/planner")