Code Monkey home page Code Monkey logo

aria2.js's Introduction

aria2.js

JavaScript (Node.js and browsers) library and cli for aria2, "The next generation download utility."

Build Status js-standard-style

Dependency Status devDependency Status

Introduction

aria2.js controls aria2 via its JSON-RPC interface and features

  • Node.js and browsers support
  • multiple transports
  • callback API
  • promise API
  • light (1.5KB minified and gzipped)

Getting started

npm install aria2


var Aria2 = require('aria2');

or

<script src="node_modules/aria2/bundle.js"></script>
var Aria2 = window.Aria2

Start aria2c in daemon mode with

aria2c --enable-rpc --rpc-listen-all=true --rpc-allow-origin-all

Usage

var aria2 = new Aria2([options]);

default options match aria2c defaults and are

{
  host: 'localhost',
  port: 6800,
  secure: false,
  secret: '',
  path: '/jsonrpc'
}

secret is optional and refers to --rpc-secret.

If the WebSocket is open (via the open method) aria2.js will use the WebSocket transport, otherwise the HTTP transport.

For HTTP, aria2.js makes use of the new fetch standard, you might need a polyfill if you want to support older browsers.

open

aria2.open() opens the WebSocket connection.

aria2.onopen = function() {
  console.log('aria2 open');
};

aria2.open([cb]);
// or
aria2.open().then(fn)

close

aria2.close() closes the WebSocket connection.

aria2.onclose = function() {
  console.log('aria2 closed!');
};

aria2.close([cb]); // callback style
// or
aria2.close().then(fn); // promise style

onsend and onmessage

aria2.onsend() is called for every message sent. aria2.onmessage() is called for every message received.

aria2.onsend = function(m) {
  console.log('aria2 OUT', m);
};
aria2.onmessage = function(m) {
  console.log('aria2 IN', m);
};

aria2 methods

For a complete listing see aria2 methods.

If you passed the secret option to aria2.js, it will be automatically added to every request so there is no need to include it.

For every aria2 methods you can use

callback style

aria2.getVersion([params,] function(err, res) {
  console.log(err || res);
});

or

aria2.send('getVersion', [params,] function(err, res) {
  console.log(err || res);
});

promise style

aria2.getVersion([params,]).then(fn)

or

aria2.send('getVersion', [params,]).then(fn)

aria2 events

For a complete listing see aria2 notifications.

For every notifications you can bind a function.

aria2.onDownloadStart = function(gid) {
  console.log(gid);
};

Example

See example.

Tests

npm install
npm test

aria2.js's People

Contributors

gekowa avatar sonnyp avatar waldyrious avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.