diff --git a/src/langs/zh_Hans.txt b/src/langs/zh_Hans.txt index fa8be9b..7c03acf 100644 --- a/src/langs/zh_Hans.txt +++ b/src/langs/zh_Hans.txt @@ -199,6 +199,7 @@ RPC host cannot be empty!=RPC 主机不能为空! RPC secret is not base64 encoded!=RPC 密钥不是 Base64 编码后的字符串! URL is not base64 encoded!=指定 URL 不是 Base64 编码后的字符串! Tap to configure and get started with AriaNg.=您还没有进行过设置, 点击这里进行设置. +Cannot initialize WebSocket!=无法初始化 WebSocket! [error] unknown=未知错误. diff --git a/src/langs/zh_Hant.txt b/src/langs/zh_Hant.txt index 3552ec1..b4b62b4 100644 --- a/src/langs/zh_Hant.txt +++ b/src/langs/zh_Hant.txt @@ -199,6 +199,7 @@ RPC host cannot be empty!=RPC 主機不能為空! RPC secret is not base64 encoded!=RPC 密鑰不是 Base64 編碼後的字元串! URL is not base64 encoded!=指定 URL 不是 Base64 編碼後的字元串! Tap to configure and get started with AriaNg.=您還沒有進行過設置, 點擊這裡進行設置. +Cannot initialize WebSocket!=無法初始化 WebSocket! [error] unknown=未知錯誤. diff --git a/src/scripts/config/configuration.js b/src/scripts/config/configuration.js index 0771f98..698ddce 100644 --- a/src/scripts/config/configuration.js +++ b/src/scripts/config/configuration.js @@ -1,7 +1,9 @@ (function () { 'use strict'; - angular.module('ariaNg').config(['$translateProvider', 'localStorageServiceProvider', 'NotificationProvider', 'ariaNgConstants', 'ariaNgLanguages', function ($translateProvider, localStorageServiceProvider, NotificationProvider, ariaNgConstants, ariaNgLanguages) { + angular.module('ariaNg').config(['$qProvider', '$translateProvider', 'localStorageServiceProvider', 'NotificationProvider', 'ariaNgConstants', 'ariaNgLanguages', function ($qProvider, $translateProvider, localStorageServiceProvider, NotificationProvider, ariaNgConstants, ariaNgLanguages) { + $qProvider.errorOnUnhandledRejections(false); + localStorageServiceProvider .setPrefix(ariaNgConstants.appPrefix) .setStorageType('localStorage') diff --git a/src/scripts/config/defaultLanguage.js b/src/scripts/config/defaultLanguage.js index 51f3bb1..cb7ebf1 100644 --- a/src/scripts/config/defaultLanguage.js +++ b/src/scripts/config/defaultLanguage.js @@ -203,6 +203,7 @@ 'RPC secret is not base64 encoded!': 'RPC secret is not base64 encoded!', 'URL is not base64 encoded!': 'URL is not base64 encoded!', 'Tap to configure and get started with AriaNg.': 'Tap to configure and get started with AriaNg.', + 'Cannot initialize WebSocket!': 'Cannot initialize WebSocket!', 'error': { 'unknown': 'Unknown error occurred.', 'operation.timeout': 'Operation timed out.', diff --git a/src/scripts/services/aria2WebSocketRpcService.js b/src/scripts/services/aria2WebSocketRpcService.js index 88def29..95f4718 100644 --- a/src/scripts/services/aria2WebSocketRpcService.js +++ b/src/scripts/services/aria2WebSocketRpcService.js @@ -29,7 +29,7 @@ }); if (content.result && context.successCallback) { - ariaNgLogService.debug('[aria2WebSocketRpcService.request] response uccess', content); + ariaNgLogService.debug('[aria2WebSocketRpcService.request] response success', content); context.successCallback(context.id, content.result); } @@ -65,28 +65,39 @@ var getSocketClient = function () { if (socketClient === null) { - socketClient = $websocket(rpcUrl); + try { + socketClient = $websocket(rpcUrl); - socketClient.onMessage(function (message) { - if (!message || !message.data) { - return; + socketClient.onMessage(function (message) { + if (!message || !message.data) { + return; + } + + var content = angular.fromJson(message.data); + + if (!content) { + return; + } + + if (content.id) { + processMethodCallback(content); + } else if (content.method) { + processEventCallback(content); + } + }); + } catch (ex) { + return { + success: false, + error: 'Cannot initialize WebSocket!', + exception: ex } - - var content = angular.fromJson(message.data); - - if (!content) { - return; - } - - if (content.id) { - processMethodCallback(content); - } else if (content.method) { - processEventCallback(content); - } - }); + } } - return socketClient; + return { + success: true, + instance: socketClient + }; }; return { @@ -108,7 +119,17 @@ deferred: deferred }; - client.send(requestBody); + if (client.instance) { + client.instance.send(requestBody); + } else { + deferred.reject({ + success: false, + context: context + }); + + ariaNgLogService.debug('[aria2WebSocketRpcService.request] client error', client); + context.errorCallback(context.id, { message: client.error }); + } return deferred.promise; },