Skip to content

websocket

Packet dataclass

Bases: Serializable

Packet class represents a message that is sent through the websocket.

Source code in backend/shared/websocket.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
@dataclass
class Packet(Serializable):
    """
    Packet class represents a message that is sent through the websocket.
    """
    type: str
    """The type of the packet."""
    data: Generic[T] = None
    """The data field is the actual data that is sent through the websocket."""

    def to_dict(self, dict_factory: Type[Dict] = dict, recurse: bool = True) -> Dict:
        return {
            'type': str(self.type),
            'data': self.data.to_dict() if isinstance(self.data, Serializable) else self.data,
        }

data: Generic[T] = None class-attribute instance-attribute

The data field is the actual data that is sent through the websocket.

type: str instance-attribute

The type of the packet.