aria2.js
JavaScript (Node.js and browsers) library for aria2, "The next generation download utility."
Intro
aria2.js supports the WebSocket and HTTP transports.
Browser
bower install aria2
<script src="bower_components/aria2/aria2.min.js"></script>
Node.js
npm install aria2
var aria2 = require('aria2');
Init
var aria2 = new Aria2([options]);
default and only valid options are
{
host: 'localhost',
port: 6800,
secure: false
}
Open
aria2.open() will open the WebSocket connexion.
aria2.onopen = function() {
console.log('I\'m open!');
};
aria2.open();
Close
aria2.close() will close the WebSocket connexion.
aria2.onclose = function() {
console.log('I\'m closed!');
};
aria2.close();
Send and message events
onsend() is called everytime a message is being sent, onmessage() is called everytime a message has been received.
aria2.onsend = function(m) {
console.log('OUT', m);
};
aria2.onmessage = function(m) {
console.log('IN', m);
};
Methods
For a complete listing see aria2 methods.
When sending a request to aria2, if the WebSocket isn't available or closed, aria2.js will use the HTTP transport.
For every method you can use
aria2.send('getVersion', [params,] function(err, res) {
console.log(err || res);
});
or directly
aria2.getVersion([params,] function(err, res) {
console.log(err || res);
});
Notifications
For a complete listing see aria2 notifications.
For every notifications you can attach a function to call.
aria2.onDownloadStart = function(event) {
console.log(event);
};
Example
See example.js