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})) )
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) )
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))
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))
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}), ))
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())