Comparing version 3.0.0 to 3.0.1
@@ -1,29 +0,29 @@ | ||
'use strict' | ||
"use strict"; | ||
var Aria2 = require('..') | ||
var Aria2 = require(".."); | ||
module.exports = function (cli, options, method, params) { | ||
var debug = require('./debug')(cli) | ||
module.exports = function(cli, options, method, params) { | ||
var debug = require("./debug")(cli); | ||
var client = new Aria2(options) | ||
client.onsend = function (m) { | ||
debug('OUT', m) | ||
} | ||
client.onmessage = function (m) { | ||
debug('IN', m) | ||
} | ||
var client = new Aria2(options); | ||
client.onsend = function(m) { | ||
debug("OUT", m); | ||
}; | ||
client.onmessage = function(m) { | ||
debug("IN", m); | ||
}; | ||
var cb = function (err, res) { | ||
var cb = function(err, res) { | ||
if (err) { | ||
console.error(err) | ||
process.exit(1) | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
console.log(res) | ||
process.exit(0) | ||
} | ||
console.log(res); | ||
process.exit(0); | ||
}; | ||
var args = [method].concat(params, cb) | ||
var args = [method].concat(params, cb); | ||
client.send.apply(client, args) | ||
} | ||
client.send.apply(client, args); | ||
}; |
#!/usr/bin/env node | ||
'use strict' | ||
"use strict"; | ||
var url = require('url') | ||
var cli = require('commander') | ||
var url = require("url"); | ||
var cli = require("commander"); | ||
process.title = 'aria2rpc' | ||
process.title = "aria2rpc"; | ||
var makeOptions = function () { | ||
var options = {'secret': cli.secret} | ||
var makeOptions = function() { | ||
var options = { secret: cli.secret }; | ||
if (cli.url) { | ||
var parsed = url.parse(cli.url) | ||
options.secure = parsed.protocol === 'wss:' | ||
options.host = parsed.hostname | ||
options.port = parsed.port | ||
options.path = parsed.path | ||
var parsed = url.parse(cli.url); | ||
options.secure = parsed.protocol === "wss:"; | ||
options.host = parsed.hostname; | ||
options.port = parsed.port; | ||
options.path = parsed.path; | ||
} | ||
return options | ||
} | ||
return options; | ||
}; | ||
cli | ||
.version(require('../package.json').version) | ||
.option('-d, --debug', 'output debug information') | ||
.option('-u, --url [url]', 'websocket url to connect to', 'ws://localhost:6800/jsonrpc') | ||
.option('-s, --secret [secret]', 'aria2 secret to use') | ||
.version(require("../package.json").version) | ||
.option("-d, --debug", "output debug information") | ||
.option( | ||
"-u, --url [url]", | ||
"websocket url to connect to", | ||
"ws://localhost:6800/jsonrpc" | ||
) | ||
.option("-s, --secret [secret]", "aria2 secret to use"); | ||
// call | ||
cli | ||
.command('call <method> [params...]') | ||
.description('call an aria2 RPC method and print result') | ||
.action(function (method, params) { | ||
var options = makeOptions() | ||
require('./call')(cli, options, method, params) | ||
}) | ||
.command("call <method> [params...]") | ||
.description("call an aria2 RPC method and print result") | ||
.action(function(method, params) { | ||
var options = makeOptions(); | ||
require("./call")(cli, options, method, params); | ||
}); | ||
// console | ||
cli | ||
.command('console') | ||
.description('start interactive console') | ||
.action(function () { | ||
var options = makeOptions() | ||
require('./console')(cli, options) | ||
}) | ||
.command("console") | ||
.description("start interactive console") | ||
.action(function() { | ||
var options = makeOptions(); | ||
require("./console")(cli, options); | ||
}); | ||
cli.parse(process.argv) | ||
cli.parse(process.argv); |
@@ -1,56 +0,56 @@ | ||
'use strict' | ||
"use strict"; | ||
var readline = require('readline') | ||
var Aria2 = require('..') | ||
var readline = require("readline"); | ||
var Aria2 = require(".."); | ||
module.exports = function (cli, options) { | ||
var debug = require('./debug')(cli) | ||
module.exports = function(cli, options) { | ||
var debug = require("./debug")(cli); | ||
var client = new Aria2(options) | ||
client.onsend = function (m) { | ||
debug('OUT', m) | ||
} | ||
client.onmessage = function (m) { | ||
debug('IN', m) | ||
var client = new Aria2(options); | ||
client.onsend = function(m) { | ||
debug("OUT", m); | ||
}; | ||
client.onmessage = function(m) { | ||
debug("IN", m); | ||
if (m.id === undefined) { | ||
console.log(m) | ||
console.log(m); | ||
} | ||
} | ||
debug('CONNECTING') | ||
client.open(function (err) { | ||
}; | ||
debug("CONNECTING"); | ||
client.open(function(err) { | ||
if (err) { | ||
console.error(err) | ||
process.exit(1) | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
debug('CONNECTED') | ||
debug("CONNECTED"); | ||
var rl = readline.createInterface({ | ||
'input': process.stdin, | ||
'output': process.stdout | ||
}) | ||
rl.setPrompt('aria2rpc ≻ ') | ||
rl.prompt() | ||
rl.on('line', function (line) { | ||
line = line.trim() | ||
if (!line) return rl.prompt() | ||
var params = line.split(' ') | ||
var cb = function (err, res) { | ||
if (err) console.error(err) | ||
else console.log(res) | ||
rl.prompt() | ||
} | ||
input: process.stdin, | ||
output: process.stdout | ||
}); | ||
rl.setPrompt("aria2rpc ≻ "); | ||
rl.prompt(); | ||
rl.on("line", function(line) { | ||
line = line.trim(); | ||
if (!line) return rl.prompt(); | ||
var params = line.split(" "); | ||
var cb = function(err, res) { | ||
if (err) console.error(err); | ||
else console.log(res); | ||
rl.prompt(); | ||
}; | ||
var args = params.concat(cb) | ||
var args = params.concat(cb); | ||
client.send.apply(client, args) | ||
}) | ||
rl.on('close', function () { | ||
debug('CLOSING') | ||
client.close(function () { | ||
debug('CLOSED') | ||
process.exit(0) | ||
}) | ||
}) | ||
}) | ||
} | ||
client.send.apply(client, args); | ||
}); | ||
rl.on("close", function() { | ||
debug("CLOSING"); | ||
client.close(function() { | ||
debug("CLOSED"); | ||
process.exit(0); | ||
}); | ||
}); | ||
}); | ||
}; |
@@ -1,9 +0,9 @@ | ||
'use strict' | ||
"use strict"; | ||
module.exports = function (cli) { | ||
return function () { | ||
module.exports = function(cli) { | ||
return function() { | ||
if (cli.debug) { | ||
console.log.apply(console, arguments) | ||
console.log.apply(console, arguments); | ||
} | ||
} | ||
} | ||
}; | ||
}; |
371
bundle.js
@@ -29,170 +29,193 @@ ;(function (global) { | ||
}(typeof global !== 'undefined' ? global : this)) | ||
;(function (global) { | ||
'use strict' | ||
(function(global) { | ||
"use strict"; | ||
var WebSocket | ||
var fetch | ||
var pg | ||
var WebSocket; | ||
var fetch; | ||
var pg; | ||
var isNode = typeof module !== 'undefined' && module.exports | ||
var isNode = typeof module !== "undefined" && module.exports; | ||
if (isNode) { | ||
WebSocket = require('ws') | ||
fetch = require('node-fetch') | ||
pg = require('polygoat') | ||
WebSocket = require("ws"); | ||
fetch = require("node-fetch"); | ||
pg = require("polygoat"); | ||
} else { | ||
WebSocket = global.WebSocket | ||
fetch = global.fetch | ||
pg = global.polygoat | ||
WebSocket = global.WebSocket; | ||
fetch = global.fetch; | ||
pg = global.polygoat; | ||
} | ||
var Aria2 = function (opts) { | ||
this.callbacks = Object.create(null) | ||
this.lastId = 0 | ||
var Aria2 = function(opts) { | ||
this.callbacks = Object.create(null); | ||
this.lastId = 0; | ||
for (var i in Aria2.options) { | ||
this[i] = typeof opts === 'object' && i in opts ? opts[i] : Aria2.options[i] | ||
this[i] = | ||
typeof opts === "object" && i in opts ? opts[i] : Aria2.options[i]; | ||
} | ||
} | ||
}; | ||
Aria2.prototype.http = function (m, fn) { | ||
var that = this | ||
Aria2.prototype.http = function(m, fn) { | ||
var that = this; | ||
var content = { | ||
method: m.method, | ||
id: m.id | ||
} | ||
}; | ||
if (Array.isArray(m.params) && m.params.length > 0) { | ||
content.params = m.params | ||
content.params = m.params; | ||
} | ||
var url = 'http' + (this.secure ? 's' : '') + '://' + this.host + ':' + this.port + this.path | ||
var url = | ||
"http" + | ||
(this.secure ? "s" : "") + | ||
"://" + | ||
this.host + | ||
":" + | ||
this.port + | ||
this.path; | ||
fetch(url, { | ||
method: 'POST', | ||
method: "POST", | ||
body: JSON.stringify(content), | ||
headers: { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json' | ||
}}) | ||
.then(function (res) { | ||
return res.json() | ||
Accept: "application/json", | ||
"Content-Type": "application/json" | ||
} | ||
}) | ||
.then(function(res) { | ||
return res.json(); | ||
}) | ||
.then(function (msg) { | ||
that._onmessage(msg) | ||
.then(function(msg) { | ||
that._onmessage(msg); | ||
}) | ||
.catch(fn) | ||
} | ||
.catch(fn); | ||
}; | ||
Aria2.prototype.send = function (method /* [,param] [,param] [,...] [, fn] */) { | ||
var params = Array.prototype.slice.call(arguments, 1) | ||
var cb = typeof params[params.length - 1] === 'function' ? params.pop() : null | ||
return this.exec(method, params, cb) | ||
} | ||
Aria2.prototype.send = function( | ||
method /* [,param] [,param] [,...] [, fn] */ | ||
) { | ||
var params = Array.prototype.slice.call(arguments, 1); | ||
var cb = | ||
typeof params[params.length - 1] === "function" ? params.pop() : null; | ||
return this.exec(method, params, cb); | ||
}; | ||
Aria2.prototype.exec = function (method, parameters, cb) { | ||
if (typeof method !== 'string') { | ||
throw new TypeError(method + ' is not a string') | ||
Aria2.prototype.exec = function(method, parameters, cb) { | ||
if (typeof method !== "string") { | ||
throw new TypeError(method + " is not a string"); | ||
} | ||
if (method.indexOf('system.') !== 0 && method.indexOf('aria2.') !== 0) { | ||
method = 'aria2.' + method | ||
if (method.indexOf("system.") !== 0 && method.indexOf("aria2.") !== 0) { | ||
method = "aria2." + method; | ||
} | ||
var m = { | ||
'method': method, | ||
'json-rpc': '2.0', | ||
'id': this.lastId++ | ||
} | ||
method: method, | ||
"json-rpc": "2.0", | ||
id: this.lastId++ | ||
}; | ||
var params = this.secret ? ['token:' + this.secret] : [] | ||
var params = this.secret ? ["token:" + this.secret] : []; | ||
if (Array.isArray(parameters)) { | ||
params = params.concat(parameters) | ||
params = params.concat(parameters); | ||
} | ||
if (params.length > 0) m.params = params | ||
if (params.length > 0) m.params = params; | ||
this.onsend(m) | ||
this.onsend(m); | ||
var that = this | ||
var that = this; | ||
// send via websocket | ||
if (this.socket && this.socket.readyState === 1) { | ||
this.socket.send(JSON.stringify(m)) | ||
// send via http | ||
this.socket.send(JSON.stringify(m)); | ||
// send via http | ||
} else { | ||
this.http(m, function (err) { | ||
that.callbacks[m.id](err) | ||
delete that.callbacks[m.id] | ||
}) | ||
this.http(m, function(err) { | ||
that.callbacks[m.id](err); | ||
delete that.callbacks[m.id]; | ||
}); | ||
} | ||
return pg(function (done) { | ||
that.callbacks[m.id] = done | ||
}, cb) | ||
} | ||
return pg(function(done) { | ||
that.callbacks[m.id] = done; | ||
}, cb); | ||
}; | ||
Aria2.prototype._onmessage = function (m) { | ||
this.onmessage(m) | ||
Aria2.prototype._onmessage = function(m) { | ||
this.onmessage(m); | ||
if (m.id !== undefined) { | ||
var callback = this.callbacks[m.id] | ||
var callback = this.callbacks[m.id]; | ||
if (callback) { | ||
if (m.error) { | ||
callback(m.error) | ||
callback(m.error); | ||
} else { | ||
callback(null, m.result) | ||
callback(null, m.result); | ||
} | ||
delete this.callbacks[m.id] | ||
delete this.callbacks[m.id]; | ||
} | ||
} else if (m.method) { | ||
var n = m.method.split('aria2.')[1] | ||
if (n.indexOf('on') === 0 && typeof this[n] === 'function' && Aria2.notifications.indexOf(n) > -1) { | ||
this[n].apply(this, m.params) | ||
var n = m.method.split("aria2.")[1]; | ||
if ( | ||
n.indexOf("on") === 0 && | ||
typeof this[n] === "function" && | ||
Aria2.notifications.indexOf(n) > -1 | ||
) { | ||
this[n].apply(this, m.params); | ||
} | ||
} | ||
} | ||
}; | ||
Aria2.prototype.open = function (fn) { | ||
var url = 'ws' + (this.secure ? 's' : '') + '://' + this.host + ':' + this.port + this.path | ||
var socket = this.socket = new WebSocket(url) | ||
var that = this | ||
var called = false | ||
Aria2.prototype.open = function(fn) { | ||
var url = | ||
"ws" + | ||
(this.secure ? "s" : "") + | ||
"://" + | ||
this.host + | ||
":" + | ||
this.port + | ||
this.path; | ||
var socket = (this.socket = new WebSocket(url)); | ||
var that = this; | ||
var called = false; | ||
socket.onclose = function () { | ||
that.onclose() | ||
} | ||
socket.onmessage = function (event) { | ||
that._onmessage(JSON.parse(event.data)) | ||
} | ||
socket.onclose = function() { | ||
that.onclose(); | ||
}; | ||
socket.onmessage = function(event) { | ||
that._onmessage(JSON.parse(event.data)); | ||
}; | ||
return pg(function (done) { | ||
socket.onopen = function () { | ||
return pg(function(done) { | ||
socket.onopen = function() { | ||
if (!called) { | ||
done() | ||
called = true | ||
done(); | ||
called = true; | ||
} | ||
that.onopen() | ||
} | ||
socket.onerror = function (err) { | ||
that.onopen(); | ||
}; | ||
socket.onerror = function(err) { | ||
if (!called) { | ||
done(err) | ||
called = true | ||
done(err); | ||
called = true; | ||
} | ||
} | ||
}, fn) | ||
} | ||
}; | ||
}, fn); | ||
}; | ||
Aria2.prototype.close = function (fn) { | ||
var socket = this.socket | ||
return pg(function (done) { | ||
Aria2.prototype.close = function(fn) { | ||
var socket = this.socket; | ||
return pg(function(done) { | ||
if (!socket) { | ||
done() | ||
done(); | ||
} else { | ||
socket.addEventListener('close', function () { | ||
done() | ||
}) | ||
socket.close() | ||
socket.addEventListener("close", function() { | ||
done(); | ||
}); | ||
socket.close(); | ||
} | ||
}, fn) | ||
} | ||
}, fn); | ||
}; | ||
@@ -202,74 +225,74 @@ // https://aria2.github.io/manual/en/html/aria2c.html#methods | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.addUri | ||
'addUri', | ||
"addUri", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.addTorrent | ||
'addTorrent', | ||
"addTorrent", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.addMetalink | ||
'addMetalink', | ||
"addMetalink", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.remove | ||
'remove', | ||
"remove", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.forceRemove | ||
'forceRemove', | ||
"forceRemove", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.pause | ||
'pause', | ||
"pause", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.pauseAll | ||
'pauseAll', | ||
"pauseAll", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.forcePause | ||
'forcePause', | ||
"forcePause", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.forcePauseAll | ||
'forcePauseAll', | ||
"forcePauseAll", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.unpause | ||
'unpause', | ||
"unpause", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.unpauseAll | ||
'unpauseAll', | ||
"unpauseAll", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.tellStatus | ||
'tellStatus', | ||
"tellStatus", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.getUris | ||
'getUris', | ||
"getUris", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.getFiles | ||
'getFiles', | ||
"getFiles", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.getPeers | ||
'getPeers', | ||
"getPeers", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.getServers | ||
'getServers', | ||
"getServers", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.tellActive | ||
'tellActive', | ||
"tellActive", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.tellWaiting | ||
'tellWaiting', | ||
"tellWaiting", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.tellStopped | ||
'tellStopped', | ||
"tellStopped", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.changePosition | ||
'changePosition', | ||
"changePosition", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.changeUri | ||
'changeUri', | ||
"changeUri", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.getOption | ||
'getOption', | ||
"getOption", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.changeOption | ||
'changeOption', | ||
"changeOption", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.getGlobalOption | ||
'getGlobalOption', | ||
"getGlobalOption", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.changeGlobalOption | ||
'changeGlobalOption', | ||
"changeGlobalOption", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.getGlobalStat | ||
'getGlobalStat', | ||
"getGlobalStat", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.purgeDownloadResult | ||
'purgeDownloadResult', | ||
"purgeDownloadResult", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.removeDownloadResult | ||
'removeDownloadResult', | ||
"removeDownloadResult", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.getVersion | ||
'getVersion', | ||
"getVersion", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.getSessionInfo | ||
'getSessionInfo', | ||
"getSessionInfo", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.shutdown | ||
'shutdown', | ||
"shutdown", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.forceShutdown | ||
'forceShutdown', | ||
"forceShutdown", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.saveSession | ||
'saveSession', | ||
"saveSession", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#system.multicall | ||
'system.multicall', | ||
"system.multicall", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#system.listMethods | ||
'system.listMethods', | ||
"system.listMethods", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#system.listNotifications | ||
'system.listNotifications' | ||
] | ||
"system.listNotifications" | ||
]; | ||
@@ -279,50 +302,48 @@ // https://aria2.github.io/manual/en/html/aria2c.html#notifications | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.onDownloadStart | ||
'onDownloadStart', | ||
"onDownloadStart", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.onDownloadPause | ||
'onDownloadPause', | ||
"onDownloadPause", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.onDownloadStop | ||
'onDownloadStop', | ||
"onDownloadStop", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.onDownloadComplete | ||
'onDownloadComplete', | ||
"onDownloadComplete", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.onDownloadError | ||
'onDownloadError', | ||
"onDownloadError", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.onBtDownloadComplete | ||
'onBtDownloadComplete' | ||
] | ||
"onBtDownloadComplete" | ||
]; | ||
Aria2.events = [ | ||
'onopen', | ||
'onclose', | ||
'onsend', | ||
'onmessage' | ||
] | ||
Aria2.events = ["onopen", "onclose", "onsend", "onmessage"]; | ||
Aria2.options = { | ||
'secure': false, | ||
'host': 'localhost', | ||
'port': 6800, | ||
'secret': '', | ||
'path': '/jsonrpc' | ||
} | ||
secure: false, | ||
host: "localhost", | ||
port: 6800, | ||
secret: "", | ||
path: "/jsonrpc" | ||
}; | ||
Aria2.methods.forEach(function (method) { | ||
var sufix = method.indexOf('.') > -1 ? method.split('.')[1] : method | ||
Aria2.prototype[sufix] = function (/* [param] [,param] [,...] */) { | ||
return this.send.apply(this, [method].concat(Array.prototype.slice.call(arguments))) | ||
} | ||
}) | ||
Aria2.methods.forEach(function(method) { | ||
var sufix = method.indexOf(".") > -1 ? method.split(".")[1] : method; | ||
Aria2.prototype[sufix] = function(/* [param] [,param] [,...] */) { | ||
return this.send.apply( | ||
this, | ||
[method].concat(Array.prototype.slice.call(arguments)) | ||
); | ||
}; | ||
}); | ||
Aria2.notifications.forEach(function (notification) { | ||
Aria2.prototype[notification] = function () {} | ||
}) | ||
Aria2.notifications.forEach(function(notification) { | ||
Aria2.prototype[notification] = function() {}; | ||
}); | ||
Aria2.events.forEach(function (event) { | ||
Aria2.prototype[event] = function () {} | ||
}) | ||
Aria2.events.forEach(function(event) { | ||
Aria2.prototype[event] = function() {}; | ||
}); | ||
if (isNode) { | ||
module.exports = Aria2 | ||
module.exports = Aria2; | ||
} else { | ||
global.Aria2 = Aria2 | ||
global.Aria2 = Aria2; | ||
} | ||
}(this)) | ||
})(this); |
371
index.js
@@ -1,169 +0,192 @@ | ||
;(function (global) { | ||
'use strict' | ||
(function(global) { | ||
"use strict"; | ||
var WebSocket | ||
var fetch | ||
var pg | ||
var WebSocket; | ||
var fetch; | ||
var pg; | ||
var isNode = typeof module !== 'undefined' && module.exports | ||
var isNode = typeof module !== "undefined" && module.exports; | ||
if (isNode) { | ||
WebSocket = require('ws') | ||
fetch = require('node-fetch') | ||
pg = require('polygoat') | ||
WebSocket = require("ws"); | ||
fetch = require("node-fetch"); | ||
pg = require("polygoat"); | ||
} else { | ||
WebSocket = global.WebSocket | ||
fetch = global.fetch | ||
pg = global.polygoat | ||
WebSocket = global.WebSocket; | ||
fetch = global.fetch; | ||
pg = global.polygoat; | ||
} | ||
var Aria2 = function (opts) { | ||
this.callbacks = Object.create(null) | ||
this.lastId = 0 | ||
var Aria2 = function(opts) { | ||
this.callbacks = Object.create(null); | ||
this.lastId = 0; | ||
for (var i in Aria2.options) { | ||
this[i] = typeof opts === 'object' && i in opts ? opts[i] : Aria2.options[i] | ||
this[i] = | ||
typeof opts === "object" && i in opts ? opts[i] : Aria2.options[i]; | ||
} | ||
} | ||
}; | ||
Aria2.prototype.http = function (m, fn) { | ||
var that = this | ||
Aria2.prototype.http = function(m, fn) { | ||
var that = this; | ||
var content = { | ||
method: m.method, | ||
id: m.id | ||
} | ||
}; | ||
if (Array.isArray(m.params) && m.params.length > 0) { | ||
content.params = m.params | ||
content.params = m.params; | ||
} | ||
var url = 'http' + (this.secure ? 's' : '') + '://' + this.host + ':' + this.port + this.path | ||
var url = | ||
"http" + | ||
(this.secure ? "s" : "") + | ||
"://" + | ||
this.host + | ||
":" + | ||
this.port + | ||
this.path; | ||
fetch(url, { | ||
method: 'POST', | ||
method: "POST", | ||
body: JSON.stringify(content), | ||
headers: { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json' | ||
}}) | ||
.then(function (res) { | ||
return res.json() | ||
Accept: "application/json", | ||
"Content-Type": "application/json" | ||
} | ||
}) | ||
.then(function(res) { | ||
return res.json(); | ||
}) | ||
.then(function (msg) { | ||
that._onmessage(msg) | ||
.then(function(msg) { | ||
that._onmessage(msg); | ||
}) | ||
.catch(fn) | ||
} | ||
.catch(fn); | ||
}; | ||
Aria2.prototype.send = function (method /* [,param] [,param] [,...] [, fn] */) { | ||
var params = Array.prototype.slice.call(arguments, 1) | ||
var cb = typeof params[params.length - 1] === 'function' ? params.pop() : null | ||
return this.exec(method, params, cb) | ||
} | ||
Aria2.prototype.send = function( | ||
method /* [,param] [,param] [,...] [, fn] */ | ||
) { | ||
var params = Array.prototype.slice.call(arguments, 1); | ||
var cb = | ||
typeof params[params.length - 1] === "function" ? params.pop() : null; | ||
return this.exec(method, params, cb); | ||
}; | ||
Aria2.prototype.exec = function (method, parameters, cb) { | ||
if (typeof method !== 'string') { | ||
throw new TypeError(method + ' is not a string') | ||
Aria2.prototype.exec = function(method, parameters, cb) { | ||
if (typeof method !== "string") { | ||
throw new TypeError(method + " is not a string"); | ||
} | ||
if (method.indexOf('system.') !== 0 && method.indexOf('aria2.') !== 0) { | ||
method = 'aria2.' + method | ||
if (method.indexOf("system.") !== 0 && method.indexOf("aria2.") !== 0) { | ||
method = "aria2." + method; | ||
} | ||
var m = { | ||
'method': method, | ||
'json-rpc': '2.0', | ||
'id': this.lastId++ | ||
} | ||
method: method, | ||
"json-rpc": "2.0", | ||
id: this.lastId++ | ||
}; | ||
var params = this.secret ? ['token:' + this.secret] : [] | ||
var params = this.secret ? ["token:" + this.secret] : []; | ||
if (Array.isArray(parameters)) { | ||
params = params.concat(parameters) | ||
params = params.concat(parameters); | ||
} | ||
if (params.length > 0) m.params = params | ||
if (params.length > 0) m.params = params; | ||
this.onsend(m) | ||
this.onsend(m); | ||
var that = this | ||
var that = this; | ||
// send via websocket | ||
if (this.socket && this.socket.readyState === 1) { | ||
this.socket.send(JSON.stringify(m)) | ||
// send via http | ||
this.socket.send(JSON.stringify(m)); | ||
// send via http | ||
} else { | ||
this.http(m, function (err) { | ||
that.callbacks[m.id](err) | ||
delete that.callbacks[m.id] | ||
}) | ||
this.http(m, function(err) { | ||
that.callbacks[m.id](err); | ||
delete that.callbacks[m.id]; | ||
}); | ||
} | ||
return pg(function (done) { | ||
that.callbacks[m.id] = done | ||
}, cb) | ||
} | ||
return pg(function(done) { | ||
that.callbacks[m.id] = done; | ||
}, cb); | ||
}; | ||
Aria2.prototype._onmessage = function (m) { | ||
this.onmessage(m) | ||
Aria2.prototype._onmessage = function(m) { | ||
this.onmessage(m); | ||
if (m.id !== undefined) { | ||
var callback = this.callbacks[m.id] | ||
var callback = this.callbacks[m.id]; | ||
if (callback) { | ||
if (m.error) { | ||
callback(m.error) | ||
callback(m.error); | ||
} else { | ||
callback(null, m.result) | ||
callback(null, m.result); | ||
} | ||
delete this.callbacks[m.id] | ||
delete this.callbacks[m.id]; | ||
} | ||
} else if (m.method) { | ||
var n = m.method.split('aria2.')[1] | ||
if (n.indexOf('on') === 0 && typeof this[n] === 'function' && Aria2.notifications.indexOf(n) > -1) { | ||
this[n].apply(this, m.params) | ||
var n = m.method.split("aria2.")[1]; | ||
if ( | ||
n.indexOf("on") === 0 && | ||
typeof this[n] === "function" && | ||
Aria2.notifications.indexOf(n) > -1 | ||
) { | ||
this[n].apply(this, m.params); | ||
} | ||
} | ||
} | ||
}; | ||
Aria2.prototype.open = function (fn) { | ||
var url = 'ws' + (this.secure ? 's' : '') + '://' + this.host + ':' + this.port + this.path | ||
var socket = this.socket = new WebSocket(url) | ||
var that = this | ||
var called = false | ||
Aria2.prototype.open = function(fn) { | ||
var url = | ||
"ws" + | ||
(this.secure ? "s" : "") + | ||
"://" + | ||
this.host + | ||
":" + | ||
this.port + | ||
this.path; | ||
var socket = (this.socket = new WebSocket(url)); | ||
var that = this; | ||
var called = false; | ||
socket.onclose = function () { | ||
that.onclose() | ||
} | ||
socket.onmessage = function (event) { | ||
that._onmessage(JSON.parse(event.data)) | ||
} | ||
socket.onclose = function() { | ||
that.onclose(); | ||
}; | ||
socket.onmessage = function(event) { | ||
that._onmessage(JSON.parse(event.data)); | ||
}; | ||
return pg(function (done) { | ||
socket.onopen = function () { | ||
return pg(function(done) { | ||
socket.onopen = function() { | ||
if (!called) { | ||
done() | ||
called = true | ||
done(); | ||
called = true; | ||
} | ||
that.onopen() | ||
} | ||
socket.onerror = function (err) { | ||
that.onopen(); | ||
}; | ||
socket.onerror = function(err) { | ||
if (!called) { | ||
done(err) | ||
called = true | ||
done(err); | ||
called = true; | ||
} | ||
} | ||
}, fn) | ||
} | ||
}; | ||
}, fn); | ||
}; | ||
Aria2.prototype.close = function (fn) { | ||
var socket = this.socket | ||
return pg(function (done) { | ||
Aria2.prototype.close = function(fn) { | ||
var socket = this.socket; | ||
return pg(function(done) { | ||
if (!socket) { | ||
done() | ||
done(); | ||
} else { | ||
socket.addEventListener('close', function () { | ||
done() | ||
}) | ||
socket.close() | ||
socket.addEventListener("close", function() { | ||
done(); | ||
}); | ||
socket.close(); | ||
} | ||
}, fn) | ||
} | ||
}, fn); | ||
}; | ||
@@ -173,74 +196,74 @@ // https://aria2.github.io/manual/en/html/aria2c.html#methods | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.addUri | ||
'addUri', | ||
"addUri", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.addTorrent | ||
'addTorrent', | ||
"addTorrent", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.addMetalink | ||
'addMetalink', | ||
"addMetalink", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.remove | ||
'remove', | ||
"remove", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.forceRemove | ||
'forceRemove', | ||
"forceRemove", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.pause | ||
'pause', | ||
"pause", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.pauseAll | ||
'pauseAll', | ||
"pauseAll", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.forcePause | ||
'forcePause', | ||
"forcePause", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.forcePauseAll | ||
'forcePauseAll', | ||
"forcePauseAll", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.unpause | ||
'unpause', | ||
"unpause", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.unpauseAll | ||
'unpauseAll', | ||
"unpauseAll", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.tellStatus | ||
'tellStatus', | ||
"tellStatus", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.getUris | ||
'getUris', | ||
"getUris", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.getFiles | ||
'getFiles', | ||
"getFiles", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.getPeers | ||
'getPeers', | ||
"getPeers", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.getServers | ||
'getServers', | ||
"getServers", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.tellActive | ||
'tellActive', | ||
"tellActive", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.tellWaiting | ||
'tellWaiting', | ||
"tellWaiting", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.tellStopped | ||
'tellStopped', | ||
"tellStopped", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.changePosition | ||
'changePosition', | ||
"changePosition", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.changeUri | ||
'changeUri', | ||
"changeUri", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.getOption | ||
'getOption', | ||
"getOption", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.changeOption | ||
'changeOption', | ||
"changeOption", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.getGlobalOption | ||
'getGlobalOption', | ||
"getGlobalOption", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.changeGlobalOption | ||
'changeGlobalOption', | ||
"changeGlobalOption", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.getGlobalStat | ||
'getGlobalStat', | ||
"getGlobalStat", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.purgeDownloadResult | ||
'purgeDownloadResult', | ||
"purgeDownloadResult", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.removeDownloadResult | ||
'removeDownloadResult', | ||
"removeDownloadResult", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.getVersion | ||
'getVersion', | ||
"getVersion", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.getSessionInfo | ||
'getSessionInfo', | ||
"getSessionInfo", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.shutdown | ||
'shutdown', | ||
"shutdown", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.forceShutdown | ||
'forceShutdown', | ||
"forceShutdown", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.saveSession | ||
'saveSession', | ||
"saveSession", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#system.multicall | ||
'system.multicall', | ||
"system.multicall", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#system.listMethods | ||
'system.listMethods', | ||
"system.listMethods", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#system.listNotifications | ||
'system.listNotifications' | ||
] | ||
"system.listNotifications" | ||
]; | ||
@@ -250,50 +273,48 @@ // https://aria2.github.io/manual/en/html/aria2c.html#notifications | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.onDownloadStart | ||
'onDownloadStart', | ||
"onDownloadStart", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.onDownloadPause | ||
'onDownloadPause', | ||
"onDownloadPause", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.onDownloadStop | ||
'onDownloadStop', | ||
"onDownloadStop", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.onDownloadComplete | ||
'onDownloadComplete', | ||
"onDownloadComplete", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.onDownloadError | ||
'onDownloadError', | ||
"onDownloadError", | ||
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.onBtDownloadComplete | ||
'onBtDownloadComplete' | ||
] | ||
"onBtDownloadComplete" | ||
]; | ||
Aria2.events = [ | ||
'onopen', | ||
'onclose', | ||
'onsend', | ||
'onmessage' | ||
] | ||
Aria2.events = ["onopen", "onclose", "onsend", "onmessage"]; | ||
Aria2.options = { | ||
'secure': false, | ||
'host': 'localhost', | ||
'port': 6800, | ||
'secret': '', | ||
'path': '/jsonrpc' | ||
} | ||
secure: false, | ||
host: "localhost", | ||
port: 6800, | ||
secret: "", | ||
path: "/jsonrpc" | ||
}; | ||
Aria2.methods.forEach(function (method) { | ||
var sufix = method.indexOf('.') > -1 ? method.split('.')[1] : method | ||
Aria2.prototype[sufix] = function (/* [param] [,param] [,...] */) { | ||
return this.send.apply(this, [method].concat(Array.prototype.slice.call(arguments))) | ||
} | ||
}) | ||
Aria2.methods.forEach(function(method) { | ||
var sufix = method.indexOf(".") > -1 ? method.split(".")[1] : method; | ||
Aria2.prototype[sufix] = function(/* [param] [,param] [,...] */) { | ||
return this.send.apply( | ||
this, | ||
[method].concat(Array.prototype.slice.call(arguments)) | ||
); | ||
}; | ||
}); | ||
Aria2.notifications.forEach(function (notification) { | ||
Aria2.prototype[notification] = function () {} | ||
}) | ||
Aria2.notifications.forEach(function(notification) { | ||
Aria2.prototype[notification] = function() {}; | ||
}); | ||
Aria2.events.forEach(function (event) { | ||
Aria2.prototype[event] = function () {} | ||
}) | ||
Aria2.events.forEach(function(event) { | ||
Aria2.prototype[event] = function() {}; | ||
}); | ||
if (isNode) { | ||
module.exports = Aria2 | ||
module.exports = Aria2; | ||
} else { | ||
global.Aria2 = Aria2 | ||
global.Aria2 = Aria2; | ||
} | ||
}(this)) | ||
})(this); |
{ | ||
"name": "aria2", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Library and cli for aria2, \"The next generation download utility.\"", | ||
@@ -26,6 +26,5 @@ "homepage": "https://github.com/sonnyp/aria2.js", | ||
"preversion": "npm test", | ||
"lint": "standard", | ||
"lint": "prettier -l **/*.js", | ||
"bundle": "cat node_modules/polygoat/index.js index.js > bundle.js", | ||
"unit": "mocha test/unit.js", | ||
"integration": "mocha test/integration.js", | ||
"unit": "mocha test/test.js", | ||
"test": "npm run bundle && npm run unit && npm run lint" | ||
@@ -36,13 +35,13 @@ }, | ||
"commander": "^2.9.0", | ||
"node-fetch": "^1.6.3", | ||
"node-fetch": "^2.1.2", | ||
"polygoat": "^1.1.4", | ||
"ws": "^1.1.1" | ||
"ws": "^5.1.1" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.4.1", | ||
"mocha": "^3.1.0", | ||
"sinon": "^1.17.2", | ||
"sinon-chai": "^2.8.0", | ||
"standard": "^8.2.0" | ||
"chai": "^4.1.2", | ||
"mocha": "^5.1.1", | ||
"prettier": "1.12.1", | ||
"sinon": "^4.5.0", | ||
"sinon-chai": "^3.0.0" | ||
} | ||
} |
166
README.md
@@ -1,66 +0,66 @@ | ||
aria2.js | ||
======== | ||
# aria2.js | ||
JavaScript (Node.js and browsers) library and [cli](https://github.com/sonnyp/aria2.js/blob/master/bin/README.md) for [aria2, "The next generation download utility."](https://aria2.github.io/) | ||
[![license](https://img.shields.io/github/license/sonnyp/aria2.js.svg?maxAge=2592000&style=flat-square)](https://raw.githubusercontent.com/sonnyp/aria2.js/master/LICENSE.md) | ||
[![Build Status](https://img.shields.io/travis/sonnyp/aria2.js/master.svg?style=flat-square)](https://travis-ci.org/sonnyp/aria2.js/branches) | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/) | ||
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier) | ||
[![Dependency Status](https://img.shields.io/david/sonnyp/aria2.js.svg?style=flat-square)](https://david-dm.org/sonnyp/aria2.js) | ||
[![devDependency Status](https://img.shields.io/david/dev/sonnyp/aria2.js.svg?style=flat-square)](https://david-dm.org/sonnyp/aria2.js#info=devDependencies) | ||
[![devDependency Status](https://img.shields.io/david/dev/sonnyp/aria2.js.svg?style=flat-square)](https://david-dm.org/sonnyp/aria2.js?type=dev) | ||
- [Introduction](#introduction) | ||
- [Getting started](#getting-started) | ||
- [Usage](#usage) | ||
- [open](#open) | ||
- [close](#close) | ||
- [onsend and onmessage](#onsend-and-onmessage) | ||
- [aria2 methods](#aria2-methods) | ||
- [addUri](https://aria2.github.io/manual/en/html/aria2c.html#aria2.addUri) | ||
- [addTorrent](https://aria2.github.io/manual/en/html/aria2c.html#aria2.addTorrent) | ||
- [addMetaLink](https://aria2.github.io/manual/en/html/aria2c.html#aria2.addMetalink) | ||
- [remove](https://aria2.github.io/manual/en/html/aria2c.html#aria2.remove) | ||
- [forceRemove](https://aria2.github.io/manual/en/html/aria2c.html#aria2.forceRemove) | ||
- [pause](https://aria2.github.io/manual/en/html/aria2c.html#aria2.pause) | ||
- [pauseAll](https://aria2.github.io/manual/en/html/aria2c.html#aria2.pauseAll) | ||
- [forcePause](https://aria2.github.io/manual/en/html/aria2c.html#aria2.forcePause) | ||
- [forcePauseAll](https://aria2.github.io/manual/en/html/aria2c.html#aria2.forcePauseAll) | ||
- [unpause](https://aria2.github.io/manual/en/html/aria2c.html#aria2.unpause) | ||
- [unpauseAll](https://aria2.github.io/manual/en/html/aria2c.html#aria2.unpauseAll) | ||
- [tellStatus](https://aria2.github.io/manual/en/html/aria2c.html#aria2.tellStatus) | ||
- [getUris](https://aria2.github.io/manual/en/html/aria2c.html#aria2.getUris) | ||
- [getFiles](https://aria2.github.io/manual/en/html/aria2c.html#aria2.getFiles) | ||
- [getPeers](https://aria2.github.io/manual/en/html/aria2c.html#aria2.getPeers) | ||
- [getServers](https://aria2.github.io/manual/en/html/aria2c.html#aria2.getServers) | ||
- [tellActive](https://aria2.github.io/manual/en/html/aria2c.html#aria2.tellActive) | ||
- [tellWaiting](https://aria2.github.io/manual/en/html/aria2c.html#aria2.tellWaiting) | ||
- [tellStopped](https://aria2.github.io/manual/en/html/aria2c.html#aria2.tellStopped) | ||
- [changePosition](https://aria2.github.io/manual/en/html/aria2c.html#aria2.changePosition) | ||
- [changeUri](https://aria2.github.io/manual/en/html/aria2c.html#aria2.changeUri) | ||
- [getOption](https://aria2.github.io/manual/en/html/aria2c.html#aria2.getOption) | ||
- [changeOption](https://aria2.github.io/manual/en/html/aria2c.html#aria2.changeOption) | ||
- [getGlobalOption](https://aria2.github.io/manual/en/html/aria2c.html#aria2.getGlobalOption) | ||
- [changeGlobalOption](https://aria2.github.io/manual/en/html/aria2c.html#aria2.changeGlobalOption) | ||
- [getGlobalStat](https://aria2.github.io/manual/en/html/aria2c.html#aria2.getGlobalStat) | ||
- [purgeDownloadResult](https://aria2.github.io/manual/en/html/aria2c.html#aria2.purgeDownloadResult) | ||
- [removeDownloadResult](https://aria2.github.io/manual/en/html/aria2c.html#aria2.removeDownloadResult) | ||
- [getVersion](https://aria2.github.io/manual/en/html/aria2c.html#aria2.getVersion) | ||
- [getSessionInfo](https://aria2.github.io/manual/en/html/aria2c.html#aria2.getSessionInfo) | ||
- [shutdown](https://aria2.github.io/manual/en/html/aria2c.html#aria2.shutdown) | ||
- [forceShutdown](https://aria2.github.io/manual/en/html/aria2c.html#aria2.forceShutdown) | ||
- [saveSession](https://aria2.github.io/manual/en/html/aria2c.html#aria2.saveSession) | ||
- [system.multicall](https://aria2.github.io/manual/en/html/aria2c.html#system.multicall) | ||
- [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) | ||
- [onDownloadStart](https://aria2.github.io/manual/en/html/aria2c.html#aria2.onDownloadStart) | ||
- [onDownloadPause](https://aria2.github.io/manual/en/html/aria2c.html#aria2.onDownloadPause) | ||
- [onDownloadStop](https://aria2.github.io/manual/en/html/aria2c.html#aria2.onDownloadStop) | ||
- [onDownloadComplete](https://aria2.github.io/manual/en/html/aria2c.html#aria2.onDownloadComplete) | ||
- [onDownloadError](https://aria2.github.io/manual/en/html/aria2c.html#aria2.onDownloadError) | ||
- [onBtDownloadComplete](https://aria2.github.io/manual/en/html/aria2c.html#aria2.onBtDownloadComplete) | ||
- [Example](#example) | ||
- [Contributing](#contributing) | ||
* [Introduction](#introduction) | ||
* [Getting started](#getting-started) | ||
* [Usage](#usage) | ||
* [open](#open) | ||
* [close](#close) | ||
* [onsend and onmessage](#onsend-and-onmessage) | ||
* [aria2 methods](#aria2-methods) | ||
* [addUri](https://aria2.github.io/manual/en/html/aria2c.html#aria2.addUri) | ||
* [addTorrent](https://aria2.github.io/manual/en/html/aria2c.html#aria2.addTorrent) | ||
* [addMetaLink](https://aria2.github.io/manual/en/html/aria2c.html#aria2.addMetalink) | ||
* [remove](https://aria2.github.io/manual/en/html/aria2c.html#aria2.remove) | ||
* [forceRemove](https://aria2.github.io/manual/en/html/aria2c.html#aria2.forceRemove) | ||
* [pause](https://aria2.github.io/manual/en/html/aria2c.html#aria2.pause) | ||
* [pauseAll](https://aria2.github.io/manual/en/html/aria2c.html#aria2.pauseAll) | ||
* [forcePause](https://aria2.github.io/manual/en/html/aria2c.html#aria2.forcePause) | ||
* [forcePauseAll](https://aria2.github.io/manual/en/html/aria2c.html#aria2.forcePauseAll) | ||
* [unpause](https://aria2.github.io/manual/en/html/aria2c.html#aria2.unpause) | ||
* [unpauseAll](https://aria2.github.io/manual/en/html/aria2c.html#aria2.unpauseAll) | ||
* [tellStatus](https://aria2.github.io/manual/en/html/aria2c.html#aria2.tellStatus) | ||
* [getUris](https://aria2.github.io/manual/en/html/aria2c.html#aria2.getUris) | ||
* [getFiles](https://aria2.github.io/manual/en/html/aria2c.html#aria2.getFiles) | ||
* [getPeers](https://aria2.github.io/manual/en/html/aria2c.html#aria2.getPeers) | ||
* [getServers](https://aria2.github.io/manual/en/html/aria2c.html#aria2.getServers) | ||
* [tellActive](https://aria2.github.io/manual/en/html/aria2c.html#aria2.tellActive) | ||
* [tellWaiting](https://aria2.github.io/manual/en/html/aria2c.html#aria2.tellWaiting) | ||
* [tellStopped](https://aria2.github.io/manual/en/html/aria2c.html#aria2.tellStopped) | ||
* [changePosition](https://aria2.github.io/manual/en/html/aria2c.html#aria2.changePosition) | ||
* [changeUri](https://aria2.github.io/manual/en/html/aria2c.html#aria2.changeUri) | ||
* [getOption](https://aria2.github.io/manual/en/html/aria2c.html#aria2.getOption) | ||
* [changeOption](https://aria2.github.io/manual/en/html/aria2c.html#aria2.changeOption) | ||
* [getGlobalOption](https://aria2.github.io/manual/en/html/aria2c.html#aria2.getGlobalOption) | ||
* [changeGlobalOption](https://aria2.github.io/manual/en/html/aria2c.html#aria2.changeGlobalOption) | ||
* [getGlobalStat](https://aria2.github.io/manual/en/html/aria2c.html#aria2.getGlobalStat) | ||
* [purgeDownloadResult](https://aria2.github.io/manual/en/html/aria2c.html#aria2.purgeDownloadResult) | ||
* [removeDownloadResult](https://aria2.github.io/manual/en/html/aria2c.html#aria2.removeDownloadResult) | ||
* [getVersion](https://aria2.github.io/manual/en/html/aria2c.html#aria2.getVersion) | ||
* [getSessionInfo](https://aria2.github.io/manual/en/html/aria2c.html#aria2.getSessionInfo) | ||
* [shutdown](https://aria2.github.io/manual/en/html/aria2c.html#aria2.shutdown) | ||
* [forceShutdown](https://aria2.github.io/manual/en/html/aria2c.html#aria2.forceShutdown) | ||
* [saveSession](https://aria2.github.io/manual/en/html/aria2c.html#aria2.saveSession) | ||
* [system.multicall](https://aria2.github.io/manual/en/html/aria2c.html#system.multicall) | ||
* [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) | ||
* [onDownloadStart](https://aria2.github.io/manual/en/html/aria2c.html#aria2.onDownloadStart) | ||
* [onDownloadPause](https://aria2.github.io/manual/en/html/aria2c.html#aria2.onDownloadPause) | ||
* [onDownloadStop](https://aria2.github.io/manual/en/html/aria2c.html#aria2.onDownloadStop) | ||
* [onDownloadComplete](https://aria2.github.io/manual/en/html/aria2c.html#aria2.onDownloadComplete) | ||
* [onDownloadError](https://aria2.github.io/manual/en/html/aria2c.html#aria2.onDownloadError) | ||
* [onBtDownloadComplete](https://aria2.github.io/manual/en/html/aria2c.html#aria2.onBtDownloadComplete) | ||
* [Example](#example) | ||
* [Contributing](#contributing) | ||
# Introduction | ||
@@ -70,10 +70,10 @@ | ||
- Node.js and browsers support | ||
- multiple transports | ||
- [HTTP](https://aria2.github.io/manual/en/html/aria2c.html#rpc-interface) | ||
- [WebSocket](https://aria2.github.io/manual/en/html/aria2c.html#json-rpc-over-websocket) | ||
- ~~[JSONP](https://aria2.github.io/manual/en/html/aria2c.html#json-rpc-using-http-get)~~ [#25](https://github.com/sonnyp/aria2.js/pull/25) | ||
- callback API | ||
- promise API | ||
- light (1.5KB minified and gzipped) | ||
* Node.js and browsers support | ||
* multiple transports | ||
* [HTTP](https://aria2.github.io/manual/en/html/aria2c.html#rpc-interface) | ||
* [WebSocket](https://aria2.github.io/manual/en/html/aria2c.html#json-rpc-over-websocket) | ||
* ~~[JSONP](https://aria2.github.io/manual/en/html/aria2c.html#json-rpc-using-http-get)~~ [#25](https://github.com/sonnyp/aria2.js/pull/25) | ||
* callback API | ||
* promise API | ||
* light (1.5KB minified and gzipped) | ||
@@ -84,9 +84,8 @@ [↑](#aria2js) | ||
`npm install aria2` | ||
---- | ||
--- | ||
```javascript | ||
var Aria2 = require('aria2'); | ||
var Aria2 = require("aria2"); | ||
``` | ||
@@ -99,7 +98,8 @@ | ||
``` | ||
```javascript | ||
var Aria2 = window.Aria2 | ||
var Aria2 = window.Aria2; | ||
``` | ||
---- | ||
--- | ||
@@ -144,3 +144,3 @@ Start aria2c in daemon mode with | ||
aria2.onopen = function() { | ||
console.log('aria2 open'); | ||
console.log("aria2 open"); | ||
}; | ||
@@ -150,3 +150,3 @@ | ||
// or | ||
aria2.open().then(fn) | ||
aria2.open().then(fn); | ||
``` | ||
@@ -162,3 +162,3 @@ | ||
aria2.onclose = function() { | ||
console.log('aria2 closed!'); | ||
console.log("aria2 closed!"); | ||
}; | ||
@@ -180,6 +180,6 @@ | ||
aria2.onsend = function(m) { | ||
console.log('aria2 OUT', m); | ||
console.log("aria2 OUT", m); | ||
}; | ||
aria2.onmessage = function(m) { | ||
console.log('aria2 IN', m); | ||
console.log("aria2 IN", m); | ||
}; | ||
@@ -191,2 +191,3 @@ ``` | ||
## aria2 methods | ||
For a complete listing see [aria2 methods](https://aria2.github.io/manual/en/html/aria2c.html#methods). | ||
@@ -199,2 +200,3 @@ | ||
#### callback style | ||
```javascript | ||
@@ -217,3 +219,3 @@ aria2.getVersion([params,] function(err, res) { | ||
```javascript | ||
aria2.getVersion([params,]).then(fn) | ||
aria2.getVersion([params]).then(fn); | ||
``` | ||
@@ -224,3 +226,3 @@ | ||
```javascript | ||
aria2.send('getVersion', [params,]).then(fn) | ||
aria2.send("getVersion", [params]).then(fn); | ||
``` | ||
@@ -246,3 +248,3 @@ | ||
See [example.js](https://github.com/sonnyp/aria2.js/blob/master/example/example.js) | ||
See [example](https://github.com/sonnyp/aria2.js/blob/master/example/). | ||
@@ -254,3 +256,3 @@ [↑](#aria2js) | ||
``` | ||
npm install mocha standard | ||
npm install | ||
npm test | ||
@@ -260,7 +262,1 @@ ``` | ||
[↑](#aria2js) | ||
# Contributing | ||
See [CONTRIBUTING.md](https://github.com/sonnyp/aria2.js/blob/master/CONTRIBUTING.md) | ||
[↑](#aria2js) |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
54908
15
722
249
3
+ Addedasync-limiter@1.0.1(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
+ Addedws@5.2.4(transitive)
- Removedencoding@0.1.13(transitive)
- Removediconv-lite@0.6.3(transitive)
- Removedis-stream@1.1.0(transitive)
- Removednode-fetch@1.7.3(transitive)
- Removedoptions@0.0.6(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedultron@1.0.2(transitive)
- Removedws@1.1.5(transitive)
Updatednode-fetch@^2.1.2
Updatedws@^5.1.1