You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- support for browsers, Node.js, React Native, deno and gjs environments
23
+
- support for [HTTP](https://aria2.github.io/manual/en/html/aria2c.html#rpc-interface) and [WebSocket](https://aria2.github.io/manual/en/html/aria2c.html#json-rpc-over-websocket) transports
24
+
- modern ECMAScript API
27
25
28
-
See [aria2 methods](https://aria2.github.io/manual/en/html/aria2c.html#methods) and [aria2 notifications](https://aria2.github.io/manual/en/html/aria2c.html#notifications).
26
+
See [aria2 methods](https://aria2.github.io/manual/en/html/aria2c.html#methods) and [aria2 notifications](https://aria2.github.io/manual/en/html/aria2c.html#notifications) to get an idea of what aria2 and aria2.js are capable of.
`aria2.batch()` is a helper for [batch](https://aria2.github.io/manual/en/html/aria2c.html#system.multicall). It behaves the same as [multicall](#multicall) except it returns an array of promises which gives more flexibility in handling errors.
`aria2.open()` opens the WebSocket connection. All subsequent requests will use the WebSocket transport instead of HTTP.
116
+
117
+
```javascript
118
+
aria2
119
+
.open()
120
+
.then(() =>console.log("open"))
121
+
.catch((err) =>console.log("error", err));
122
+
```
123
+
124
+
[↑](#aria2js)
125
+
126
+
### close
127
+
128
+
`aria2.close()` closes the WebSocket connection. All subsequent requests will use the HTTP transport instead of WebSocket.
129
+
130
+
```javascript
131
+
aria2
132
+
.close()
133
+
.then(() =>console.log("closed"))
134
+
.catch((err) =>console.log("error", err));
135
+
```
136
+
137
+
[↑](#aria2js)
138
+
139
139
### listNotifications
140
140
141
141
`aria2.listNotifications()` is a helper for [system.listNotifications](https://aria2.github.io/manual/en/html/aria2c.html#system.listNotifications). The difference with `aria2.call('listNotifications')` is that it removes the `"aria2."` prefix from the results.
`aria2.listMethods()` is a helper for [system.listMethods](https://aria2.github.io/manual/en/html/aria2c.html#system.listMethods). The difference with `aria2.call('listMethods')` is that it removes the `"aria2."` prefix for the results.
161
+
`aria2.listMethods()` is a helper for [system.listMethods](https://aria2.github.io/manual/en/html/aria2c.html#system.listMethods). The difference with `aria2.call('listMethods')` is that it removes the `"aria2."` prefix from the results.
Additionally every [aria2 notifications](https://aria2.github.io/manual/en/html/aria2c.html#notifications) received will be emitted as an event (with and without the `"aria2."` prefix). Only available when using WebSocket, see [open](#open).
207
-
208
-
```javascript
209
-
aria2.on("onDownloadStart", ([guid]) => {
210
-
console.log("aria2 onDownloadStart", guid);
211
-
});
178
+
// called when an error occurs
179
+
aria2.onerror= (error) => {
180
+
console.log("aria2", "ERROR");
181
+
console.log(error);
182
+
};
183
+
184
+
// called when a notification is received on the WebSocket
0 commit comments