Comparing version 1.2.1 to 1.3.0
42
Aria2.js
@@ -9,3 +9,7 @@ ;(function (global) { | ||
if (typeof module !== 'undefined' && module.exports) { | ||
function isNode () { | ||
return typeof module !== 'undefined' && module.exports | ||
} | ||
if (isNode()) { | ||
WebSocket = require('ws') | ||
@@ -32,3 +36,2 @@ b64 = function (str) { | ||
Aria2.prototype.http = function (m, fn) { | ||
// FIXME json-rpc post wouldn't work | ||
var opts = { | ||
@@ -38,16 +41,24 @@ 'host': this.host, | ||
'path': this.path, | ||
'secure': this.secure, | ||
'query': { | ||
'method': m.method, | ||
'id': m.id | ||
} | ||
'secure': this.secure | ||
} | ||
if (Array.isArray(m.params) && m.params.length > 0) { | ||
opts.query.params = b64(JSON.stringify(m.params)) | ||
var content = { | ||
method: m.method, | ||
id: m.id | ||
} | ||
// browser, use jsonp | ||
if (!(typeof module !== 'undefined' && module.exports)) { | ||
// use POST (default) | ||
if (isNode() || !this.jsonp) { | ||
opts.body = content | ||
opts.method = 'POST' | ||
if (Array.isArray(m.params) && m.params.length > 0) { | ||
opts.body.params = m.params | ||
} | ||
// use JSONP | ||
} else { | ||
opts.query = content | ||
opts.jsonp = 'jsoncallback' | ||
if (Array.isArray(m.params) && m.params.length > 0) { | ||
opts.query.params = b64(JSON.stringify(m.params)) | ||
} | ||
} | ||
@@ -57,6 +68,6 @@ | ||
httpclient.request(opts, function (err, res) { | ||
httpclient.request(opts, function (err, res, body) { | ||
if (err) return fn(err) | ||
var msg = opts.jsonp ? res.body : JSON.parse(res.toString()) | ||
var msg = opts.jsonp ? body : JSON.parse(body.toString()) | ||
that._onmessage(msg) | ||
@@ -275,3 +286,4 @@ }) | ||
'secret': '', | ||
'path': '/jsonrpc' | ||
'path': '/jsonrpc', | ||
'jsonp': false | ||
} | ||
@@ -294,3 +306,3 @@ | ||
if (typeof module !== 'undefined' && module.exports) { | ||
if (isNode()) { | ||
module.exports = Aria2 | ||
@@ -297,0 +309,0 @@ } else { |
@@ -26,3 +26,3 @@ #!/usr/bin/env node | ||
.option('-u, --url [url]', 'websocket url to connect to', 'ws://localhost:6800/jsonrpc') | ||
.option('-s --secret [secret]', 'aria2 secret to use') | ||
.option('-s, --secret [secret]', 'aria2 secret to use') | ||
@@ -29,0 +29,0 @@ // call |
{ | ||
"name": "aria2", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "Library and cli for aria2, \"The next generation download utility.\"", | ||
@@ -35,3 +35,3 @@ "homepage": "https://github.com/sonnyp/aria2.js", | ||
"commander": "^2.9.0", | ||
"httpclient": "0.0.4", | ||
"httpclient": "0.1.0", | ||
"ws": "^1.0.1" | ||
@@ -38,0 +38,0 @@ }, |
@@ -55,2 +55,3 @@ aria2.js | ||
- [system.listMethods](https://aria2.github.io/manual/en/html/aria2c.html#system.listMethods) | ||
- [system.listNotifications](https://aria2.github.io/manual/en/html/aria2c.html#system.listNotifications) | ||
- [aria2 events](#aria2-events) | ||
@@ -82,2 +83,4 @@ - [onDownloadStart](https://aria2.github.io/manual/en/html/aria2c.html#aria2.onDownloadStart) | ||
```xml | ||
<!-- optional for HTTP/JSONP support --> | ||
<script src="node_modules/httpclient/bundle.js"></script> | ||
<script src="node_modules/aria2/Aria2.js"></script> | ||
@@ -111,8 +114,11 @@ ``` | ||
secret: '', | ||
path: '/jsonrpc' | ||
path: '/jsonrpc', | ||
jsonp: false | ||
} | ||
``` | ||
Secret is optional and refers to [--rpc-secret](https://aria2.github.io/manual/en/html/aria2c.html#cmdoption--rpc-secret). | ||
`secret` is optional and refers to [--rpc-secret](https://aria2.github.io/manual/en/html/aria2c.html#cmdoption--rpc-secret). | ||
`jsonp: true` will make aria2.js uses [JSONP](https://en.wikipedia.org/wiki/JSONP) for non WebSocket requests, useful if you cannot make aria2c allow your origin. It has no effect on Node.js. | ||
[↑](#aria2js) | ||
@@ -165,3 +171,3 @@ | ||
Note that if you have passed the secret option to aria2.js, it will be automatically added it to every request so there is no need to include it. | ||
If you have passed the secret option to aria2.js, it will be automatically added to every request so there is no need to include it. | ||
@@ -168,0 +174,0 @@ When sending a request to aria2, if the WebSocket is closed, aria2.js will use the HTTP transport. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35144
400
223
+ Addedes6-promise@3.3.1(transitive)
+ Addedhttpclient@0.1.0(transitive)
- Removedes6-promise@1.0.0(transitive)
- Removedhttpclient@0.0.4(transitive)
Updatedhttpclient@0.1.0