{"id":22093119,"url":"https://github.com/jc3213/aria2.js","last_synced_at":"2026-04-09T05:31:50.001Z","repository":{"id":241264100,"uuid":"804729371","full_name":"jc3213/aria2.js","owner":"jc3213","description":"A JavaScript library for seamless JSON-RPC access with aria2 download utility","archived":false,"fork":false,"pushed_at":"2026-03-30T01:50:11.000Z","size":733,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-30T05:08:53.757Z","etag":null,"topics":["aria2","aria2-rpc","javascript","javascript-library","jsonrpc","promise-api","task-manager","webworker"],"latest_commit_sha":null,"homepage":"https://jc3213.github.io/aria2.js/","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-2.1","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jc3213.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-05-23T06:44:39.000Z","updated_at":"2026-03-30T01:50:14.000Z","dependencies_parsed_at":"2025-04-19T07:21:12.083Z","dependency_job_id":"ac4a050f-6f12-474f-87c5-246e64bbb49f","html_url":"https://github.com/jc3213/aria2.js","commit_stats":null,"previous_names":["jc3213/aria2.js"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jc3213/aria2.js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jc3213%2Faria2.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jc3213%2Faria2.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jc3213%2Faria2.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jc3213%2Faria2.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jc3213","download_url":"https://codeload.github.com/jc3213/aria2.js/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jc3213%2Faria2.js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31587779,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"online","status_checked_at":"2026-04-09T02:00:06.848Z","response_time":112,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aria2","aria2-rpc","javascript","javascript-library","jsonrpc","promise-api","task-manager","webworker"],"created_at":"2024-12-01T03:12:37.071Z","updated_at":"2026-04-09T05:31:49.983Z","avatar_url":"https://github.com/jc3213.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# aria2.js\n\n| Lastest | Extension | Web App |\n| - | - | - |\n| [aria2.js](https://jc3213.github.io/aria2.js/aria2.js) | [Download with Aria2](https://jc3213.github.io/download_with_aria2/) | [Task Manager](https://jc3213.github.io/aria2.js/app) |\n\n### HTML\n```HTML\n\u003cscript src=\"https://jc3213.github.io/aria2.js/aria2.js\"\u003e\u003c/script\u003e\n```\n\n### TamperMonkey\n```javascript\n// @require https://jc3213.github.io/aria2.js/aria2.js\n```\n\n## Syntax\n```javascript\nlet aria2 = new Aria2(\"http://localhost:6800/jsonrpc\", \"mysecret\");\n```\n\n```javascript\nlet aria2 = new Aria2(\"http://localhost:6800/jsonrpc#mysecret\");\n```\n\n```javascript\nlet aria2 = new Aria2();\naria2.url = 'wss://example.com:433/jsonrpc';\naria2.secret = 'mysecret';\n```\n\n## Properties\n- [url](#url)\n- [secret](#secret)\n- [retries](#retries)\n- [timeout](#timeout)\n\n### url\n- the URL of JSON-RPC\n```javascript\naria2.url = url;\n```\n- `${scheme}://${hostname}:${port}/jsonrpc`\n    - scheme\n        - `http`\n        - `https`\n        - `ws`\n        - `wss`\n    - hostname\n        - `www.example.com`\n    - port\n        - `6800` *default*\n        - `443`  *ssl*\n\n### secret\n- the secret token `secret=your-secret-token` in JSON-RPC configuration\n```javascript\naria2.secret = secret;\n```\n- `string`\n\n### retries\n- maximum retries when connection to JSON-RPC is closed\n```javascript\naria2.retries = retries;\n```\n- `integer`\n- `10`: Default\n- `-1` or other negative numbers for unlimited retries\n \n### timeout\n- time interval between retries\n```javascript\naria2.timeout = timeout;\n```\n- `integer`\n- `10`: Default, equivalent to **10000** millisecond\n- It is recommended to use numbers larger than `3`\n\n## Method\n- [connect](#connect)\n- [disconnect](#disconnect)\n- [call](#call)\n\n### connect\n- connect to `WebSocket` of aria2 JSON-RPC\n```javascript\naria2.connect();\n```\n\n### disconnect\n- disconnect from `WebSocket` of aria2 JSON-RPC\n```javascript\naria2.disconnect();\n```\n\n### call\n- send message to JSON-RPC\n```javascript\nlet response = aria2.call( { method, params } );\nlet response = aria2.call([ { method, params }, { method, params }, ..., { method, params } ]);\n```\n- use `WebSocket` or `POST` method based on [scheme](#scheme)\n- response\n    - `Promise` object, return an array that contains the response from JSON-RPC if fulfilled\n- method **required**\n    - Read [RPC method calls](https://aria2.github.io/manual/en/html/aria2c.html#methods)\n- params *optional*\n    - JSON-RPC method call parameters\n\n#### Call Sample\n```javascript\nlet { result } = await aria2.call( { method: 'aria2.tellActive' } );\nconsole.log(result) // All downloading sessions;\n\nlet { result } = await aria2.call([ { method: 'aria2.getGlobalOption' }, { method: 'aria2.getVersion' } ]);\nlet [ [globalOption], [version] ] = result;\nconsole.log(globalOption, version); // The options, version and enabled features of JSON-RPC;\n```\n\n## Events\n- [onopen](#onopen)\n- [onclose](#onclose)\n- [onmessage](#onmessage)\n\n### onopen\n- callback function triggered when JSON-RPC connection is opened.\n```javascript\naria2.onopen = function(event) { ... };\n```\n\n### onclose\n- callback function triggered when JSON-RPC connection is closed.\n```javascript\naria2.onclose = function(event) { ... };\n```\n\n### onmessage\n- callback function triggered when a message is received from JSON-RPC.\n```javascript\naria2.onmessage = function (response: object[]) { ... };\n```\n\n## Code Sample\n```javascript\nlet jsonrpc = {};\nlet session = {};\nlet keeplive;\n\nlet waiting = new Set([ 'waiting', 'paused' ]);\nlet dispatch = {\n    'aria2.onDownloadStart' (gid, result) {\n        console.log(\"The session #\" + gid + \" has started\");\n        session.active[gid] = result;\n        if (session.waiting[gid]) {\n            delete session.waiting[gid];\n        }\n    },\n    'aria2.onDownloadComplete' (gid, result) {\n        console.log(\"The session #\" + gid + \" has completed\");\n        dispatch.default(gid, result);\n    },\n    default (gid, result) {\n        if (session.active[gid]) {\n            delete session.active[gid];\n            if (waiting.has(result.status)) {\n                session.waiting[gid] = result;\n            } else {\n                session.stopped[gid] = result;\n            }\n        }\n    }\n};\n\nlet aria2 = new Aria2(\"http://localhost:6800/jsonrpc#mysecret\");\naria2.retries = -1;\n\naria2.onopen = async () =\u003e {\n    session.all = {};\n    session.active = {};\n    session.waiting = {};\n    session.stopped = {};\n\n    let { result: [\n        [options], [version], [stats], [active], [waiting], [stopped]\n    ] } = await aria2.call([\n        { method: 'aria2.getGlobalOption' },\n        { method: 'aria2.getVersion' },\n        { method: 'aria2.getGlobalStat' },\n        { method: 'aria2.tellActive' },\n        { method: 'aria2.tellWaiting', params: [0, 999] },\n        { method: 'aria2.tellStopped', params: [0, 999] }\n    ]);\n\n    jsonrpc.options = options;\n    jsonrpc.version = version;\n    jsonrpc.stats = stats;\n\n    for (let a of active) {\n        session.active[a.gid] = session.all[a.gid] = a;\n    }\n    for (let w of waiting) {\n        session.waiting[w.gid] = session.all[w.gid] = w;\n    }\n    for (let s of stopped) {\n        session.stopped[s.gid] = session.all[s.gid] = s;\n    }\n\n    keeplive = setInterval(async () =\u003e {\n        let { result: [\n            [stats], [active]\n         ] } = await aria2.call([\n            { method: 'aria2.getGlobalStat' },\n            { method: 'aria2.tellActive'}\n        ]);\n        jsonrpc.stats = stats;\n        active.forEach((a) =\u003e session.active[a.gid] = session.all[a.gid] = a);\n    }, 10000);\n};\n\naria2.onclose = () =\u003e clearInterval(keeplive);\n\naria2.onmessage = async ({ method, params }) =\u003e {\n    if (method === 'aria2.onBtDownloadComplete') {\n        return;\n    }\n\n    let [{ gid }] = params;\n    let { result } = await aria2.call({ method: 'aria2.tellStatus', params: [gid] });\n\n    (dispatch[method] ?? dispatch.default)(gid, result);\n};\n\naria2.connect();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjc3213%2Faria2.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjc3213%2Faria2.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjc3213%2Faria2.js/lists"}