A Flutter package that provides API functionality and real-time streaming for interacting with aria2c using JSON-RPC.
- 📡 JSON-RPC Communication – Easily send commands to
aria2c
. - 🔄 Stream Support – Listen to real-time updates from
aria2c
. - ⚡ Comprehensive API – Full control over downloads, settings, and notifications.
- 🔧 Easy Integration – Works seamlessly with Flutter Streams.
Add aria2cf
to your pubspec.yaml
:
dependencies:
aria2cf:
git:
url: https://github.com/DrkXo/aria2cf
ref: master
Then, run:
flutter pub get
import 'package:aria2cf/aria2cf.dart';
Create an instance of the Aria2cSocket
and establish a connection to the aria2c
RPC server:
void main() async {
Aria2cSocket aria2cSocket = Aria2cSocket(
secret: 'your-secret',
);
// Default url 'ws://127.0.0.1:6800/jsonrpc'
final isconnected = await aria2cSocket.connect(
maxAttempts: 3, // Number of reconnection attempts
retryInterval: Duration(seconds: 5), // Interval between reconnection attempts
);
// Additional code will go here
}
Once connected, you can add a new download by specifying the URI of the file:
final downloadUri = 'https://example.com/file.zip'; // Replace with your file URL
aria2cSocket.addUri(urls: [downloadUri]);
You can listen to the data stream to monitor the progress of your downloads:
aria2cSocket.methodStreamStream.listen((event) {
// Process the event data
});
Manage your downloads using the provided methods:
final gid = 'your-download-gid'; // Replace with your download GID
// Pause the download
aria2cSocket.pause(gid:gid);
// Resume the download
aria2cSocket.resume(gid:gid);
// Remove the download
aria2cSocket.remove(gid:gid);
After completing your operations, ensure you disconnect from the RPC server:
aria2cSocket.
694B
disconnect();
print('Disconnected from aria2c RPC server.');
Note: Ensure that the aria2c
daemon is running with RPC mode enabled. You can start aria2c
with the following command:
aria2c --enable-rpc --rpc-listen-all=true --rpc-allow-origin-all
connect()
– Connects to thearia2c
RPC server.addUri(List<String> uris)
– Adds a new download task.pause(String gid)
– Pauses a download.resume(String gid)
– Resumes a paused download.remove(String gid)
– Removes a download.getGlobalStat()
– Retrieves global statistics.methodStreamStream
– A stream of download events.
-
aria2c
must be installed and running with RPC enabled:aria2c --enable-rpc --rpc-listen-all=true --rpc-allow-origin-all
This package is licensed under the MIT License. See LICENSE for details.
Contributions, issues, and feature requests are welcome! Feel free to check out the GitHub repository.