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/filters/volumn.js"></script>
|
||||||
<script src="scripts/langs/en-US.js"></script>
|
<script src="scripts/langs/en-US.js"></script>
|
||||||
<script src="scripts/langs/zh-CN.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/aria2RpcService.js"></script>
|
||||||
<script src="scripts/services/aria2WebSocketRpcService.js"></script>
|
<script src="scripts/services/aria2WebSocketRpcService.js"></script>
|
||||||
<script src="scripts/services/ariaNgSettingService.js"></script>
|
<script src="scripts/services/ariaNgSettingService.js"></script>
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
appPrefix: 'AriaNg'
|
appPrefix: 'AriaNg'
|
||||||
}).constant('ariaNgDefaultOptions', {
|
}).constant('ariaNgDefaultOptions', {
|
||||||
localeName: 'en-US',
|
localeName: 'en-US',
|
||||||
|
protocol: 'http',
|
||||||
globalStatRefreshInterval: 1000,
|
globalStatRefreshInterval: 1000,
|
||||||
downloadTaskRefreshInterval: 1000
|
downloadTaskRefreshInterval: 1000
|
||||||
}).constant('aria2RpcConstants', {
|
}).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 () {
|
(function () {
|
||||||
'use strict';
|
'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) {
|
var invoke = function (method, context) {
|
||||||
context.uniqueId = utils.generateUniqueId();
|
context.uniqueId = utils.generateUniqueId();
|
||||||
context.requestBody = {
|
context.requestBody = {
|
||||||
|
@ -11,7 +11,11 @@
|
||||||
params: context.params
|
params: context.params
|
||||||
};
|
};
|
||||||
|
|
||||||
return aria2WebSocketRpcService.request(context);
|
if (ariaNgSettingService.getProtocol() == 'ws') {
|
||||||
|
return aria2WebSocketRpcService.request(context);
|
||||||
|
} else {
|
||||||
|
return aria2HttpRpcService.request(context);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('ariaNg').factory('aria2WebSocketRpcService', ['$websocket', 'ariaNgSettingService', function ($websocket, ariaNgSettingService) {
|
angular.module('ariaNg').factory('aria2WebSocketRpcService', ['$websocket', 'ariaNgSettingService', function ($websocket, ariaNgSettingService) {
|
||||||
var rpcUrl = ariaNgSettingService.getJsonRpcUrl();
|
var rpcUrl = ariaNgSettingService.getJsonRpcUrl('ws');
|
||||||
var socketClient = $websocket(rpcUrl);
|
var socketClient = $websocket(rpcUrl);
|
||||||
var sendIdMapping = {};
|
var sendIdMapping = {};
|
||||||
|
|
||||||
|
|
|
@ -29,12 +29,6 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
get: function (key) {
|
|
||||||
return getOption(key);
|
|
||||||
},
|
|
||||||
set: function (key, value) {
|
|
||||||
return setOption(key, value);
|
|
||||||
},
|
|
||||||
getLocaleName: function () {
|
getLocaleName: function () {
|
||||||
return getOption('localeName');
|
return getOption('localeName');
|
||||||
},
|
},
|
||||||
|
@ -42,14 +36,20 @@
|
||||||
setOption('localeName', value);
|
setOption('localeName', value);
|
||||||
$translate.use(value);
|
$translate.use(value);
|
||||||
},
|
},
|
||||||
getJsonRpcUrl: function () {
|
getJsonRpcUrl: function (protocol) {
|
||||||
var rpcHost = getOption('aria2RpcHost');
|
var rpcHost = getOption('aria2RpcHost');
|
||||||
|
|
||||||
if (!rpcHost) {
|
if (!rpcHost) {
|
||||||
rpcHost = $location.$$host + ':6800';
|
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 () {
|
getGlobalStatRefreshInterval: function () {
|
||||||
return getOption('globalStatRefreshInterval');
|
return getOption('globalStatRefreshInterval');
|
||||||
|
@ -59,11 +59,11 @@
|
||||||
},
|
},
|
||||||
getDisplayOrder: function () {
|
getDisplayOrder: function () {
|
||||||
var value = getOption('displayOrder');
|
var value = getOption('displayOrder');
|
||||||
|
|
||||||
if (!value) {
|
if (!value) {
|
||||||
value = 'default';
|
value = 'default';
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
},
|
},
|
||||||
setDisplayOrder: function (value) {
|
setDisplayOrder: function (value) {
|
||||||
|
|
Reference in a new issue