diff --git a/app/index.html b/app/index.html index 3a4308f..8402100 100644 --- a/app/index.html +++ b/app/index.html @@ -185,6 +185,7 @@ + diff --git a/app/scripts/core/constants.js b/app/scripts/core/constants.js index a4f4404..e3ee106 100644 --- a/app/scripts/core/constants.js +++ b/app/scripts/core/constants.js @@ -6,6 +6,7 @@ appPrefix: 'AriaNg' }).constant('ariaNgDefaultOptions', { localeName: 'en-US', + protocol: 'http', globalStatRefreshInterval: 1000, downloadTaskRefreshInterval: 1000 }).constant('aria2RpcConstants', { diff --git a/app/scripts/services/aria2HttpRpcService.js b/app/scripts/services/aria2HttpRpcService.js new file mode 100644 index 0000000..ceb365c --- /dev/null +++ b/app/scripts/services/aria2HttpRpcService.js @@ -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 + }); + } + }; + }]); +})(); diff --git a/app/scripts/services/aria2RpcService.js b/app/scripts/services/aria2RpcService.js index 157c715..aaca4f7 100644 --- a/app/scripts/services/aria2RpcService.js +++ b/app/scripts/services/aria2RpcService.js @@ -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 }; - return aria2WebSocketRpcService.request(context); + if (ariaNgSettingService.getProtocol() == 'ws') { + return aria2WebSocketRpcService.request(context); + } else { + return aria2HttpRpcService.request(context); + } }; return { diff --git a/app/scripts/services/aria2WebSocketRpcService.js b/app/scripts/services/aria2WebSocketRpcService.js index 5117648..2c45fea 100644 --- a/app/scripts/services/aria2WebSocketRpcService.js +++ b/app/scripts/services/aria2WebSocketRpcService.js @@ -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 = {}; diff --git a/app/scripts/services/ariaNgSettingService.js b/app/scripts/services/ariaNgSettingService.js index 98e7832..e184204 100644 --- a/app/scripts/services/ariaNgSettingService.js +++ b/app/scripts/services/ariaNgSettingService.js @@ -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'); @@ -59,11 +59,11 @@ }, getDisplayOrder: function () { var value = getOption('displayOrder'); - + if (!value) { value = 'default'; } - + return value; }, setDisplayOrder: function (value) {