Beispiel #1
0
    def broadcast_client_update(self, connection: Connection, attributes: Dict[str, Any]):
        if attributes == {}:
            return

        self.broadcast_to_all_clients(
            common.Command(common.MessageType.CLIENT_UPDATE, common.encode_json({connection.unique_id: attributes}))
        )
Beispiel #2
0
    def set_client_attributes(self, attributes: dict):
        diff = update_attributes_and_get_diff(self.current_custom_attributes, attributes)
        if diff == {}:
            return True

        return self.send_command(
            common.Command(common.MessageType.SET_CLIENT_CUSTOM_ATTRIBUTES, common.encode_json(diff), 0)
        )
Beispiel #3
0
 def get_list_clients_command(self) -> common.Command:
     with self._mutex:
         result_dict = {
             cid: c.client_attributes()
             for cid, c in self._connections.items()
         }
         return common.Command(common.MessageType.LIST_CLIENTS,
                               common.encode_json(result_dict))
Beispiel #4
0
 def get_list_rooms_command(self) -> common.Command:
     with self._mutex:
         result_dict = {
             room_name: value.attributes_dict()
             for room_name, value in self._rooms.items()
         }
         return common.Command(common.MessageType.LIST_ROOMS,
                               common.encode_json(result_dict))
Beispiel #5
0
    def broadcast_room_update(self, room: Room, attributes: Dict[str, Any]):
        if attributes == {}:
            return

        self.broadcast_to_all_clients(
            common.Command(
                common.MessageType.ROOM_UPDATE,
                common.encode_json({room.name: attributes}),
            ))
Beispiel #6
0
def save_room(room_attributes: dict, commands: List[Command], file_path: str):
    with open(file_path, "wb") as f:
        f.write(encode_json(room_attributes))
        for c in commands:
            f.write(c.to_byte_buffer())