2013-01-29 13:47:40 +01:00
|
|
|
angular
|
2013-03-02 12:01:07 +01:00
|
|
|
.module('webui.services.rpc.syscall', [
|
|
|
|
'webui.services.rpc.jsoncall', 'webui.services.rpc.sockcall',
|
|
|
|
'webui.services.utils', 'webui.services.alerts'
|
|
|
|
])
|
|
|
|
.factory('$syscall', ['$log', '$jsoncall', '$sockcall', '$alerts',
|
|
|
|
function(log, jsonRPC, sockRPC, alerts) {
|
2013-01-15 09:24:09 +01:00
|
|
|
return {
|
2016-04-13 11:23:19 +02:00
|
|
|
state: 'none',
|
2013-01-15 09:24:09 +01:00
|
|
|
// called to initialize the rpc interface, call everytime configuration changes
|
|
|
|
// conf has the following structure:
|
|
|
|
// {
|
|
|
|
// host (string): host for the aria2 server
|
|
|
|
// port (number): port number for the aria2 server
|
2013-03-09 06:35:53 +01:00
|
|
|
// encrypt (boolean, optional): true if encryption is enabled in the aria2 server
|
2013-01-15 09:24:09 +01:00
|
|
|
// auth (optional): {
|
2014-05-17 17:41:00 +02:00
|
|
|
// token (string): secret token for authentication (--rpc-secret)
|
2013-01-15 09:24:09 +01:00
|
|
|
// user (string): username for http authentication if enabled
|
|
|
|
// pass (string): password for the http authentication if enabled
|
|
|
|
// }
|
|
|
|
init: function(conf) {
|
2016-04-13 11:23:19 +02:00
|
|
|
console.log("Syscall is initializing to", conf);
|
|
|
|
this.state = 'initializing';
|
2013-01-15 09:24:09 +01:00
|
|
|
jsonRPC.init(conf);
|
2016-04-13 11:23:19 +02:00
|
|
|
var syscall = this;
|
|
|
|
sockRPC.init(conf, function() {
|
|
|
|
console.log("Syscall is ready");
|
|
|
|
syscall.state = 'ready';
|
|
|
|
});
|
2013-01-15 09:24:09 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
// call this to start an rpc call, opts has the following structure:
|
|
|
|
// {
|
|
|
|
// name (string): name of the actual aria2 syscall
|
|
|
|
// success (function): callback called with (parsed) data if rpc is successfull
|
|
|
|
// error (function): callback called when an error occurs
|
|
|
|
// params (array, optional): the params for some syscall (like multicall) and is optional for others
|
|
|
|
// }
|
|
|
|
invoke: function(opts) {
|
|
|
|
opts.success = opts.success || angular.noop;
|
|
|
|
opts.error = opts.error || angular.noop;
|
|
|
|
|
2013-01-17 07:51:03 +01:00
|
|
|
if (sockRPC.initialized) {
|
2015-04-04 21:36:04 +02:00
|
|
|
console.log('calling sock rpc');
|
2013-01-15 09:24:09 +01:00
|
|
|
return sockRPC.invoke(opts);
|
2013-01-17 07:51:03 +01:00
|
|
|
}
|
|
|
|
else {
|
2013-03-11 17:01:58 +01:00
|
|
|
console.log('calling json rpc');
|
2013-01-15 09:24:09 +01:00
|
|
|
return jsonRPC.invoke(opts);
|
2013-01-17 07:51:03 +01:00
|
|
|
}
|
2013-01-15 09:24:09 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}]);
|
|
|
|
|
|
|
|
|