From 1119e736e7b614dc94458552121298ca27553097 Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Sun, 11 Oct 2015 12:57:20 +0200 Subject: [PATCH] Remove unnecessary setTimeout --- themes/default/public/js/lufi-up.js | 30 ++++++++++++----------------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/themes/default/public/js/lufi-up.js b/themes/default/public/js/lufi-up.js index 104f9b5..269e98b 100644 --- a/themes/default/public/js/lufi-up.js +++ b/themes/default/public/js/lufi-up.js @@ -197,21 +197,17 @@ function sliceAndUpload(randomkey, i, parts, j, delay, del_at_first_view, short) } else { window.ws.onclose = function() { console.log('Websocket closed, waiting 10sec.'); - setTimeout(function() { - window.ws = spawnWebsocket(0, function() { - console.log('sending again slice '+(j + 1)+'/'+parts+' of file '+file.name); - window.ws.send(data+'XXMOJOXX'+JSON.stringify(encrypted)); - }); - }, 10000); + window.ws = spawnWebsocket(0, function() { + console.log('sending again slice '+(j + 1)+'/'+parts+' of file '+file.name); + window.ws.send(data+'XXMOJOXX'+JSON.stringify(encrypted)); + }); }; window.ws.onerror = function() { console.log('Error on Websocket, waiting 10sec.'); - setTimeout(function() { - window.ws = spawnWebsocket(0, function() { - console.log('sending again slice '+(j + 1)+'/'+parts+' of file '+file.name); - window.ws.send(data+'XXMOJOXX'+JSON.stringify(encrypted)); - }); - }, 10000); + window.ws = spawnWebsocket(0, function() { + console.log('sending again slice '+(j + 1)+'/'+parts+' of file '+file.name); + window.ws.send(data+'XXMOJOXX'+JSON.stringify(encrypted)); + }); }; window.ws.send(data+'XXMOJOXX'+JSON.stringify(encrypted)); } @@ -384,13 +380,11 @@ function spawnWebsocket(i, callback) { updateProgressBar(JSON.parse(e.data)); } ws.onerror = function() { - if (i < 5 && callback !== undefined) { - setTimeout(function() { - console.log('Retrying to send file '+i); - window.ws = spawnWebsocket(i + 1, callback); - }, 10000); - } console.log('error'); + if (i < 5 && callback !== undefined) { + console.log('Retrying to send file '+i); + window.ws = spawnWebsocket(i + 1, callback); + } } return ws; }