support requesting rpc service using http protocol
This commit is contained in:
parent
38469b607d
commit
671124e3da
|
@ -185,6 +185,7 @@
|
|||
<script src="scripts/filters/volumn.js"></script>
|
||||
<script src="scripts/langs/en-US.js"></script>
|
||||
<script src="scripts/langs/zh-CN.js"></script>
|
||||
<script src="scripts/services/aria2HttpRpcService.js"></script>
|
||||
<script src="scripts/services/aria2RpcService.js"></script>
|
||||
<script src="scripts/services/aria2WebSocketRpcService.js"></script>
|
||||
<script src="scripts/services/ariaNgSettingService.js"></script>
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
appPrefix: 'AriaNg'
|
||||
}).constant('ariaNgDefaultOptions', {
|
||||
localeName: 'en-US',
|
||||
protocol: 'http',
|
||||
globalStatRefreshInterval: 1000,
|
||||
downloadTaskRefreshInterval: 1000
|
||||
}).constant('aria2RpcConstants', {
|
||||
|
|
33
app/scripts/services/aria2HttpRpcService.js
Normal file
33
app/scripts/services/aria2HttpRpcService.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
angular.module('ariaNg').factory('aria2HttpRpcService', ['$http', 'ariaNgSettingService', function ($http, ariaNgSettingService) {
|
||||
var rpcUrl = ariaNgSettingService.getJsonRpcUrl('http');
|
||||
|
||||
return {
|
||||
request: function (context) {
|
||||
if (!context) {
|
||||
return;
|
||||
}
|
||||
|
||||
var requestContext = {
|
||||
url: rpcUrl,
|
||||
method: 'POST',
|
||||
data: context.requestBody
|
||||
};
|
||||
|
||||
return $http(requestContext).success(function (data, header, config, status) {
|
||||
if (!data || !data.result) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (context.callback) {
|
||||
context.callback(data.result);
|
||||
}
|
||||
}).error(function (data, header, config, status) {
|
||||
//Do Nothing
|
||||
});
|
||||
}
|
||||
};
|
||||
}]);
|
||||
})();
|
|
@ -1,7 +1,7 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
angular.module('ariaNg').factory('aria2RpcService', ['aria2RpcConstants', 'aria2WebSocketRpcService', 'utils', function (aria2RpcConstants, aria2WebSocketRpcService, utils) {
|
||||
angular.module('ariaNg').factory('aria2RpcService', ['aria2RpcConstants', 'ariaNgSettingService', 'aria2HttpRpcService', 'aria2WebSocketRpcService', 'utils', function (aria2RpcConstants, ariaNgSettingService, aria2HttpRpcService, aria2WebSocketRpcService, utils) {
|
||||
var invoke = function (method, context) {
|
||||
context.uniqueId = utils.generateUniqueId();
|
||||
context.requestBody = {
|
||||
|
@ -11,7 +11,11 @@
|
|||
params: context.params
|
||||
};
|
||||
|
||||
if (ariaNgSettingService.getProtocol() == 'ws') {
|
||||
return aria2WebSocketRpcService.request(context);
|
||||
} else {
|
||||
return aria2HttpRpcService.request(context);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('ariaNg').factory('aria2WebSocketRpcService', ['$websocket', 'ariaNgSettingService', function ($websocket, ariaNgSettingService) {
|
||||
var rpcUrl = ariaNgSettingService.getJsonRpcUrl();
|
||||
var rpcUrl = ariaNgSettingService.getJsonRpcUrl('ws');
|
||||
var socketClient = $websocket(rpcUrl);
|
||||
var sendIdMapping = {};
|
||||
|
||||
|
|
|
@ -29,12 +29,6 @@
|
|||
};
|
||||
|
||||
return {
|
||||
get: function (key) {
|
||||
return getOption(key);
|
||||
},
|
||||
set: function (key, value) {
|
||||
return setOption(key, value);
|
||||
},
|
||||
getLocaleName: function () {
|
||||
return getOption('localeName');
|
||||
},
|
||||
|
@ -42,14 +36,20 @@
|
|||
setOption('localeName', value);
|
||||
$translate.use(value);
|
||||
},
|
||||
getJsonRpcUrl: function () {
|
||||
getJsonRpcUrl: function (protocol) {
|
||||
var rpcHost = getOption('aria2RpcHost');
|
||||
|
||||
if (!rpcHost) {
|
||||
rpcHost = $location.$$host + ':6800';
|
||||
}
|
||||
|
||||
return 'ws://' + rpcHost + '/jsonrpc';
|
||||
return protocol + '://' + rpcHost + '/jsonrpc';
|
||||
},
|
||||
getProtocol: function () {
|
||||
return getOption('protocol');
|
||||
},
|
||||
setProtocol: function (value) {
|
||||
setOption('protocol', value);
|
||||
},
|
||||
getGlobalStatRefreshInterval: function () {
|
||||
return getOption('globalStatRefreshInterval');
|
||||
|
|
Reference in a new issue