web_sock connection reset cases handled

This commit is contained in:
Hamza Zia 2012-06-09 21:51:28 +08:00
parent c3fae7388c
commit 56ce71454a

View File

@ -36,7 +36,7 @@ var update_server_conf = function() {
if(port.length !== 0) { if(port.length !== 0) {
server_conf.port = port; server_conf.port = port;
} }
web_sock = undefined;
clear_dialogs(); clear_dialogs();
update_ui(); update_ui();
}; };
@ -84,16 +84,19 @@ var web_sock_send = function(conf, multicall) {
web_sock.send(JSON.stringify(data)); web_sock.send(JSON.stringify(data));
} }
var web_sock_init = function() { var web_sock_init = function() {
if(!web_sock) {
var sock = new WebSocket('ws://' + server_conf.host + ':' + server_conf.port + '/jsonrpc'); var sock = new WebSocket('ws://' + server_conf.host + ':' + server_conf.port + '/jsonrpc');
sock.onopen = function() { sock.onopen = function() {
console.log('websocket connected!!!'); console.log('websocket connected!!!');
web_sock = sock; web_sock = sock;
}; };
sock.onclose = function() { sock.onclose = function() {
console.log('websocket closed'); web_sock_error();
web_sock = undefined;
}; };
sock.onerror = web_sock_error; sock.onerror = web_sock_error;
sock.onmessage = web_sock_message; sock.onmessage = web_sock_message;
}
} }
var jsonp_syscall = function(conf, multicall) { var jsonp_syscall = function(conf, multicall) {
@ -146,11 +149,16 @@ var jsonp_syscall = function(conf, multicall) {
}); });
} }
var aria_syscall = function(conf, multicall) { var aria_syscall = function(conf, multicall) {
if(!web_sock || server_conf.user.length || server_conf.pass.length) if(!WebSocket || server_conf.user.length || server_conf.pass.length) {
jsonp_syscall(conf, multicall); jsonp_syscall(conf, multicall);
else { }
else if(web_sock) {
web_sock_send(conf, multicall); web_sock_send(conf, multicall);
} }
else {
web_sock_init();
jsonp_syscall(conf, multicall);
}
} }
var update_ui = function() { var update_ui = function() {
updateDownloads(); updateDownloads();