| Library | SharedWorker | Browser Extension | Web UI & Electron App |
|---|---|---|---|
| aria2.js | shared.js | Download with Aria2 | Aria2 Task Manager |
Download SharedWorker
Bash
curl -L -O https://jc3213.github.io/aria2.js/sharedworker/shared.js
curl -L -O https://jc3213.github.io/aria2.js/sharedworker/worker.js
Powershell
Invoke-WebRequest "https://jc3213.github.io/aria2.js/sharedworker/shared.js" -OutFile "shared.js"
Invoke-WebRequest "https://jc3213.github.io/aria2.js/sharedworker/worker.js" -OutFile "worker.js"
Syntax
HTML
<script src="shared.js"></script>
Javascript
const worker = new SharedWorker('shared.js');
const port = worker.port;
port.start();
port.onmessage = function(event) {
const message = event.data;
const id = message.id;
const type = message.type;
const response = message.response;
console.log(id, type, response);
};
port.postMessage({ id, type, payload });
id
String/Number- Unique ID for the message
type
String- connect
- disconnect
- Close
WebSocketconnection
- Close
- subscribe
- Add message port to the broadcast lists
- unsubscribe
- Remove message port from the broadcast lists
- websocket
- Handle notification events from
WebSocketJSON-RPC - Only send messages to ports in the broadcast lists
- Handle notification events from
- call
- multicall
- Send multiple messages to aria2 JSON-RPC
payload = [ { methodName, params }, ... ]- methodName
- params
HTML
<script src="shared.js"></script>
<script src="worker.js"></script>
Javascript
aria2.retries = 10; // Default
aria2.timeout = 10; // Default
aria2.onmessage = function(message) {
console.log(message);
};
await aria2.connect(jsonrpc, secret, callback);
let response = await aria2.call(method, params);
let response = await aria2.multicall([ { methodName, params }, ... ]);
jsonrpc
String- The URL of JSON-RPC of aria2 download ultility
secret
String- The secret token
secret=your-secret-tokenin JSON-RPC configuration
method
String- Read RPC method calls
params
Array- JSON-RPC method call parameters