Skip to the content.
Library Windows CLI SharedWorker Browser Extension Web UI & Electron App
aria2.js aria2c.cmd aria2-socket-worker.js Download with Aria2 Aria2 Task Manager

Download SharedWorker

Bash

curl -L -O https://jc3213.github.io/aria2.js/sharedworker/aria2-socket-worker.js
curl -L -O https://jc3213.github.io/aria2.js/sharedworker/aria2-worker-client.js

Powershell

Invoke-WebRequest "https://jc3213.github.io/aria2.js/sharedworker/aria2-socket-worker.js" -OutFile "aria2-socket-worker.js"
Invoke-WebRequest "https://jc3213.github.io/aria2.js/sharedworker/aria2-worker-client.js" -OutFile "aria2-worker-client.js"

Syntax

File System

/aria2-socket-worker.js
/index.html
/index.js

Javascript

const worker = new SharedWorker('/aria2-socket-worker.js');
const port = worker.port;

port.start();

port.onmessage = function(event) {
    const message = event.data;
    const id = message.id;
    const type = message.type;
    const result = message.result;
    console.log(id, type, result);
};

port.postMessage({ id, type, payload });

id

type

File System

/aria2-socket-worker.js
/aria2-worker-client.js
/index.html
/index.js

HTML

<script src="/aria2-worker-client.js"></script>

Javascript

aria2.retries = 10; // Default
aria2.timeout = 10; // Default

console.log(await aria2.retries, await aria2.timeout);

aria2.onopen = function() {
    console.log("WebSocket connection is opened");
};

aria2.onclose = function() {
    console.log("WebSocket connection is closed");
};

aria2.onmessage = function(message) {
    console.log("Notification recieved from JSON-RPC", message);
};

await aria2.subscribe();
await aria2.connect(jsonrpc, secret);
let response = await aria2.call(method, params);
let response = await aria2.multicall([ { methodName, params }, ... ]);

jsonrpc

secret

method

params