From 9e63fa2ff6706a646926ff7cf689515c2ee4c480 Mon Sep 17 00:00:00 2001 From: hamza zia Date: Mon, 11 Mar 2013 17:01:58 +0100 Subject: [PATCH] improved aria2 connection settings handling in angular --- js/ctrls/alert.js | 2 +- js/ctrls/modal.js | 2 +- js/services/rpc/jsoncall.js | 1 + js/services/rpc/sockcall.js | 18 ++++++++++++++---- js/services/rpc/syscall.js | 1 + 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/js/ctrls/alert.js b/js/ctrls/alert.js index df5e8cf..230345b 100644 --- a/js/ctrls/alert.js +++ b/js/ctrls/alert.js @@ -16,7 +16,7 @@ angular.module('webui.ctrls.alert', [ setTimeout(function() { var ind = scope.pendingAlerts.indexOf(obj); if (ind != -1) scope.removeAlert(ind); - }, 5000); + }, 10000); scope.$digest(); }); diff --git a/js/ctrls/modal.js b/js/ctrls/modal.js index 29fff2f..962f552 100644 --- a/js/ctrls/modal.js +++ b/js/ctrls/modal.js @@ -87,7 +87,7 @@ angular conf: { host: 'localhost', port: 6800, - encrypt: true, + encrypt: false, auth: { user: '', pass: '' diff --git a/js/services/rpc/jsoncall.js b/js/services/rpc/jsoncall.js index 0a5c506..bb31ef5 100644 --- a/js/services/rpc/jsoncall.js +++ b/js/services/rpc/jsoncall.js @@ -64,6 +64,7 @@ angular setTimeout(function() { rpc.ariaRequest( authUrl, + opts.name, opts.params, opts.success, function() { diff --git a/js/services/rpc/sockcall.js b/js/services/rpc/sockcall.js index 83f0979..5c16519 100644 --- a/js/services/rpc/sockcall.js +++ b/js/services/rpc/sockcall.js @@ -24,13 +24,22 @@ function(_, JSON, name, utils, alerts) { scheme: 'ws', // called when a connection error occurs - onerror: function(err) { + onerror: function(ev) { _.each(sockRPC.handles, function(h) { h.error() }); sockRPC.handles = []; + sockRPC.initialized = false; + alerts.log('Error while talking to aria2 over websocket'); + + }, + onclose: function(ev) { + if (sockRPC.handles && sockRPC.handles.length) + sockRPC.onerror('Connection reset while pending calls to aria2'); + sockRPC.initialized = false; }, // when connection opens onopen: function() { + alerts.addAlert('Connected to aria2 successfully over websocket!', 'success'); sockRPC.initialized = true; }, @@ -82,14 +91,15 @@ function(_, JSON, name, utils, alerts) { sockRPC.scheme = sockRPC.conf.encrypt ? 'wss' : 'ws'; if (sockRPC.sock) { - sockRPC.onopen = sockRPC.sock.onmessage = sockRPC.sock.onerror = sockRPC.sock.onclose = null; - sockRPC.onerror(); + sockRPC.sock.onopen = sockRPC.sock.onmessage = sockRPC.sock.onerror = sockRPC.sock.onclose = null; + sockRPC.onerror({message: 'Changing the websocket aria2 server details'}); } try { sockRPC.sock = new WebSocket(sockRPC.scheme + '://' + conf.host + ':' + conf.port + '/jsonrpc'); sockRPC.sock.onopen = sockRPC.onopen; - sockRPC.sock.onclose = sockRPC.sock.onerror = sockRPC.onerror; + sockRPC.sock.onclose = sockRPC.onclose; + sockRPC.sock.onerror = sockRPC.onerror; sockRPC.sock.onmessage = sockRPC.onmessage; } catch (ex) { diff --git a/js/services/rpc/syscall.js b/js/services/rpc/syscall.js index a829a75..bbaa3fb 100644 --- a/js/services/rpc/syscall.js +++ b/js/services/rpc/syscall.js @@ -43,6 +43,7 @@ function(log, jsonRPC, sockRPC, alerts) { return sockRPC.invoke(opts); } else { + console.log('calling json rpc'); return jsonRPC.invoke(opts); } }