From 56ce71454ace406ea78c78c809a63d57dc342fc2 Mon Sep 17 00:00:00 2001 From: Hamza Zia Date: Sat, 9 Jun 2012 21:51:28 +0800 Subject: [PATCH] web_sock connection reset cases handled --- js/script.js | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/js/script.js b/js/script.js index c3bfcac..16c8642 100755 --- a/js/script.js +++ b/js/script.js @@ -36,7 +36,7 @@ var update_server_conf = function() { if(port.length !== 0) { server_conf.port = port; } - + web_sock = undefined; clear_dialogs(); update_ui(); }; @@ -84,16 +84,19 @@ var web_sock_send = function(conf, multicall) { web_sock.send(JSON.stringify(data)); } var web_sock_init = function() { - var sock = new WebSocket('ws://' + server_conf.host + ':' + server_conf.port + '/jsonrpc'); - sock.onopen = function() { - console.log('websocket connected!!!'); - web_sock = sock; - }; - sock.onclose = function() { - console.log('websocket closed'); - }; - sock.onerror = web_sock_error; - sock.onmessage = web_sock_message; + if(!web_sock) { + var sock = new WebSocket('ws://' + server_conf.host + ':' + server_conf.port + '/jsonrpc'); + sock.onopen = function() { + console.log('websocket connected!!!'); + web_sock = sock; + }; + sock.onclose = function() { + web_sock_error(); + web_sock = undefined; + }; + sock.onerror = web_sock_error; + sock.onmessage = web_sock_message; + } } var jsonp_syscall = function(conf, multicall) { @@ -146,11 +149,16 @@ var jsonp_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); - else { + } + else if(web_sock) { web_sock_send(conf, multicall); } + else { + web_sock_init(); + jsonp_syscall(conf, multicall); + } } var update_ui = function() { updateDownloads();