improved aria2 connection settings handling in angular

This commit is contained in:
hamza zia 2013-03-11 17:01:58 +01:00 committed by Hamza Zia
parent cc9e33f5bc
commit 9e63fa2ff6
5 changed files with 18 additions and 6 deletions

View File

@ -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();
});

View File

@ -87,7 +87,7 @@ angular
conf: {
host: 'localhost',
port: 6800,
encrypt: true,
encrypt: false,
auth: {
user: '',
pass: ''

View File

@ -64,6 +64,7 @@ angular
setTimeout(function() {
rpc.ariaRequest(
authUrl,
opts.name,
opts.params,
opts.success,
function() {

View File

@ -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) {

View File

@ -43,6 +43,7 @@ function(log, jsonRPC, sockRPC, alerts) {
return sockRPC.invoke(opts);
}
else {
console.log('calling json rpc');
return jsonRPC.invoke(opts);
}
}