A Flutter package which provides an interface to the League of Legends Client API (LCU API) and LCU Socket connection.
Use Hexcore.create
to create a new instance of Hexcore
Hexcore hexcore = await Hexcore.create();
await hexcore.connectToClient();
At the moment that Hexcore connect to the client, it will watch the League Client state. If the player closes the client, the package will wait until the player reopen it.
Hexcore has three states:
initial
: When the instance of Hexcore is created.searchingClientPath
: When Hexcore is searching for the League Client path at the player's PC.waiting
: Hexcore already found the League Client Path, and now is waiting for the player to open the game or trying to connect to it.connected
: Hexcore is connected and ready to go.
Hexcore has a ValueNotifier
that notifies about the state of the connection, so you can use an AnimatedContainer to build according to it's state.
...
AnimatedBuilder(
animation: hexcore.status,
builder: (BuildContext context, Widget? child) {
if (hexcore.status.value == HexcoreStatus.waiting) {
return const Center(
child: CircularProgressIndicator(),
);
} else {
return const Center(
child: Text('Hexcore is ready!');
);
}
},
);
...
With hexcore you can send notification throw the League Client.
await hexcore.sendCustomNotification(
title: 'Hexcore notification',
details: 'Hello World',
iconUrl: 'https://some_url_here',
backgroundUrl: 'https://some_url_here',
);
This method create and insert the current player in a custom lobby.
await hexcore.createCustomMatch(
lobbyName: 'Custom game #1',
lobbyPassword: 'hexcore_123',
);
List all the available custom matches, so you can get the information you need to join a match.
List<Map<String,dynamic>> matches = await hexcore.listCustomMatches();
Use this method when you need to join a match. You can get the id of the match at listCustomMatches
method.
await hexcore.joinCustomMatch(
id: 'lobby_id',
password: 'lobby_password'
);
In this package you can also find an interface for the LCU Socket connection, where you can subscribe and listen to events emitted by LCU.
Create an instance and use HexcoreSocket.connect
to connect.
❗ You need to connect to the LCU using Hexcore.connectToClient
before trying the socket connection. ❗
HexcoreSocket hexcoreSocket = HexcoreSocket();
await hexcoreSocket.connect();
To subscribe to new events you need to call the method add
.
hexcoreSocket.add('[5, "OnJsonApiEvent"]');
In this example you subscribe to all LCU Events. Here you can understand more about LCU Events.
Use listen
method to create a StreamSubscription
to handle the events that has been subscribed.
hexcoreSocket.listen((event){
print(event);
});
You may need to override the badCertificateCallback
in way to send requests to the League Client, there is a example:
HttpOverrides.global = MyHttpOverrides();
class MyHttpOverrides extends HttpOverrides {
@override
HttpClient createHttpClient(SecurityContext? context) {
return super.createHttpClient(context)
..badCertificateCallback =
(X509Certificate cert, String host, int port) => true;
}
}